Skip to content

Commit

Permalink
Fix compatability with Julia 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
IainNZ committed Feb 21, 2015
1 parent 5694434 commit 9c76e84
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 25 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ notifications:
email: false
env:
- JULIAVERSION="juliareleases"
- JULIAVERSION="julianightlies"
before_install:
- sudo add-apt-repository ppa:staticfloat/julia-deps -y
- sudo add-apt-repository ppa:staticfloat/${JULIAVERSION} -y
Expand All @@ -16,7 +17,7 @@ before_install:
script:
- julia -e 'versioninfo(); Pkg.init(); Pkg.clone(pwd())'
- julia -e 'Pkg.test("JuMPeR", coverage=true)'
- julia -e 'Pkg.clone("https://github.com/vgupta1/DDUS.jl.git")'
- julia -e 'Pkg.test("DDUS")'
- if [ $JULIAVERSION = "juliareleases" ]; then julia -e 'Pkg.clone("https://github.com/vgupta1/DDUS.jl.git")'; fi
- if [ $JULIAVERSION = "juliareleases" ]; then julia -e 'Pkg.test("DDUS")'; fi
after_success:
- julia -e 'cd(Pkg.dir("JuMPeR")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'cd(Pkg.dir("JuMPeR")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
6 changes: 3 additions & 3 deletions src/JuMPeR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ end
RobustData(cutsolver) = RobustData(Any[],Any[],Any[],Any[],
0,String[],Float64[],Float64[],Symbol[],
Dict{Int,Symbol}(), Dict{Int,Vector}(),
GeneralOracle(), {},
cutsolver,{},{},0.0)
GeneralOracle(), Any[],
cutsolver,JuMP.JuMPContainer[],Any[], 0.0)

function RobustModel(;solver=JuMP.UnsetSolver(),cutsolver=JuMP.UnsetSolver())
m = Model(solver=solver)
Expand Down Expand Up @@ -158,7 +158,7 @@ function addConstraint(m::Model, c::UncConstraint, w=nothing)
# Just a regular old constraint
push!(rd.uncertainconstr,c)
push!(rd.oracles, w)
push!(rd.activecuts, {})
push!(rd.activecuts, Any[])
return ConstraintRef{UncConstraint}(m,length(rd.uncertainconstr))
end

Expand Down
2 changes: 1 addition & 1 deletion src/oracle_bertsim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ end
# TODO: Relax assumption of one uncertain per variable?
function generateCut(bs::BertSimOracle, master::Model, rm::Model, inds::Vector{Int}, active=false)
master_sol = master.colVal
new_cons = {}
new_cons = Any[]

for con_ind in inds
absx_devs = Float64[] # kth term is x[j]*devs[i]
Expand Down
4 changes: 2 additions & 2 deletions src/oracle_gen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ end

function generateCut(gen::GeneralOracle, master::Model, rm::Model, inds::Vector{Int}, active=false)
# If not doing cuts...
(!gen.use_cuts && !active) && return {}
(!gen.use_cuts && !active) && return Any[]

rd = getRobust(rm)
master_sol = master.colVal
new_cons = {}
new_cons = Any[]

for con_ind in inds
con = get_uncertain_constraint(rm, con_ind)
Expand Down
6 changes: 3 additions & 3 deletions src/oracle_gen_graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function setup(gen::GeneralGraphOracle, rm::Model, prefs)
if !gen.use_cuts
for comp = 1:num_components
# Get constraints for this component
comp_uncset = {}
comp_uncset = Any[]
for ci = 1:length(rd.uncertaintyset)
if gen.con_to_comp[ci] == comp
push!(comp_uncset, rd.uncertaintyset[ci])
Expand Down Expand Up @@ -301,11 +301,11 @@ end

function generateCut(gen::GeneralGraphOracle, master::Model, rm::Model, inds::Vector{Int}, active=false)
# If not doing cuts...
(!gen.use_cuts && !active) && return {}
(!gen.use_cuts && !active) && return Any[]

rd = getRobust(rm)
master_sol = master.colVal
new_cons = {}
new_cons = Any[]

for con_ind in inds
con = get_uncertain_constraint(rm, con_ind)
Expand Down
8 changes: 6 additions & 2 deletions src/robustmacro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ macro defUnc(m, x, extra...)
end
end

# Stuff to make JuMP macros work with Uncertains
# Stuff to make JuMP macros work with Uncertains - should probably be
# typed tighter, but seems to work OK.
(*)(u::Uncertain) = u
function addToExpression(aff::GenericAffExpr,c,x)
function addToExpression(aff::GenericAffExpr, c, x)
return aff + c*x
end
function addToExpression(val::Real, c, x::Union(UAffExpr,FullAffExpr))
return val + c*x
end
14 changes: 7 additions & 7 deletions src/robustops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@
(*)(lhs::Uncertain, rhs::AffExpr) = (*)(rhs, lhs)
(/)(lhs::Uncertain, rhs::AffExpr) = error("Cannot divide uncertain by expression")
# Uncertain--Uncertain
(+)(lhs::Uncertain, rhs::Uncertain) = UAffExpr([lhs,rhs],[1.,+1.],0.)
(-)(lhs::Uncertain, rhs::Uncertain) = UAffExpr([lhs,rhs],[1.,-1.],0.)
(+)(lhs::Uncertain, rhs::Uncertain) = UAffExpr(vcat(lhs,rhs),[1.,+1.],0.)
(-)(lhs::Uncertain, rhs::Uncertain) = UAffExpr(vcat(lhs,rhs),[1.,-1.],0.)
(*)(lhs::Uncertain, rhs::Uncertain) = error("Cannot multiply two uncertains")
(/)(lhs::Uncertain, rhs::Uncertain) = error("Cannot divide two uncertains")
# Uncertain--UAffExpr
(+)(lhs::Uncertain, rhs::UAffExpr) = UAffExpr([lhs,rhs.vars],[1.0, rhs.coeffs], rhs.constant)
(-)(lhs::Uncertain, rhs::UAffExpr) = UAffExpr([lhs,rhs.vars],[1.0,-rhs.coeffs],-rhs.constant)
(+)(lhs::Uncertain, rhs::UAffExpr) = UAffExpr(vcat(lhs,rhs.vars),vcat(1.0, rhs.coeffs), rhs.constant)
(-)(lhs::Uncertain, rhs::UAffExpr) = UAffExpr(vcat(lhs,rhs.vars),vcat(1.0,-rhs.coeffs),-rhs.constant)
(*)(lhs::Uncertain, rhs::UAffExpr) = error("Cannot multiply uncertain and expression")
(/)(lhs::Uncertain, rhs::UAffExpr) = error("Cannot divide uncertain by expression")
# Uncertain--FullAffExpr
Expand All @@ -111,12 +111,12 @@
(/)(lhs::UAffExpr, rhs::AffExpr) = error("Cannot divide by affine expression")
# UAffExpr--Uncertain
(+)(lhs::UAffExpr, rhs::Uncertain) = (+)(rhs,lhs)
(-)(lhs::UAffExpr, rhs::Uncertain) = UAffExpr([rhs,lhs.vars],[-1.0,lhs.coeffs],lhs.constant)
(-)(lhs::UAffExpr, rhs::Uncertain) = UAffExpr(vcat(rhs,lhs.vars),vcat(-1.0,lhs.coeffs),lhs.constant)
(*)(lhs::UAffExpr, rhs::Uncertain) = (*)(rhs,lhs)
(/)(lhs::UAffExpr, rhs::Uncertain) = error("Cannot divide by uncertain")
# UAffExpr--UAffExpr
(+)(lhs::UAffExpr, rhs::UAffExpr) = UAffExpr([lhs.vars,rhs.vars],[lhs.coeffs,rhs.coeffs],lhs.constant+rhs.constant)
(-)(lhs::UAffExpr, rhs::UAffExpr) = UAffExpr([lhs.vars,rhs.vars],[lhs.coeffs,-rhs.coeffs],lhs.constant-rhs.constant)
(+)(lhs::UAffExpr, rhs::UAffExpr) = UAffExpr(vcat(lhs.vars,rhs.vars),vcat(lhs.coeffs, rhs.coeffs),lhs.constant+rhs.constant)
(-)(lhs::UAffExpr, rhs::UAffExpr) = UAffExpr(vcat(lhs.vars,rhs.vars),vcat(lhs.coeffs,-rhs.coeffs),lhs.constant-rhs.constant)
(*)(lhs::UAffExpr, rhs::UAffExpr) = error("Cannot multiply two expressions")
(/)(lhs::UAffExpr, rhs::UAffExpr) = error("Cannot divide two expressions")
# UAffExpr--FullAffExpr
Expand Down
6 changes: 5 additions & 1 deletion test/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ facts("[macro] Uncertain constraints") do
@fact lastuc(rm) => "-u x $le -5"

@addConstraint(rm, (u+w)*x + 2 + w*x <= u*z + 3)
@fact lastuc(rm) => "(u + w) x + w x + -u z $le 1"
if VERSION > v"0.4.0-"
@fact lastuc(rm) => "u x + w x + w x + -u z $le 1"
else
@fact lastuc(rm) => "(u + w) x + w x + -u z $le 1"
end

@addConstraint(rm, sum{v[i]*y[i], i=1:5; i!=3} <= 9)
@fact lastuc(rm) => "v[1] y[1] + v[2] y[2] + v[4] y[4] + v[5] y[5] $le 9"
Expand Down
6 changes: 3 additions & 3 deletions test/oracle_general.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ facts("[oracle_gen_poly] Test 9 (infeasible LP)") do
for solver in lp_solvers, cuts in [true,false]
# Exemptions:
# - IpoptSolver reports UserLimit, which isn't too helpful.
"$(typeof(solver))"=="IpoptSolver" && continue
contains("$(typeof(solver))","IpoptSolver") && continue
# - ECOSSolver has a bug, it reports Unbounded
"$(typeof(solver))"=="ECOSSolver" && continue
contains("$(typeof(solver))","ECOSSolver") && continue

context("$(typeof(solver)), cuts=$cuts") do
m = RobustModel(solver=solver)
Expand Down Expand Up @@ -261,7 +261,7 @@ facts("[oracle_gen_poly] Test 14 (unbounded uncertainty set)") do
for solver in lp_solvers, cuts in [true,false]
# Exemptions:
# - IpoptSolver reports UserLimit, which isn't too helpful.
"$(typeof(solver))"=="IpoptSolver" && continue
contains("$(typeof(solver))","IpoptSolver") && continue
context("$(typeof(solver)), cuts=$cuts") do
m = RobustModel(solver=solver)
@defVar(m, x >= 1)
Expand Down

0 comments on commit 9c76e84

Please sign in to comment.