Skip to content

Commit

Permalink
Merge pull request #90 from joaquimg/jg/typo
Browse files Browse the repository at this point in the history
Fix CI reference constructor
  • Loading branch information
joaquimg authored Sep 30, 2020
2 parents faf945b + bf84593 commit aebd720
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/jump.jl
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ function get_constrain_ref(vref::BilevelVariableRef)
end
end
@assert idx != -1
return BilevelConstraintRef(model, idx, DUAL_OF_LOWER)
return BilevelConstraintRef(model, idx)
end

# Objective
Expand Down
2 changes: 1 addition & 1 deletion src/moi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ mutable struct StrongDualityInequalityMode{T} <: StrongDualityMode{T}
function StrongDualityInequalityMode()
return new{Float64}(zero(Float64))
end
function StrongDualityInequalityMode{T}(eps::T) where T
function StrongDualityInequalityMode(eps::T) where T
return new{Float64}(eps)
end
end
Expand Down
51 changes: 46 additions & 5 deletions test/jump.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1391,8 +1391,8 @@ function jump_HTP_lin08(optimizer, mode = BilevelJuMP.SOS1Mode(), config = Confi
MOI.empty!(optimizer)
model = BilevelModel(()->optimizer, mode = mode)

@variable(Upper(model), x[i=1:2])
@variable(Lower(model), y[i=1:2])
@variable(Upper(model), x[i=1:2], start = [2, 0][i])
@variable(Lower(model), y[i=1:2], start = [1.5, 0][i])

@objective(Upper(model), Min,
-2x[1] + x[2] + 0.5*y[1])
Expand Down Expand Up @@ -1462,8 +1462,8 @@ function jump_HTP_lin10(optimizer, mode = BilevelJuMP.SOS1Mode(), config = Confi
MOI.empty!(optimizer)
model = BilevelModel(()->optimizer, mode = mode)

@variable(Upper(model), x[i=1:2])
@variable(Lower(model), y[i=1:2])
@variable(Upper(model), x[i=1:2], start = [2, 0][i])
@variable(Lower(model), y[i=1:2], start = [1.5, 0][i])

@objective(Upper(model), Min,
-2x[1] + x[2] + 0.5*y[1])
Expand Down Expand Up @@ -2301,7 +2301,7 @@ function jump_fanzeres2017(optimizer, mode = BilevelJuMP.SOS1Mode(), config = Co
@constraint(Lower(model), g[4] <= 100)
@constraint(Lower(model), lb[i=1:4], g[i] >= 0)

@variable(Upper(model), lambda, DualOf(b), start = 1_000)
@variable(Upper(model), lambda >= 0, DualOf(b), start = 1_000)

@objective(Upper(model), Max, lambda*g[1])

Expand All @@ -2317,6 +2317,47 @@ function jump_fanzeres2017(optimizer, mode = BilevelJuMP.SOS1Mode(), config = Co
@test value(lambda) 1_000 atol=1e-3
end

function jump_eq_price(optimizer, mode = BilevelJuMP.SOS1Mode(), config = Config())

atol = config.atol
start = config.start_value

j = 3
jger = 1
G = [10, 15, 12]
d = 26
c = [1, 2, 1.5]
p = 1
q = 10

MOI.empty!(optimizer)
model = BilevelModel(()->optimizer, mode = mode)

@variable(Upper(model), u[i=1:jger] >= 0, start = [2.0][i])

@variable(Lower(model), def >= 0, start = 0)
@variable(Lower(model), g[i=1:j] >= 0, start = [10.0, 4.0, 12.0][i])

@constraint(Lower(model), MaxGen[i=1:j], g[i] <= G[i])
@constraint(Lower(model), DemBal, sum(g[i] for i in 1:j) + def == d)
@objective(Lower(model), Min, sum(u[i]*g[i] for i in 1:jger) +
sum(c[i+jger]*g[i+jger] for i in 1:(j-jger)) + 100*def)

@variable(Upper(model), lambda >= 0, DualOf(DemBal), start = 2.0)
@objective(Upper(model), Max, lambda*sum(g[i] for i in 1:jger) -
sum(c[i]*g[i] for i in 1:jger) - (lambda - p)*q)

optimize!(model)

primal_status(model)
termination_status(model)

@test value.(g) [10.0, 4.0, 12.0] atol=atol
@test value(def) 0.0 atol=atol
@test value(lambda) 2.0 atol=atol
@test value.(u) [2.0] atol=atol

end

function jump_16(optimizer, mode = BilevelJuMP.SOS1Mode(), config = Config())

Expand Down
42 changes: 30 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ solvers_quad = OptModeType[]
solvers_bin_exp = OptModeType[]
solvers_sos_quad = OptModeType[]
solvers_nlp = OptModeType[]
solvers_nlp_sd = OptModeType[]
solvers_nlp_lowtol = OptModeType[]
solvers_sos_quad_bin = OptModeType[]
solvers_fa_quad_bin = OptModeType[]
solvers_fa = OptModeType[]
solvers_fa2 = OptModeType[]

Expand Down Expand Up @@ -146,17 +148,25 @@ end
end

@testset "Princeton Handbook of Test Problems" begin
for solver in solvers_nlp
for solver in vcat(solvers_nlp, solvers_nlp_sd)
jump_HTP_lin01(solver.opt, solver.mode, CONFIG_3_start)
jump_HTP_lin02(solver.opt, solver.mode)
# jump_HTP_lin02(solver.opt, solver.mode, CONFIG_4)
jump_HTP_lin03(solver.opt, solver.mode)
jump_HTP_lin03_vec(solver.opt, solver.mode)
jump_HTP_lin04(solver.opt, solver.mode)
jump_HTP_lin05(solver.opt, solver.mode) # broken on cbc linux on julia 1.0 and 1.2 but not 1.1 see: https://travis-ci.org/joaquimg/BilevelJuMP.jl/builds/619335351
jump_HTP_lin06(solver.opt, solver.mode)
jump_HTP_lin07(solver.opt, solver.mode, CONFIG_2)
jump_HTP_lin08(solver.opt, solver.mode)
jump_HTP_lin08(solver.opt, solver.mode, CONFIG_4)
jump_HTP_lin09(solver.opt, solver.mode)
# jump_HTP_lin10(solver.opt, solver.mode)
end
for solver in solvers_nlp_sd
jump_HTP_lin02(solver.opt, solver.mode, CONFIG_2)
# jump_HTP_lin10(solver.opt, solver.mode)
end
for solver in solvers_nlp
jump_HTP_lin02(solver.opt, solver.mode)
jump_HTP_lin10(solver.opt, solver.mode)
end
for solver in solvers_nlp
Expand Down Expand Up @@ -236,19 +246,27 @@ end
end
end

@testset "conejo2016" begin
@testset "equilibrium" begin
for solver in solvers_nlp
jump_conejo2016(solver.opt, solver.mode)
end
for solver in solvers_sos_quad_bin
jump_conejo2016(solver.opt, solver.mode, config, bounds = true)
end
end

@testset "fanzeres2017" begin
for solver in solvers_nlp
jump_fanzeres2017(solver.opt, solver.mode)
# jump_eq_price(solver.opt, solver.mode)
end
for solver in solvers_nlp_sd
jump_conejo2016(solver.opt, solver.mode)
# jump_fanzeres2017(solver.opt, solver.mode)
# jump_eq_price(solver.opt, solver.mode)
end
# for solver in solvers_sos_quad_bin
# jump_conejo2016(solver.opt, solver.mode, config, bounds = true)
# jump_fanzeres2017(solver.opt, solver.mode)
# jump_eq_price(solver.opt, solver.mode)
# end
# for solver in solvers_fa_quad_bin
# jump_conejo2016(solver.opt, solver.mode, config, bounds = true)
# jump_fanzeres2017(solver.opt, solver.mode)
# jump_eq_price(solver.opt, solver.mode)
# end
end

# require SOCtoNonConvexQuad bridge to work with Ipopt
Expand Down
16 changes: 15 additions & 1 deletion test/solvers/cbc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ MOI.set(CBC_OPTIMIZER, MOI.Silent(), true)
const CBC_CACHE = MOIU.UniversalFallback(MOIU.Model{Float64}())
const CBC_CACHED = MOIU.CachingOptimizer(CBC_CACHE, CBC_OPTIMIZER)
const CBC_BRIDGED = MOI.Bridges.full_bridge_optimizer(CBC_CACHED, Float64)
MOI.Bridges.add_bridge(CBC_BRIDGED, MOI.Bridges.Constraint.SOCtoNonConvexQuadBridge{Float64})

push!(solvers, (opt = CBC_BRIDGED, mode = BilevelJuMP.SOS1Mode()))
push!(solvers_sos, (opt = CBC_BRIDGED, mode = BilevelJuMP.SOS1Mode()))
Expand All @@ -17,14 +18,27 @@ push!(solvers_fa2, (opt = CBC_BRIDGED, mode = BilevelJuMP.FortunyAmatMcCarlMode(

push!(solvers_bin_exp, (
opt = QuadraticToBinary.Optimizer{Float64}(CBC_BRIDGED),
mode = BilevelJuMP.StrongDualityInequalityMode{Float64}(1e-9)))
mode = BilevelJuMP.StrongDualityInequalityMode(1e-9)))
MOI.set(solvers_bin_exp[end].opt, QuadraticToBinary.GlobalVariablePrecision(), 1e-5)

push!(solvers_bin_exp, (
opt = QuadraticToBinary.Optimizer{Float64}(CBC_BRIDGED),
mode = BilevelJuMP.StrongDualityEqualityMode()))
MOI.set(solvers_bin_exp[end].opt, QuadraticToBinary.GlobalVariablePrecision(), 1e-5)

#=
QTB_CBC_BRIDGED = MOI.Bridges.full_bridge_optimizer(
QuadraticToBinary.Optimizer{Float64}(CBC_BRIDGED, lb=-1000,ub=1000),
Float64)
MOI.Bridges.add_bridge(QTB_CBC_BRIDGED, MOI.Bridges.Constraint.SOCtoNonConvexQuadBridge{Float64})
push!(solvers_sos_quad_bin, (
opt = QTB_CBC_BRIDGED,
mode = BilevelJuMP.SOS1Mode()))
push!(solvers_fa_quad_bin, (
opt = QTB_CBC_BRIDGED,
mode = BilevelJuMP.FortunyAmatMcCarlMode(primal_big_M = 1000, dual_big_M = 1000)))
=#
# push!(solvers_sos_quad, (
# opt = QuadraticToBinary.Optimizer{Float64}(CBC_BRIDGED),
# mode = BilevelJuMP.SOS1Mode()))
Expand Down
3 changes: 2 additions & 1 deletion test/solvers/ipopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ push!(solvers_nlp, (opt = IPO_BRIDGED, mode = BilevelJuMP.ProductWithSlackMode(1
push!(solvers, (opt = IPO_BRIDGED, mode = BilevelJuMP.ProductMode(1e-9)))
push!(solvers_quad, (opt = IPO_BRIDGED, mode = BilevelJuMP.ProductMode(1e-9)))

# push!(solvers_nlp, (opt = IPO_BRIDGED, mode = BilevelJuMP.StrongDualityInequalityMode(1e-9)))
push!(solvers_nlp_sd, (opt = IPO_BRIDGED, mode = BilevelJuMP.StrongDualityEqualityMode()))
#=
push!(solvers, (opt = IPO_BRIDGED, mode = BilevelJuMP.StrongDualityInequalityMode(1e-9)))
push!(solvers_quad, (opt = IPO_BRIDGED, mode = BilevelJuMP.StrongDualityInequalityMode(1e-9)))
#push!(solvers_nlp, (opt = IPO_BRIDGED, mode = BilevelJuMP.StrongDualityInequalityMode(1e-9)))
=#

0 comments on commit aebd720

Please sign in to comment.