Skip to content

Commit

Permalink
Fix conicconstraintdata when parent has more columns (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored and joehuchette committed Jun 1, 2017
1 parent 8241d2d commit a00a92c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/BendersBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ function conicconstraintdata(m::Model)
V_s = Float64[]

# Fill it up
tmprow = JuMP.IndexedVector(Float64,m.numCols)
if numMasterCols > 0
tmprow_m = JuMP.IndexedVector(Float64, parent.numCols)
end
tmprow_s = JuMP.IndexedVector(Float64, m.numCols)

JuMP.fillconstrRHS!(b, con_cones, 0, m.linconstr)
if numMasterCols > 0
JuMP.fillconstrLHS!(I_m, J_m, V_m, tmprow, 0, m.linconstr, parent, true)
JuMP.fillconstrLHS!(I_m, J_m, V_m, tmprow_m, 0, m.linconstr, parent, true)
end
c = JuMP.fillconstrLHS!(I_s, J_s, V_s, tmprow, 0, m.linconstr, m, true)
c = JuMP.fillconstrLHS!(I_s, J_s, V_s, tmprow_s, 0, m.linconstr, m, true)

for idx in 1:m.numCols
# identify integrality information
Expand All @@ -70,16 +73,16 @@ function conicconstraintdata(m::Model)

JuMP.fillconstrRHS!(b, con_cones, c, m.socconstr)
if numMasterCols > 0
JuMP.fillconstrLHS!(I_m, J_m, V_m, tmprow, c, m.socconstr, parent, true)
JuMP.fillconstrLHS!(I_m, J_m, V_m, tmprow_m, c, m.socconstr, parent, true)
end
c = JuMP.fillconstrLHS!(I_s, J_s, V_s, tmprow, c, m.socconstr, m, true)
c = JuMP.fillconstrLHS!(I_s, J_s, V_s, tmprow_s, c, m.socconstr, m, true)

@assert c == numLinRows + numBounds + numSOCRows

if numMasterCols > 0
c, d = JuMP.fillconstr!(I_m, J_m, V_m, b, con_cones, tmprow, constr_to_row, c, d, m.sdpconstr, m, true)
c, d = JuMP.fillconstr!(I_m, J_m, V_m, b, con_cones, tmprow_m, constr_to_row, c, d, m.sdpconstr, m, true)
end
c, d = JuMP.fillconstr!(I_s, J_s, V_s, b, con_cones, tmprow, constr_to_row, c, d, m.sdpconstr, m, true)
c, d = JuMP.fillconstr!(I_s, J_s, V_s, b, con_cones, tmprow_s, constr_to_row, c, d, m.sdpconstr, m, true)

if c < length(b)
# This happens for example when symmetry constraints are dropped with SDP
Expand Down
23 changes: 23 additions & 0 deletions test/benderstest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ using Base.Test
misocp_solver = CbcSolver()
socp_solver = ECOS.ECOSSolver(verbose=false)

@testset "[Benders] conicconstraintdata with more variables in parent" begin
m = StructuredModel(num_scenarios=1)
@variable(m, x[1:2])
@objective(m, :Min, sum(x))

bl = StructuredModel(parent=m, id=1)
@variable(bl, y)
@constraint(bl, 4y + 5x[1] + 6x[2] >= 2)
@objective(bl, :Max, 3y)

c, A, B, b, var_cones, con_cones, v = StructJuMP.conicconstraintdata(bl)
@test c == [-3]
@test A == [5 6]
@test B == reshape([4], 1, 1)
@test b == [2]
@test length(var_cones) == 1
@test var_cones[1][1] == :Free
@test collect(var_cones[1][2]) == [1]
@test con_cones[1][1] == :NonPos
@test collect(con_cones[1][2]) == [1]
@test v == [:Cont]
end

@testset "[Benders] Empty scenario test" begin

m = StructuredModel(num_scenarios=0)
Expand Down

0 comments on commit a00a92c

Please sign in to comment.