Skip to content

Commit

Permalink
[presolve] presolve repr master (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
guimarqu authored Oct 10, 2023
1 parent 9f7702d commit 27a5886
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/Algorithm/presolve/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ function PresolveFormRepr(
rows_to_deactivate::Vector{Int},
tightened_bounds::Dict{Int, Tuple{Float64, Bool, Float64, Bool}},
lm,
um
um;
fix_vars = true
)
nb_cols = form.nb_vars
nb_rows = form.nb_constrs
Expand Down Expand Up @@ -242,7 +243,7 @@ function PresolveFormRepr(
@assert !isinf(ub)
new_partial_sol[i] += ub
end
if abs(ub - lb) <= Coluna.TOL
if fix_vars && abs(ub - lb) <= Coluna.TOL
fixed_col_mask[i] = true
nb_fixed_vars += 1
end
Expand Down
33 changes: 25 additions & 8 deletions src/Algorithm/presolve/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,16 @@ end
function propagate_in_presolve_form(
form::PresolveFormulation,
rows_to_deactivate::Vector{Int},
tightened_bounds::Dict{Int, Tuple{Float64, Bool, Float64, Bool}}
tightened_bounds::Dict{Int, Tuple{Float64, Bool, Float64, Bool}};
fix_vars = true
)
fixed_vars = vars_to_fix(form.form, tightened_bounds)
fixed_vars = fix_vars ? vars_to_fix(form.form, tightened_bounds) : Dict{VarId, Float64}()

col_mask = ones(Bool, form.form.nb_vars)
col_mask[collect(keys(fixed_vars))] .= false
if fix_vars
col_mask[collect(keys(fixed_vars))] .= false
end

row_mask = ones(Bool, form.form.nb_constrs)
row_mask[rows_to_deactivate] .= false

Expand All @@ -127,7 +131,18 @@ function propagate_in_presolve_form(
push!(deactivated_constrs, getid(constr))
end

form_repr = PresolveFormRepr(form.form, rows_to_deactivate, tightened_bounds, form.form.lower_multiplicity, form.form.upper_multiplicity)
form_repr = PresolveFormRepr(
form.form,
rows_to_deactivate,
tightened_bounds,
form.form.lower_multiplicity,
form.form.upper_multiplicity;
fix_vars = fix_vars
)

@assert length(col_to_var) == length(form_repr.lbs)
@assert length(col_to_var) == length(form_repr.ubs)
@assert length(row_to_constr) == length(form_repr.rhs)

return PresolveFormulation(
col_to_var,
Expand Down Expand Up @@ -349,17 +364,19 @@ function run!(algo::PresolveAlgorithm, ::Env, reform::Reformulation, input::Pres
MathProg.setcurlb!(getmaster(reform), varid, val)
else # especially for MasterPureVar
MathProg.setcurlb!(getmaster(reform), varid, val)
MathProg.setcubub!(getmaster(reform), varid, val)
MathProg.setcurub!(getmaster(reform), varid, val)
end
end

presolve_reform = create_presolve_reform(reform)
tightened_bounds_restr = bounds_tightening(presolve_reform.restricted_master.form)
new_restricted_master = propagate_in_presolve_form(presolve_reform.restricted_master, Int[], tightened_bounds_restr)

tightened_bounds = bounds_tightening(presolve_reform.restricted_master.form)

new_restricted_master = propagate_in_presolve_form(presolve_reform.restricted_master, Int[], tightened_bounds)
tightened_bounds_repr = bounds_tightening(presolve_reform.original_master.form)
new_original_master = propagate_in_presolve_form(presolve_reform.original_master, Int[], tightened_bounds_repr; fix_vars = false)

presolve_reform.restricted_master = new_restricted_master
presolve_reform.original_master = new_original_master

# # Compute global bounds of aggregated variables.
# new_original_master = compute_global_bounds(presolve_reform.original_master, new_restricted_master)
Expand Down
12 changes: 7 additions & 5 deletions src/Algorithm/presolve/propagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ function propagate_global_bounds!(presolve_repr_master::PresolveFormulation, mas
lm = presolve_sp.form.lower_multiplicity
um = presolve_sp.form.upper_multiplicity
for (i, var) in enumerate(presolve_sp.col_to_var)
repr_col = presolve_repr_master.var_to_col[getid(var)]
lb = presolve_sp.form.lbs[i]
ub = presolve_sp.form.ubs[i]
presolve_repr_master.form.lbs[repr_col] = lb * (lb < 0 ? um : lm)
presolve_repr_master.form.ubs[repr_col] = ub * (ub < 0 ? lm : um)
repr_col = get(presolve_repr_master.var_to_col, getid(var), nothing)
if !isnothing(repr_col)
lb = presolve_sp.form.lbs[i]
ub = presolve_sp.form.ubs[i]
presolve_repr_master.form.lbs[repr_col] = lb * (lb < 0 ? um : lm)
presolve_repr_master.form.ubs[repr_col] = ub * (ub < 0 ? lm : um)
end
end
return
end
Expand Down

0 comments on commit 27a5886

Please sign in to comment.