Skip to content

Commit a00a92c

Browse files
blegatjoehuchette
authored andcommitted
Fix conicconstraintdata when parent has more columns (#51)
1 parent 8241d2d commit a00a92c

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/BendersBridge.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@ function conicconstraintdata(m::Model)
5151
V_s = Float64[]
5252

5353
# Fill it up
54-
tmprow = JuMP.IndexedVector(Float64,m.numCols)
54+
if numMasterCols > 0
55+
tmprow_m = JuMP.IndexedVector(Float64, parent.numCols)
56+
end
57+
tmprow_s = JuMP.IndexedVector(Float64, m.numCols)
5558

5659
JuMP.fillconstrRHS!(b, con_cones, 0, m.linconstr)
5760
if numMasterCols > 0
58-
JuMP.fillconstrLHS!(I_m, J_m, V_m, tmprow, 0, m.linconstr, parent, true)
61+
JuMP.fillconstrLHS!(I_m, J_m, V_m, tmprow_m, 0, m.linconstr, parent, true)
5962
end
60-
c = JuMP.fillconstrLHS!(I_s, J_s, V_s, tmprow, 0, m.linconstr, m, true)
63+
c = JuMP.fillconstrLHS!(I_s, J_s, V_s, tmprow_s, 0, m.linconstr, m, true)
6164

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

7174
JuMP.fillconstrRHS!(b, con_cones, c, m.socconstr)
7275
if numMasterCols > 0
73-
JuMP.fillconstrLHS!(I_m, J_m, V_m, tmprow, c, m.socconstr, parent, true)
76+
JuMP.fillconstrLHS!(I_m, J_m, V_m, tmprow_m, c, m.socconstr, parent, true)
7477
end
75-
c = JuMP.fillconstrLHS!(I_s, J_s, V_s, tmprow, c, m.socconstr, m, true)
78+
c = JuMP.fillconstrLHS!(I_s, J_s, V_s, tmprow_s, c, m.socconstr, m, true)
7679

7780
@assert c == numLinRows + numBounds + numSOCRows
7881

7982
if numMasterCols > 0
80-
c, d = JuMP.fillconstr!(I_m, J_m, V_m, b, con_cones, tmprow, constr_to_row, c, d, m.sdpconstr, m, true)
83+
c, d = JuMP.fillconstr!(I_m, J_m, V_m, b, con_cones, tmprow_m, constr_to_row, c, d, m.sdpconstr, m, true)
8184
end
82-
c, d = JuMP.fillconstr!(I_s, J_s, V_s, b, con_cones, tmprow, constr_to_row, c, d, m.sdpconstr, m, true)
85+
c, d = JuMP.fillconstr!(I_s, J_s, V_s, b, con_cones, tmprow_s, constr_to_row, c, d, m.sdpconstr, m, true)
8386

8487
if c < length(b)
8588
# This happens for example when symmetry constraints are dropped with SDP

test/benderstest.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@ using Base.Test
77
misocp_solver = CbcSolver()
88
socp_solver = ECOS.ECOSSolver(verbose=false)
99

10+
@testset "[Benders] conicconstraintdata with more variables in parent" begin
11+
m = StructuredModel(num_scenarios=1)
12+
@variable(m, x[1:2])
13+
@objective(m, :Min, sum(x))
14+
15+
bl = StructuredModel(parent=m, id=1)
16+
@variable(bl, y)
17+
@constraint(bl, 4y + 5x[1] + 6x[2] >= 2)
18+
@objective(bl, :Max, 3y)
19+
20+
c, A, B, b, var_cones, con_cones, v = StructJuMP.conicconstraintdata(bl)
21+
@test c == [-3]
22+
@test A == [5 6]
23+
@test B == reshape([4], 1, 1)
24+
@test b == [2]
25+
@test length(var_cones) == 1
26+
@test var_cones[1][1] == :Free
27+
@test collect(var_cones[1][2]) == [1]
28+
@test con_cones[1][1] == :NonPos
29+
@test collect(con_cones[1][2]) == [1]
30+
@test v == [:Cont]
31+
end
32+
1033
@testset "[Benders] Empty scenario test" begin
1134

1235
m = StructuredModel(num_scenarios=0)

0 commit comments

Comments
 (0)