Skip to content

Commit

Permalink
enforce convergence condition (#861)
Browse files Browse the repository at this point in the history
* enforce convergence condition

* update tests

---------

Co-authored-by: Guillaume Marques <[email protected]>
  • Loading branch information
najaverzat and guimarqu authored May 4, 2023
1 parent f479bff commit 5bcbed5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
18 changes: 13 additions & 5 deletions src/Algorithm/colgen/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct ColGenPhaseOutput <: ColGen.AbstractColGenPhaseOutput
exact_stage::Bool
time_limit_reached::Bool
nb_iterations::Int
min_sense::Bool
end

struct ColGenOutput <: ColGen.AbstractColGenOutput
Expand Down Expand Up @@ -143,7 +144,12 @@ end

colgen_master_has_new_cuts(output::ColGenPhaseOutput) = output.new_cut_in_master
colgen_uses_exact_stage(output::ColGenPhaseOutput) = output.exact_stage
colgen_has_converged(output::ColGenPhaseOutput) = !isnothing(output.mlp) && !isnothing(output.db) && abs(output.mlp - output.db) < 1e-5
colgen_has_converged(output::ColGenPhaseOutput) = !isnothing(output.mlp) &&
!isnothing(output.db) && (
( abs(output.mlp - output.db) < 1e-5 ) ||
( (output.min_sense) && (output.db >= output.mlp) ) ||
( !(output.min_sense) && (output.db <= output.mlp) )
)
colgen_has_no_new_cols(output::ColGenPhaseOutput) = output.no_more_columns

## Implementation of `next_phase`.
Expand Down Expand Up @@ -684,7 +690,7 @@ ColGen.after_colgen_iteration(ctx::ColGenContext, phase, stage, env, colgen_iter

ColGen.colgen_phase_output_type(::ColGenContext) = ColGenPhaseOutput

function ColGen.new_phase_output(::Type{<:ColGenPhaseOutput}, phase, stage, colgen_iter_output::ColGenIterationOutput, iteration)
function ColGen.new_phase_output(::Type{<:ColGenPhaseOutput}, min_sense, phase, stage, colgen_iter_output::ColGenIterationOutput, iteration)
return ColGenPhaseOutput(
colgen_iter_output.master_lp_primal_sol,
colgen_iter_output.master_ip_primal_sol,
Expand All @@ -696,11 +702,12 @@ function ColGen.new_phase_output(::Type{<:ColGenPhaseOutput}, phase, stage, colg
colgen_iter_output.infeasible_master || colgen_iter_output.infeasible_subproblem,
ColGen.is_exact_stage(stage),
colgen_iter_output.time_limit_reached,
iteration
iteration,
min_sense
)
end

function ColGen.new_phase_output(::Type{<:ColGenPhaseOutput}, phase::ColGenPhase1, stage, colgen_iter_output::ColGenIterationOutput, iteration)
function ColGen.new_phase_output(::Type{<:ColGenPhaseOutput}, min_sense, phase::ColGenPhase1, stage, colgen_iter_output::ColGenIterationOutput, iteration)
return ColGenPhaseOutput(
colgen_iter_output.master_lp_primal_sol,
colgen_iter_output.master_ip_primal_sol,
Expand All @@ -712,7 +719,8 @@ function ColGen.new_phase_output(::Type{<:ColGenPhaseOutput}, phase::ColGenPhase
colgen_iter_output.infeasible_master || colgen_iter_output.infeasible_subproblem || abs(colgen_iter_output.mlp) > 1e-5,
ColGen.is_exact_stage(stage),
colgen_iter_output.time_limit_reached,
iteration
iteration,
min_sense
)
end

Expand Down
4 changes: 2 additions & 2 deletions src/ColGen/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function run_colgen_phase!(context, phase, stage, env, ip_primal_sol; iter = 1)
iteration += 1
end
O = colgen_phase_output_type(context)
return new_phase_output(O, phase, stage, colgen_iter_output, iteration)
return new_phase_output(O, is_minimization(context), phase, stage, colgen_iter_output, iteration)
end

function run!(context, env, ip_primal_sol; iter = 1)
Expand Down Expand Up @@ -237,7 +237,7 @@ abstract type AbstractColGenIterationOutput end

@mustimplement "ColGenIterationOutput" get_master_ip_primal_sol(::AbstractColGenIterationOutput) = nothing

@mustimplement "ColGenPhaseOutput" new_phase_output(::Type{<:AbstractColGenPhaseOutput}, phase, stage, ::AbstractColGenIterationOutput, iteration) = nothing
@mustimplement "ColGenPhaseOutput" new_phase_output(::Type{<:AbstractColGenPhaseOutput}, min_sense, phase, stage, ::AbstractColGenIterationOutput, iteration) = nothing

@mustimplement "ColGenPhaseOutput" get_master_ip_primal_sol(::AbstractColGenPhaseOutput) = nothing

Expand Down
3 changes: 2 additions & 1 deletion test/unit/ColGen/colgen_phase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ function infeasible_phase_output()
true, #infeasible
true, #exact_stage
false,
6
6,
true
)

@test ColGen.stop_colgen(ctx, colgen_phase_output)
Expand Down

0 comments on commit 5bcbed5

Please sign in to comment.