Skip to content

Commit

Permalink
Merge branch 'master' of github.com:atoptima/Coluna.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
rrsadykov committed Sep 13, 2023
2 parents 57f4a77 + 0ad4ea7 commit df79897
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
12 changes: 8 additions & 4 deletions src/Algorithm/presolve/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ struct PresolveFormRepr
sense::Vector{ConstrSense} # on constraints
lbs::Vector{Float64} # on variables
ubs::Vector{Float64} # on variables
lower_multiplicity::Float64
upper_multiplicity::Float64
end

function PresolveFormRepr(coef_matrix, rhs, sense, lbs, ubs)
function PresolveFormRepr(coef_matrix, rhs, sense, lbs, ubs, lm, um)
length(lbs) == length(ubs) || throw(ArgumentError("Inconsistent sizes of bounds and coef_matrix."))
length(rhs) == length(sense) || throw(ArgumentError("Inconsistent sizes of rhs and coef_matrix."))
nb_vars = length(lbs)
nb_constrs = length(rhs)
return PresolveFormRepr(
nb_vars, nb_constrs, coef_matrix, transpose(coef_matrix), rhs, sense, lbs, ubs
nb_vars, nb_constrs, coef_matrix, transpose(coef_matrix), rhs, sense, lbs, ubs, lm, um
)
end

Expand Down Expand Up @@ -191,7 +193,9 @@ function PresolveFormRepr(
form::PresolveFormRepr,
rows_to_deactivate::Vector{Int},
vars_to_fix::Dict{Int, Float64},
tightened_bounds::Dict{Int, Tuple{Float64, Bool, Float64, Bool}}
tightened_bounds::Dict{Int, Tuple{Float64, Bool, Float64, Bool}},
lm::Float64,
um::Float64
)
nb_cols = form.nb_vars
nb_rows = form.nb_constrs
Expand Down Expand Up @@ -232,5 +236,5 @@ function PresolveFormRepr(
new_lbs = lbs[col_mask]
new_ubs = ubs[col_mask]

return PresolveFormRepr(new_coef_matrix, new_rhs, new_sense, new_lbs, new_ubs)
return PresolveFormRepr(new_coef_matrix, new_rhs, new_sense, new_lbs, new_ubs, lm, um)
end
20 changes: 16 additions & 4 deletions src/Algorithm/presolve/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ struct DwPresolveReform
dw_sps::Dict{FormId, PresolveFormulation}
end

function create_presolve_form(form::Formulation, keep_var::Function, keep_constr::Function)
function create_presolve_form(
form::Formulation,
keep_var::Function,
keep_constr::Function;
lower_multiplicity = 1,
upper_multiplicity = 1
)
constr_ids, var_ids, nz = _submatrix_nz_elems(form, keep_constr, keep_var)

var_to_col = Dict{VarId,Int64}()
Expand Down Expand Up @@ -61,6 +67,8 @@ function create_presolve_form(form::Formulation, keep_var::Function, keep_constr
sense_vals,
lbs_vals,
ubs_vals,
lower_multiplicity,
upper_multiplicity
)

deactivated_constrs = ConstrId[]
Expand All @@ -73,7 +81,7 @@ function create_presolve_form(form::Formulation, keep_var::Function, keep_constr
constr_to_row,
form,
deactivated_constrs,
fixed_vars
fixed_vars,
)
end

Expand Down Expand Up @@ -111,7 +119,7 @@ function propagate_in_presolve_form(
row_to_constr,
var_to_col,
constr_to_row,
PresolveFormRepr(form.form, rows_to_deactivate, vars_to_fix, tightened_bounds),
PresolveFormRepr(form.form, rows_to_deactivate, vars_to_fix, tightened_bounds, form.form.lower_multiplicity, form.form.upper_multiplicity),
deactivated_constrs,
fixed_vars
)
Expand Down Expand Up @@ -166,7 +174,9 @@ function create_presolve_reform(reform::Reformulation{DwMaster})

dw_sps = Dict{FormId, PresolveFormulation}()
for (spid, sp) in get_dw_pricing_sps(reform)
dw_sps[spid] = create_presolve_form(sp, sp_vars, sp_constrs)
lm = getcurrhs(master, sp.duty_data.lower_multiplicity_constr_id)
um = getcurrhs(master, sp.duty_data.upper_multiplicity_constr_id)
dw_sps[spid] = create_presolve_form(sp, sp_vars, sp_constrs, lower_multiplicity = lm, upper_multiplicity = um)
end
return DwPresolveReform(original_master, restricted_master, dw_sps)
end
Expand Down Expand Up @@ -254,4 +264,6 @@ function treat!(algo::PresolveAlgorithm, reform::Reformulation{DwMaster})
@show bounds_tightening(presolve_reform.original_master.form)

@show presolve_reform

update_reform!(reform, presolve_reform)
end
2 changes: 1 addition & 1 deletion src/Tests/Parser/Parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ module Parser
duty = ClMP.DwSpSetupVar
end
v = ClMP.setvar!(spform, varid, duty; lb = var.lb, ub = var.ub, kind = var.kind)
if var.duty <= ClMP.DwSpPricingVar
if var.duty <= ClMP.DwSpSetupVar
spform.duty_data.setup_var = ClMP.getid(v)
end
ClMP.setperencost!(spform, v, cost)
Expand Down
10 changes: 10 additions & 0 deletions test/unit/Presolve/build_formulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ function build_dw_presolve_reformulation()
(mast_var_ids["x_26"], 0.0, 1.0),
(mast_var_ids["x_27"], 0.0, 1.0)
]

@test presolve_original_master.form.lower_multiplicity == 1
@test presolve_original_master.form.upper_multiplicity == 1

for (varuid, lb, ub) in var_ids_lbs_ubs
@test presolve_original_master.form.lbs[varuid] == lb
Expand All @@ -153,6 +156,10 @@ function build_dw_presolve_reformulation()
end

presolve_restricted_master = presolve_reform.restricted_master

@test presolve_restricted_master.form.lower_multiplicity == 1
@test presolve_restricted_master.form.upper_multiplicity == 1

mast_var_ids = Dict{String, Int}(ClMP.getname(master, var) => k for (k, var) in enumerate(presolve_restricted_master.col_to_var))

var_ids_lbs_ubs = [
Expand Down Expand Up @@ -292,6 +299,9 @@ function build_dw_presolve_reformulation()

dw_sp = ClMP.get_dw_pricing_sps(reform)[5]
presolve_dw_sp = presolve_reform.dw_sps[5]

@test presolve_dw_sp.form.lower_multiplicity == 0
@test presolve_dw_sp.form.upper_multiplicity == 1

sp_var_ids = Dict{String, Int}(ClMP.getname(dw_sp, var) => k for (k,var) in enumerate(presolve_dw_sp.col_to_var))

Expand Down
6 changes: 4 additions & 2 deletions test/unit/Presolve/propagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function _mathprog_formulation!(env, form_duty, var_descriptions, constr_descrip
return form, name_to_vars, name_to_constrs
end

function _presolve_formulation(var_names, constr_names, matrix, form, name_to_vars, name_to_constrs)
function _presolve_formulation(var_names, constr_names, matrix, form, name_to_vars, name_to_constrs; lm=1, um=1)
rhs = [Coluna.MathProg.getcurrhs(form, name_to_constrs[name]) for name in constr_names]
sense = [Coluna.MathProg.getcursense(form, name_to_constrs[name]) for name in constr_names]
lbs = [Coluna.MathProg.getcurlb(form, name_to_vars[name]) for name in var_names]
Expand All @@ -77,7 +77,9 @@ function _presolve_formulation(var_names, constr_names, matrix, form, name_to_va
rhs,
sense,
lbs,
ubs
ubs,
lm,
um
)

col_to_var = [name_to_vars[name] for name in var_names]
Expand Down

0 comments on commit df79897

Please sign in to comment.