Skip to content

Commit

Permalink
rm propagation of objective constant in subsolver (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
guimarqu authored Apr 15, 2022
1 parent f527345 commit 5cee601
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
8 changes: 0 additions & 8 deletions src/MathProg/MOIinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ function update_cost_in_optimizer!(form::Formulation, optimizer::MoiOptimizer, v
return
end

function update_obj_const_in_optimizer!(form::Formulation, optimizer::MoiOptimizer)
MOI.modify(
getinner(optimizer), MoiObjective(),
MOI.ScalarConstantChange{Float64}(getobjconst(form))
)
return
end

function update_constr_member_in_optimizer!(
optimizer::MoiOptimizer, c::Constraint, v::Variable, coeff::Float64
)
Expand Down
4 changes: 1 addition & 3 deletions src/MathProg/buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Changes must be always buffered.
"""
mutable struct FormulationBuffer{Vi,V,Ci,C}
changed_obj_sense::Bool # sense of the objective function
changed_obj_const::Bool # constant in the objective function
changed_cost::Set{Vi} # cost of a variable
changed_bound::Set{Vi} # bound of a variable
changed_var_kind::Set{Vi} # kind of a variable
Expand All @@ -65,14 +64,13 @@ mutable struct FormulationBuffer{Vi,V,Ci,C}
end

FormulationBuffer{Vi,V,Ci,C}() where {Vi,V,Ci,C} = FormulationBuffer(
false, false, Set{Vi}(), Set{Vi}(), Set{Vi}(), Set{Ci}(),
false, Set{Vi}(), Set{Vi}(), Set{Vi}(), Set{Ci}(),
VarConstrBuffer{Vi, V}(), VarConstrBuffer{Ci, C}(),
Dict{Pair{Ci,Vi},Float64}()
)

function empty!(buffer::FormulationBuffer{Vi,V,Ci,C}) where {Vi,V,Ci,C}
buffer.changed_obj_sense = false
buffer.changed_obj_const = false
buffer.changed_cost = Set{Vi}()
buffer.changed_bound = Set{Vi}()
buffer.changed_var_kind = Set{Vi}()
Expand Down
1 change: 0 additions & 1 deletion src/MathProg/formulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ getobjconst(form::Formulation) = form.manager.objective_constant
"Sets objective constant of the formulation."
function setobjconst!(form::Formulation, val::Float64)
form.manager.objective_constant = val
form.buffer.changed_obj_const = true
return
end

Expand Down
6 changes: 0 additions & 6 deletions src/MathProg/optimizerwrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ function sync_solver!(optimizer::MoiOptimizer, f::Formulation)
update_cost_in_optimizer!(f, optimizer, getvar(f, id))
end

# Update objective constant
if buffer.changed_obj_const
update_obj_const_in_optimizer!(f, optimizer)
buffer.changed_obj_const = false
end

# Update objective sense
if buffer.changed_obj_sense
set_obj_sense!(optimizer, getobjsense(f))
Expand Down
30 changes: 30 additions & 0 deletions test/e2e/generalized_assignment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,34 @@
@test JuMP.objective_value(model) 75.0
@test JuMP.termination_status(model) == MOI.OPTIMAL
end

@testset "toy instance with objective constant" begin
M = 1:3;
J = 1:15;
c = [12.7 22.5 8.9 20.8 13.6 12.4 24.8 19.1 11.5 17.4 24.7 6.8 21.7 14.3 10.5; 19.1 24.8 24.4 23.6 16.1 20.6 15.0 9.5 7.9 11.3 22.6 8.0 21.5 14.7 23.2; 18.6 14.1 22.7 9.9 24.2 24.5 20.8 12.9 17.7 11.9 18.7 10.1 9.1 8.9 7.7; 13.1 16.2 16.8 16.7 9.0 16.9 17.9 12.1 17.5 22.0 19.9 14.6 18.2 19.6 24.2];
w = [61 70 57 82 51 74 98 64 86 80 69 79 60 76 78; 50 57 61 83 81 79 63 99 82 59 83 91 59 99 91;91 81 66 63 59 81 87 90 65 55 57 68 92 91 86; 62 79 73 60 75 66 68 99 69 60 56 100 67 68 54];
Q = [1020 1460 1530];

coluna = optimizer_with_attributes(
Coluna.Optimizer,
"params" => Coluna.Params(
solver = Coluna.Algorithm.TreeSearchAlgorithm() # default branch-cut-and-price
),
"default_optimizer" => GLPK.Optimizer # GLPK for the master & the subproblems
);

model = BlockModel(coluna)
@axis(M_axis, M);
@variable(model, x[m in M_axis, j in J], Bin);
@constraint(model, cov[j in J], sum(x[m, j] for m in M_axis) >= 1);
@constraint(model, knp[m in M_axis], sum(w[m, j] * x[m, j] for j in J) <= Q[m]);
@objective(model, Min, sum(c[m, j] * x[m, j] for m in M_axis, j in J) + 250);
@dantzig_wolfe_decomposition(model, decomposition, M_axis)
subproblems = getsubproblems(decomposition)
specify!.(subproblems, lower_multiplicity = 0, upper_multiplicity = 1)
optimize!(model)

@test JuMP.objective_value(model) 250 + 166.5
return
end
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ include("ColunaTests.jl")
retest(Coluna, ColunaTests)

# Run a specific test:
#retest(ColunaTests, "MathProg - buffer")
#retest(ColunaTests, "toy instance with objective constant")
2 changes: 0 additions & 2 deletions test/unit/MathProg/buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ end

function _test_buffer(current::ClMP.FormulationBuffer, expected::ClMP.FormulationBuffer)
@test isequal(current.changed_obj_sense, expected.changed_obj_sense)
@test isequal(current.changed_obj_const, expected.changed_obj_const)
@test isequal(current.changed_cost, expected.changed_cost)
@test isequal(current.changed_bound, expected.changed_bound)
@test isequal(current.changed_var_kind, expected.changed_var_kind)
Expand All @@ -35,7 +34,6 @@ _empty_buffer() = ClMP.FormulationBuffer{ClMP.VarId,ClMP.Variable,ClMP.ConstrId,
constrid = ClMP.getid(constr)
expected_buffer = _empty_buffer()
expected_buffer.changed_obj_sense = false # minimization by default
expected_buffer.changed_obj_const = false
expected_buffer.var_buffer = ClMP.VarConstrBuffer{ClMP.VarId, ClMP.Variable}()
expected_buffer.var_buffer.added = Set([varid])
expected_buffer.constr_buffer = ClMP.VarConstrBuffer{ClMP.ConstrId, ClMP.Constraint}()
Expand Down

0 comments on commit 5cee601

Please sign in to comment.