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

Column already insert not an error anymore #753

Merged
merged 3 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Algorithm/colgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
max_nb_iterations = 1000,
log_print_frequency = 1,
redcost_tol = 1e-4,
show_column_already_inserted_warning = true,
cleanup_threshold = 10000,
cleanup_ratio = 0.66,
smoothing_stabilization = 0.0 # should be in [0, 1],
Expand Down Expand Up @@ -74,6 +75,8 @@ Here are their meanings :
log_print_frequency::Int64 = 1
store_all_ip_primal_sols::Bool = false
redcost_tol::Float64 = 1e-4
show_column_already_inserted_warning = true
throw_column_already_inserted_warning = false
solve_subproblems_parallel::Bool = false
cleanup_threshold::Int64 = 10000
cleanup_ratio::Float64 = 0.66
Expand Down Expand Up @@ -119,7 +122,7 @@ reduced cost in min (resp. max) problem that already exists in the master
and that is already active.
An active master column cannot have a negative reduced cost.
"""
struct ColumnAlreadyInsertedColGenError
struct ColumnAlreadyInsertedColGenWarning
column_in_master::Bool
column_is_active::Bool
column_reduced_cost::Float64
Expand All @@ -128,7 +131,7 @@ struct ColumnAlreadyInsertedColGenError
subproblem::Formulation{DwSp}
end

function Base.show(io::IO, err::ColumnAlreadyInsertedColGenError)
function Base.show(io::IO, err::ColumnAlreadyInsertedColGenWarning)
msg = """
Unexpected variable state during column insertion.
======
Expand Down Expand Up @@ -469,9 +472,15 @@ function insert_columns!(
else
in_master = haskey(masterform, col_id)
is_active = iscuractive(masterform, col_id)
throw(ColumnAlreadyInsertedColGenError(
warning = ColumnAlreadyInsertedColGenWarning(
in_master, is_active, red_cost, col_id, masterform, sol.solution.model
))
)
if algo.show_column_already_inserted_warning
@warn warning
end
if algo.throw_column_already_inserted_warning
throw(warning)
end
end
else
push!(primal_sols_to_insert, sol)
Expand Down
18 changes: 13 additions & 5 deletions test/unit/Algorithm/colgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ end
@testset "Two identical columns at two iterations" begin
# Expected: unexpected variable state error.
env, master, spform, spvars, constr = reformulation_for_colgen()
algo = ClA.ColumnGeneration()
algo = ClA.ColumnGeneration(
throw_column_already_inserted_warning = true
)
phase = 1

## Iteration 1
Expand Down Expand Up @@ -83,13 +85,15 @@ end
)
ClA.add_ip_primal_sols!(sp_optstate, col3)

@test_throws ClA.ColumnAlreadyInsertedColGenError ClA.insert_columns!(master, sp_optstate, redcosts_spsols, algo, phase)
@test_throws ClA.ColumnAlreadyInsertedColGenWarning ClA.insert_columns!(master, sp_optstate, redcosts_spsols, algo, phase)
end

@testset "Two identical columns at same iteration" begin
# Expected: no error and two identical columns in the formulation
env, master, spform, spvars, constr = reformulation_for_colgen()
algo = ClA.ColumnGeneration()
algo = ClA.ColumnGeneration(
throw_column_already_inserted_warning = true
)

redcosts_spsols = [-2.0, -2.0, 2.0]
phase = 1
Expand Down Expand Up @@ -124,7 +128,9 @@ end

@testset "Deactivated column added twice at same iteration" begin
env, master, spform, spvars, constr = reformulation_for_colgen()
algo = ClA.ColumnGeneration()
algo = ClA.ColumnGeneration(
throw_column_already_inserted_warning = true
)

# Add column.
col1 = ClMP.PrimalSolution(
Expand Down Expand Up @@ -166,7 +172,9 @@ end

@testset "Infeasible subproblem" begin
env, master, spform, spvars, constr = reformulation_for_colgen()
algo = ClA.ColumnGeneration()
algo = ClA.ColumnGeneration(
throw_column_already_inserted_warning = true
)

sp_optstate = ClA.OptimizationState(spform; termination_status = ClB.INFEASIBLE_OR_UNBOUNDED)

Expand Down