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

Fix the double addition of deactivated columns #727

Merged
merged 3 commits into from
Sep 27, 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
16 changes: 11 additions & 5 deletions src/Algorithm/colgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,17 +456,14 @@ function insert_columns!(
if !isnothing(bestsol) && getstatus(bestsol) == FEASIBLE_SOL
# First we activate columns that are already in the pool.
primal_sols_to_insert = PrimalSolution{Formulation{DwSp}}[]
col_ids_to_activate = Set{VarId}()
sols = get_ip_primal_sols(sp_optstate)
for (sol, red_cost) in Iterators.zip(sols, redcosts_spsols)
if improving_red_cost(red_cost, algo, getobjsense(masterform))
col_id = get_column_from_pool(sol)
if !isnothing(col_id)
if haskey(masterform, col_id) && !iscuractive(masterform, col_id)
activate!(masterform, col_id)
if phase == 1
setcurcost!(masterform, col_id, 0.0)
end
nb_cols_generated += 1
push!(col_ids_to_activate, col_id)
else
in_master = haskey(masterform, col_id)
is_active = iscuractive(masterform, col_id)
Expand All @@ -488,6 +485,15 @@ function insert_columns!(
end
nb_cols_generated += 1
end

# And we reactivate the deactivated columns already generated.
for col_id in col_ids_to_activate
activate!(masterform, col_id)
if phase == 1
setcurcost!(masterform, col_id, 0.0)
end
nb_cols_generated += 1
end
return nb_cols_generated
end
return -1
Expand Down
42 changes: 40 additions & 2 deletions test/unit/Algorithm/colgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,45 @@ end
@test nb_new_cols == 2
end

@testset "Stabilization" begin

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

# Add column.
col1 = ClMP.PrimalSolution(
spform,
map(x -> ClMP.getid(spvars[x]), ["x1", "x3"]),
[1.0, 2.0],
1.0,
ClB.FEASIBLE_SOL
)
col_id = ClA.insert_column!(master, col1, "MC")

# Deactivate column.
ClMP.deactivate!(master, col_id)

# Add same column twice.
redcosts_spsols = [-2.0, -2.0]
phase = 1

sp_optstate = ClA.OptimizationState(spform; max_length_ip_primal_sols = 5)
col2 = ClMP.PrimalSolution(
spform,
map(x -> ClMP.getid(spvars[x]), ["x1", "x3"]),
[1.0, 2.0],
1.0,
ClB.FEASIBLE_SOL
)
col3 = ClMP.PrimalSolution(
spform,
map(x -> ClMP.getid(spvars[x]), ["x1", "x3"]),
[1.0, 2.0],
2.0,
ClB.FEASIBLE_SOL
)
ClA.add_ip_primal_sols!(sp_optstate, col2, col3)

nb_new_cols = ClA.insert_columns!(master, sp_optstate, redcosts_spsols, algo, phase)
@test nb_new_cols == 1
end
end