Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize twice #462

Merged
merged 12 commits into from
Mar 9, 2021
4 changes: 3 additions & 1 deletion src/decomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ function buildformulations!(
end

function reformulate!(prob::Problem, annotations::Annotations, env::Env)
closefillmode!(getcoefmatrix(prob.original_formulation))
if getcoefmatrix(prob.original_formulation).fillmode
closefillmode!(getcoefmatrix(prob.original_formulation))
end
decomposition_tree = annotations.tree
if decomposition_tree !== nothing
root = BD.getroot(decomposition_tree)
Expand Down
5 changes: 5 additions & 0 deletions src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Starting point of the solver.
function optimize!(prob::MathProg.Problem, annotations::Annotations, params::Params)
_welcome_message()

buffer_reset = prob.original_formulation.buffer
ann_pf_reset = annotations.ann_per_form

# Adjust parameters
## Retrieve initial bounds on the objective given by the user
init_pb = get_initial_primal_bound(prob)
Expand All @@ -63,6 +66,8 @@ function optimize!(prob::MathProg.Problem, annotations::Annotations, params::Par
end

env.kpis.elapsed_optimization_time = elapsed_optim_time(env)
prob.original_formulation.buffer = buffer_reset
annotations.ann_per_form = ann_pf_reset

println(_to)
TO.reset_timer!(_to)
Expand Down
66 changes: 66 additions & 0 deletions test/issues_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,68 @@ function solve_empty_model()
@test_throws ErrorException optimize!(model)
end

function optimize_twice()
# no reformulation + direct model
coluna = JuMP.optimizer_with_attributes(
Coluna.Optimizer,
"params" => CL.Params(solver = ClA.SolveIpForm()),
"default_optimizer" => GLPK.Optimizer
)
model = BlockModel(coluna, direct_model = true)
@variable(model, x)
@constraint(model, x <= 1)
@objective(model, Max, x)
optimize!(model)
@test JuMP.objective_value(model) == 1
optimize!(model)
@test JuMP.objective_value(model) == 1

# no reformulation + no direct model
model = BlockModel(coluna)
@variable(model, x)
@constraint(model, x <= 1)
@objective(model, Max, x)
optimize!(model)
@test JuMP.objective_value(model) == 1
optimize!(model)
@test JuMP.objective_value(model) == 1

# reformulation + direct model
data = CLD.GeneralizedAssignment.data("play2.txt")
coluna = JuMP.optimizer_with_attributes(
Coluna.Optimizer,
"params" => CL.Params(solver = ClA.TreeSearchAlgorithm(
branchingtreefile = "playgap.dot"
)),
"default_optimizer" => GLPK.Optimizer
)
model, x, dec = CLD.GeneralizedAssignment.model(data, coluna)
BD.objectiveprimalbound!(model, 100)
BD.objectivedualbound!(model, 0)
optimize!(model)
@test JuMP.objective_value(model) ≈ 75.0
optimize!(model)
@test JuMP.objective_value(model) ≈ 75.0

# # reformulation + no direct model (`CLD.GeneralizedAssignment.model(data, coluna, false)` threw
# # "MethodError: no method matching Model(; direct_model=false)")
# model = BlockModel(coluna)
# @axis(M, data.machines)
# @variable(model, x[m in M, j in data.jobs], Bin)
# @constraint(model, cov[j in data.jobs], sum(x[m,j] for m in M) >= 1)
# @constraint(model, knp[m in M], sum(data.weight[j,m]*x[m,j] for j in data.jobs) <= data.capacity[m])
# @objective(model, Min, sum(data.cost[j,m]*x[m,j] for m in M, j in data.jobs))
# @dantzig_wolfe_decomposition(model, dec, M)
# subproblems = BlockDecomposition.getsubproblems(dec)
# specify!.(subproblems, lower_multiplicity = 0)
# BD.objectiveprimalbound!(model, 100)
# BD.objectivedualbound!(model, 0)
# optimize!(model)
# @test JuMP.objective_value(model) ≈ 75.0
# optimize!(model)
# @test JuMP.objective_value(model) ≈ 75.0
end

function test_issues_fixed()
@testset "no_decomposition" begin
solve_with_no_decomposition()
Expand All @@ -125,6 +187,10 @@ function test_issues_fixed()
@testset "solve_empty_model" begin
solve_empty_model()
end

@testset "optimize_twice()" begin
optimize_twice()
end
end

test_issues_fixed()