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

add tests stop_when_inf_db and infeasible_phase_output #858

Merged
merged 9 commits into from
May 4, 2023
18 changes: 13 additions & 5 deletions src/Algorithm/colgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,8 @@ function _new_context(C::Type{<:ColGen.AbstractColGenContext}, reform, algo)
return C(reform, algo)
end

function run!(algo::ColumnGeneration, env::Env, reform::Reformulation, input::OptimizationState)
C = _colgen_context(algo)
ctx = _new_context(C, reform, algo)
result = ColGen.run!(ctx, env, get_best_ip_primal_sol(input))
function _colgen_optstate_output(result, master)

master = getmaster(reform)
optstate = OptimizationState(master)

if result.infeasible
Expand All @@ -155,9 +151,21 @@ function run!(algo::ColumnGeneration, env::Env, reform::Reformulation, input::Op
set_lp_dual_bound!(optstate, DualBound(master, result.db))
set_ip_dual_bound!(optstate, DualBound(master, result.db))
end

return optstate
end

function run!(algo::ColumnGeneration, env::Env, reform::Reformulation, input::OptimizationState)
C = _colgen_context(algo)
ctx = _new_context(C, reform, algo)
result = ColGen.run!(ctx, env, get_best_ip_primal_sol(input))

master = getmaster(reform)


najaverzat marked this conversation as resolved.
Show resolved Hide resolved
return _colgen_optstate_output(result, master)
end

### BELOW: delete before v0.6

# function run!(algo::ColumnGeneration, env::Env, reform::Reformulation, input::OptimizationState)
Expand Down
63 changes: 63 additions & 0 deletions test/unit/ColGen/colgen_phase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,67 @@ function continue_colgen_phase_otherwise()
end
register!(unit_tests, "colgen_phase", continue_colgen_phase_otherwise)

function stop_when_inf_db()
reform, _, _ = get_reform_master_and_vars()
ctx = ClA.ColGenContext(reform, ClA.ColumnGeneration())
colgen_iteration = 1
env = nothing

colgen_iter_output = ClA.ColGenIterationOutput(
true,
4578,
Inf,
1,
false,
false,
false,
false,
false,
false,
nothing,
nothing,
nothing
)

@test_broken ColGen.stop_colgen_phase(ctx, ClA.ColGenPhase1(), env, colgen_iter_output, colgen_iteration)
end
register!(unit_tests, "colgen_phase", stop_when_inf_db)


function infeasible_phase_output()

reform, _, _ = get_reform_master_and_vars()
ctx = ClA.ColGenContext(reform, ClA.ColumnGeneration())

colgen_phase_output = ClA.ColGenPhaseOutput(
nothing,
nothing,
nothing,
167673.9643, #mlp
162469.0291, #db
false,
true,
true, #infeasible
true, #exact_stage
false,
6
)

@test ColGen.stop_colgen(ctx, colgen_phase_output)
najaverzat marked this conversation as resolved.
Show resolved Hide resolved

colgen_output = ColGen.new_output(ClA.ColGenOutput, colgen_phase_output)

@test colgen_output.infeasible == true
@test isnothing(colgen_output.master_lp_primal_sol)
@test isnothing(colgen_output.master_ip_primal_sol)
@test isnothing(colgen_output.master_lp_dual_sol)
@test_broken isnothing(colgen_output.mlp)
@test_broken isnothing(colgen_output.db)

master = ClA.getmaster(reform)
optstate = ClA._colgen_optstate_output(colgen_output, master)

@test optstate.termination_status == ClA.INFEASIBLE

end
register!(unit_tests, "colgen_phase", infeasible_phase_output)