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

Proposition for presolve interface + put back StaticVarConstrUnit usage #1068

Merged
merged 1 commit into from
Sep 21, 2023
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
2 changes: 1 addition & 1 deletion src/Algorithm/basic/solveipform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function get_units_usage(
# are reverted before the end of the algorithm,
# so the state of the formulation remains the same
units_usage = Tuple{AbstractModel, UnitType, UnitPermission}[]
#push!(units_usage, (form, StaticVarConstrUnit, READ_ONLY))
push!(units_usage, (form, StaticVarConstrUnit, READ_ONLY))
if Duty <: MathProg.AbstractMasterDuty
push!(units_usage, (form, MasterColumnsUnit, READ_ONLY))
push!(units_usage, (form, MasterBranchConstrsUnit, READ_ONLY))
Expand Down
2 changes: 1 addition & 1 deletion src/Algorithm/basic/solvelpform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function get_units_usage(
# is reverted before the end of the algorithm,
# so the state of the formulation remains the same
units_usage = Tuple{AbstractModel, UnitType, UnitPermission}[]
#push!(units_usage, (form, StaticVarConstrUnit, READ_ONLY))
push!(units_usage, (form, StaticVarConstrUnit, READ_ONLY))
if Duty <: MathProg.AbstractMasterDuty
push!(units_usage, (form, MasterColumnsUnit, READ_ONLY))
push!(units_usage, (form, MasterBranchConstrsUnit, READ_ONLY))
Expand Down
8 changes: 4 additions & 4 deletions src/Algorithm/benders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@
push!(units_usage, (master, MasterCutsUnit, READ_AND_WRITE))

# TO DO : everything else should be communicated by the child algorithms
#push!(units_usage, (master, StaticVarConstrUnit, READ_ONLY))
push!(units_usage, (master, StaticVarConstrUnit, READ_ONLY))

Check warning on line 104 in src/Algorithm/benders.jl

View check run for this annotation

Codecov / codecov/patch

src/Algorithm/benders.jl#L104

Added line #L104 was not covered by tests
push!(units_usage, (master, MasterBranchConstrsUnit, READ_ONLY))
push!(units_usage, (master, MasterColumnsUnit, READ_ONLY))
# for (id, spform) in get_benders_sep_sps(reform)
# #push!(units_usage, (spform, StaticVarConstrUnit, READ_ONLY))
# end
for (_, spform) in get_benders_sep_sps(reform)
push!(units_usage, (spform, StaticVarConstrUnit, READ_ONLY))
end

Check warning on line 109 in src/Algorithm/benders.jl

View check run for this annotation

Codecov / codecov/patch

src/Algorithm/benders.jl#L107-L109

Added lines #L107 - L109 were not covered by tests
return units_usage
end

Expand Down
10 changes: 9 additions & 1 deletion src/Algorithm/colgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,15 @@ function get_units_usage(algo::ColumnGeneration, reform::Reformulation)
units_usage = Tuple{AbstractModel,UnitType,UnitPermission}[]
master = getmaster(reform)
push!(units_usage, (master, MasterColumnsUnit, READ_AND_WRITE))
#push!(units_usage, (master, PartialSolutionUnit, READ_ONLY))
push!(units_usage, (master, StaticVarConstrUnit, READ_ONLY))

# as column generation may call essential cut callbacks
# TO DO: it would be good to verify first whether any callback is really defined
push!(units_usage, (master, MasterCutsUnit, READ_AND_WRITE))

for (_, spform) in get_dw_pricing_sps(reform)
push!(units_usage, (spform, StaticVarConstrUnit, READ_ONLY))
end
if stabilization_is_used(algo)
#push!(units_usage, (master, ColGenStabilizationUnit, READ_AND_WRITE))
end
Expand Down
20 changes: 16 additions & 4 deletions src/Algorithm/presolve/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@
"""
struct PresolveAlgorithm <: AlgoAPI.AbstractAlgorithm
ϵ::Float64
update_sp_var_bounds::Bool
PresolveAlgorithm(;ϵ = 1e-6, update_sp_var_bounds = false) = new(ϵ, update_sp_var_bounds)
PresolveAlgorithm(;ϵ = Coluna.TOL) = new(ϵ)

Check warning on line 256 in src/Algorithm/presolve/interface.jl

View check run for this annotation

Codecov / codecov/patch

src/Algorithm/presolve/interface.jl#L256

Added line #L256 was not covered by tests
end

# PresolveAlgorithm does not have child algorithms, therefore get_child_algorithms() is not defined
Expand All @@ -265,18 +264,31 @@
push!(units_usage, (master, StaticVarConstrUnit, READ_AND_WRITE))
push!(units_usage, (master, MasterBranchConstrsUnit, READ_AND_WRITE))
push!(units_usage, (master, MasterCutsUnit, READ_AND_WRITE))
push!(units_usage, (master, MasterColumnsUnit, READ_ONLY))
push!(units_usage, (master, MasterColumnsUnit, READ_AND_WRITE))

Check warning on line 267 in src/Algorithm/presolve/interface.jl

View check run for this annotation

Codecov / codecov/patch

src/Algorithm/presolve/interface.jl#L267

Added line #L267 was not covered by tests
for (_, dw_sp) in get_dw_pricing_sps(reform)
push!(units_usage, (dw_sp, StaticVarConstrUnit, READ_AND_WRITE))
end
return units_usage
end

struct PresolveInput
partial_sol_to_fix::Dict{VarId, Float64}
# may be instead?
#partial_sol_to_fix::MathProg.PrimalSolution{Formulation{MasterDuty}}
end

struct PresolveOutput
feasible::Bool
end

function run!(algo::PresolveAlgorithm, ::Env, reform::Reformulation, _)::PresolveOutput
function run!(algo::PresolveAlgorithm, ::Env, reform::Reformulation, input::PresolveInput)::PresolveOutput

Check warning on line 284 in src/Algorithm/presolve/interface.jl

View check run for this annotation

Codecov / codecov/patch

src/Algorithm/presolve/interface.jl#L284

Added line #L284 was not covered by tests
# TO DO : if input.partial_sol_to_fix is not empty, we first need to
# 1) augment partial solution inside reform.master with input.partial_sol_to_fix
# 2) change RHS of master constraints correspondigly
# 3) fix pure master variables in input.partial_sol_to_fix
# 4) update global bounds of subproblem variables participating in columns in input.partial_sol_to_fix
# (see document FixingColumnInColuna.md)

treat!(algo, reform)
return PresolveOutput(true)
end
Expand Down
6 changes: 3 additions & 3 deletions test/revise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ include("e2e/run.jl")
include("e2e_extra/run.jl")

listen_to_tests([
#run_unit_tests,
run_unit_tests,
run_integration_tests,
#run_e2e_tests,
#run_e2e_extra_tests
run_e2e_tests,
run_e2e_extra_tests
])
2 changes: 1 addition & 1 deletion test/unit/Algorithm/record_staticvarconstr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function unit_static_var_constr_record1()
# make changes on the formulation
ClMP.setcurlb!(form, vars["v1"], 5.0)
ClMP.setcurub!(form, vars["v2"], 12.0)
ClMP.setcurcost!(form, vars["v3"], 4.0)
ClMP.setcurcost!(form, vars["v3"], 4.6)
ClMP.setcurrhs!(form, constrs["c1"], 1.0)
ClMP.deactivate!(form, constrs["c2"])

Expand Down
6 changes: 3 additions & 3 deletions test/unit/Presolve/partial_solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function test_partial_solution2()
@test all(form2.ubs .== [Inf, Inf])
@test all(form2.partial_solution .== [3.0, 3.0])
end
register!(unit_tests, "presolve_partial_sol", test_partial_solution2; f= true)
register!(unit_tests, "presolve_partial_sol", test_partial_solution2)

function test_partial_solution3()
# 2x + 3y <= 5
Expand Down Expand Up @@ -118,7 +118,7 @@ function test_partial_solution3()
@test all(form2.ubs .== [-0.0, 8.0])
@test all(form2.partial_solution .== [-3.0, 0.0])
end
register!(unit_tests, "presolve_partial_sol", test_partial_solution3; f= true)
register!(unit_tests, "presolve_partial_sol", test_partial_solution3)

function test_partial_solution4()
# 2x + 3y <= 5
Expand Down Expand Up @@ -158,4 +158,4 @@ function test_partial_solution4()
@test all(form2.ubs .== [0.0, 0.0])
@test all(form2.partial_solution .== [-1.0, -1.0])
end
register!(unit_tests, "presolve_partial_sol", test_partial_solution4; f= true)
register!(unit_tests, "presolve_partial_sol", test_partial_solution4)
Loading