From e4f1968183c3581be3452b8919ac39823982cdc5 Mon Sep 17 00:00:00 2001 From: Natacha Javerzat Date: Tue, 2 May 2023 17:01:46 +0200 Subject: [PATCH 1/7] add tests stop_when_inf_db and infeasible_phase_output --- test/unit/ColGen/colgen_phase.jl | 89 ++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/test/unit/ColGen/colgen_phase.jl b/test/unit/ColGen/colgen_phase.jl index 6c1ba8ec4..2ead7ff3d 100644 --- a/test/unit/ColGen/colgen_phase.jl +++ b/test/unit/ColGen/colgen_phase.jl @@ -451,4 +451,93 @@ 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 ColGen.stop_colgen_phase(ctx, ClA.ColGenPhase1(), env, colgen_iter_output, colgen_iteration) +end +register!(unit_tests, "colgen_phase", stop_when_inf_db) + + +function mock_run(result, master, optstate) + + if result.infeasible + ClA.setterminationstatus!(optstate, ClA.INFEASIBLE) + end + + if !isnothing(result.master_lp_primal_sol) + ClA.set_lp_primal_sol!(optstate, result.master_lp_primal_sol) + end + if !isnothing(result.master_ip_primal_sol) + ClA.update_ip_primal_sol!(optstate, result.master_ip_primal_sol) + end + + if !isnothing(result.master_lp_dual_sol) + ClA.update_lp_dual_sol!(optstate, result.master_lp_dual_sol) + end + + if !isnothing(result.db) + ClA.set_lp_dual_bound!(optstate, DualBound(master, result.db)) + ClA.set_ip_dual_bound!(optstate, DualBound(master, result.db)) + end + return optstate + +end + +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) + + 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 isnothing(colgen_output.mlp) + @test isnothing(colgen_output.db) + + master = ClA.getmaster(reform) + optstate = mock_run(colgen_output, master, ClA.OptimizationState(master)) + + @test optstate.termination_status == ClA.INFEASIBLE + +end +register!(unit_tests, "colgen_phase", infeasible_phase_output) \ No newline at end of file From a5ee25262bc50531a7ba20263dae524a6c237521 Mon Sep 17 00:00:00 2001 From: Natacha Javerzat Date: Wed, 3 May 2023 16:44:19 +0200 Subject: [PATCH 2/7] create aux function for run! in colgen.jl, update tests --- src/Algorithm/colgen.jl | 21 ++++++++++++++------- test/unit/ColGen/colgen_phase.jl | 28 +--------------------------- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/src/Algorithm/colgen.jl b/src/Algorithm/colgen.jl index 04808c883..8f3b1f0c7 100644 --- a/src/Algorithm/colgen.jl +++ b/src/Algorithm/colgen.jl @@ -127,13 +127,7 @@ 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)) - - master = getmaster(reform) - optstate = OptimizationState(master) +function _colgen_optstate_output(result, master, optstate) if result.infeasible setterminationstatus!(optstate, INFEASIBLE) @@ -155,9 +149,22 @@ 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) + optstate = OptimizationState(master) + + return _colgen_optstate_output(result, master, optstate) + +end + ### BELOW: delete before v0.6 # function run!(algo::ColumnGeneration, env::Env, reform::Reformulation, input::OptimizationState) diff --git a/test/unit/ColGen/colgen_phase.jl b/test/unit/ColGen/colgen_phase.jl index 2ead7ff3d..e7d8bb0e2 100644 --- a/test/unit/ColGen/colgen_phase.jl +++ b/test/unit/ColGen/colgen_phase.jl @@ -478,32 +478,6 @@ end register!(unit_tests, "colgen_phase", stop_when_inf_db) -function mock_run(result, master, optstate) - - if result.infeasible - ClA.setterminationstatus!(optstate, ClA.INFEASIBLE) - end - - if !isnothing(result.master_lp_primal_sol) - ClA.set_lp_primal_sol!(optstate, result.master_lp_primal_sol) - end - - if !isnothing(result.master_ip_primal_sol) - ClA.update_ip_primal_sol!(optstate, result.master_ip_primal_sol) - end - - if !isnothing(result.master_lp_dual_sol) - ClA.update_lp_dual_sol!(optstate, result.master_lp_dual_sol) - end - - if !isnothing(result.db) - ClA.set_lp_dual_bound!(optstate, DualBound(master, result.db)) - ClA.set_ip_dual_bound!(optstate, DualBound(master, result.db)) - end - return optstate - -end - function infeasible_phase_output() reform, _, _ = get_reform_master_and_vars() @@ -535,7 +509,7 @@ function infeasible_phase_output() @test isnothing(colgen_output.db) master = ClA.getmaster(reform) - optstate = mock_run(colgen_output, master, ClA.OptimizationState(master)) + optstate = ClA._colgen_optstate_output(colgen_output, master, ClA.OptimizationState(master)) @test optstate.termination_status == ClA.INFEASIBLE From 73d2329a7654f16f45c6f25201c8168c73e4e4c0 Mon Sep 17 00:00:00 2001 From: NatachaJaverzat <95150195+enjoyUrFruits@users.noreply.github.com> Date: Wed, 3 May 2023 17:05:22 +0200 Subject: [PATCH 3/7] Update src/Algorithm/colgen.jl Co-authored-by: Guillaume Marques --- src/Algorithm/colgen.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Algorithm/colgen.jl b/src/Algorithm/colgen.jl index 8f3b1f0c7..59458c692 100644 --- a/src/Algorithm/colgen.jl +++ b/src/Algorithm/colgen.jl @@ -162,7 +162,6 @@ function run!(algo::ColumnGeneration, env::Env, reform::Reformulation, input::Op optstate = OptimizationState(master) return _colgen_optstate_output(result, master, optstate) - end ### BELOW: delete before v0.6 From 00a78e18028593d5b5a4b2a11759a4bebfe0c45a Mon Sep 17 00:00:00 2001 From: NatachaJaverzat <95150195+enjoyUrFruits@users.noreply.github.com> Date: Wed, 3 May 2023 17:05:31 +0200 Subject: [PATCH 4/7] Update test/unit/ColGen/colgen_phase.jl Co-authored-by: Guillaume Marques --- test/unit/ColGen/colgen_phase.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/ColGen/colgen_phase.jl b/test/unit/ColGen/colgen_phase.jl index e7d8bb0e2..df4634151 100644 --- a/test/unit/ColGen/colgen_phase.jl +++ b/test/unit/ColGen/colgen_phase.jl @@ -473,7 +473,7 @@ function stop_when_inf_db() nothing ) - @test ColGen.stop_colgen_phase(ctx, ClA.ColGenPhase1(), env, colgen_iter_output, colgen_iteration) + @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) From 32b25f79ed28b81c6b8df121f1f6b285e9f8e056 Mon Sep 17 00:00:00 2001 From: NatachaJaverzat <95150195+enjoyUrFruits@users.noreply.github.com> Date: Wed, 3 May 2023 17:05:38 +0200 Subject: [PATCH 5/7] Update test/unit/ColGen/colgen_phase.jl Co-authored-by: Guillaume Marques --- test/unit/ColGen/colgen_phase.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/ColGen/colgen_phase.jl b/test/unit/ColGen/colgen_phase.jl index df4634151..8b019ab93 100644 --- a/test/unit/ColGen/colgen_phase.jl +++ b/test/unit/ColGen/colgen_phase.jl @@ -497,7 +497,7 @@ function infeasible_phase_output() 6 ) - @test ColGen.stop_colgen(ctx, colgen_phase_output) + @test_broken ColGen.stop_colgen(ctx, colgen_phase_output) colgen_output = ColGen.new_output(ClA.ColGenOutput, colgen_phase_output) From 549c11b9d581b238ea59f3536f33979f3221911d Mon Sep 17 00:00:00 2001 From: Natacha Javerzat Date: Wed, 3 May 2023 17:09:55 +0200 Subject: [PATCH 6/7] fix run aux method --- src/Algorithm/colgen.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Algorithm/colgen.jl b/src/Algorithm/colgen.jl index 59458c692..dc68f890b 100644 --- a/src/Algorithm/colgen.jl +++ b/src/Algorithm/colgen.jl @@ -127,7 +127,9 @@ function _new_context(C::Type{<:ColGen.AbstractColGenContext}, reform, algo) return C(reform, algo) end -function _colgen_optstate_output(result, master, optstate) +function _colgen_optstate_output(result, master) + + optstate = OptimizationState(master) if result.infeasible setterminationstatus!(optstate, INFEASIBLE) @@ -159,9 +161,9 @@ function run!(algo::ColumnGeneration, env::Env, reform::Reformulation, input::Op result = ColGen.run!(ctx, env, get_best_ip_primal_sol(input)) master = getmaster(reform) - optstate = OptimizationState(master) + - return _colgen_optstate_output(result, master, optstate) + return _colgen_optstate_output(result, master) end ### BELOW: delete before v0.6 From d404dee317e900b8943c4642fb4ebbc590245ed5 Mon Sep 17 00:00:00 2001 From: Natacha Javerzat Date: Thu, 4 May 2023 10:04:39 +0200 Subject: [PATCH 7/7] add broken tag, fix load error --- test/unit/ColGen/colgen_phase.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/ColGen/colgen_phase.jl b/test/unit/ColGen/colgen_phase.jl index 8b019ab93..1cb7cd96b 100644 --- a/test/unit/ColGen/colgen_phase.jl +++ b/test/unit/ColGen/colgen_phase.jl @@ -497,7 +497,7 @@ function infeasible_phase_output() 6 ) - @test_broken ColGen.stop_colgen(ctx, colgen_phase_output) + @test ColGen.stop_colgen(ctx, colgen_phase_output) colgen_output = ColGen.new_output(ClA.ColGenOutput, colgen_phase_output) @@ -505,11 +505,11 @@ function infeasible_phase_output() @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 isnothing(colgen_output.mlp) - @test isnothing(colgen_output.db) + @test_broken isnothing(colgen_output.mlp) + @test_broken isnothing(colgen_output.db) master = ClA.getmaster(reform) - optstate = ClA._colgen_optstate_output(colgen_output, master, ClA.OptimizationState(master)) + optstate = ClA._colgen_optstate_output(colgen_output, master) @test optstate.termination_status == ClA.INFEASIBLE