Skip to content

Commit

Permalink
Fix the double addition of deactivated columns (#727)
Browse files Browse the repository at this point in the history
* Fixed a bug in the double addition of a column that was deactivated in the master

* improve fix + test

Co-authored-by: Guillaume Marques <[email protected]>
  • Loading branch information
artalvpes and guimarqu authored Sep 27, 2022
1 parent fa33acb commit a11158d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
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

0 comments on commit a11158d

Please sign in to comment.