From a00a92c4285447759a74ef4d12b9e8a675d78914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 1 Jun 2017 16:16:48 +0200 Subject: [PATCH] Fix conicconstraintdata when parent has more columns (#51) --- src/BendersBridge.jl | 17 ++++++++++------- test/benderstest.jl | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/BendersBridge.jl b/src/BendersBridge.jl index f002f2b..d9c3117 100644 --- a/src/BendersBridge.jl +++ b/src/BendersBridge.jl @@ -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 @@ -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 diff --git a/test/benderstest.jl b/test/benderstest.jl index 04b1839..ceb0974 100644 --- a/test/benderstest.jl +++ b/test/benderstest.jl @@ -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)