Removed variables and constraints during presolve
AnsweredHello Gurobi Team,
I have a question regarding presolve.
I started a journey to strenthen my formulation, and my first stop was presolve. I see bunch of variables and constraints are removed, and I checked specific pattern (I was able to detect some).
This is how I checked which constraints and variables are removed during presolve.
import gurobipy as gp
# Original model before presolve
m1 = gp.read("GurobiLogs/model.lp")
mp = m1.presolve()
mp.write("GurobiLogs/mypresolved.lp")
all_vars = set(v.VarName for v in m1.getVars())
all_constrs = set(c.ConstrName for c in m1.getConstrs())
# Optimize to apply presolve
m1.setParam("MIPGap", 0.000000)
m1.optimize()
# After presolve: only remaining variables and constraints are accessible
preserved_vars = set(v.VarName for v in mp.getVars())
preserved_constrs = set(c.ConstrName for c in mp.getConstrs())
removed_vars = all_vars - preserved_vars
removed_constrs = all_constrs - preserved_constrs
My understanding is if a variable is removed during presolve, it is basically do not exists during solving process. Then I realize the optimal value of a binary variable that is removed during presolve is 1.
So my question is, does presolve actually fix values rather than removing? I assume this is the case and that variable is fixed to 1 during presolve.
Thank you.
-
Hi Ozge,
This is how I checked which constraints and variables are removed during presolve.
Unfortunately this approach is not valid, variable and constraint names do not necessarily match between original and presolved model. More details here: https://support.gurobi.com/hc/en-us/articles/360024738352-How-does-presolve-work
does presolve actually fix values rather than removing? I assume this is the case and that variable is fixed to 1 during presolve.
If presolve deduces a variable must obtain a particular value then it will replace this variable by the value.
- Riley
0 -
Thank you for your answer, Riley.
I've read that article, and decided to inspect my model as it says:
Usually, you would write out this model to an *.lp file and inspect it manually.
It is a bit surprising for me you say the approach is not valid. As I was able to catch a pattern on removed variables, and preprocessed myself and it worked well.
Anyway, I appreciate your answer.
Özge
0 -
Hi Ozge,
It's good to hear it worked, the preprocessed model can certainly give you inspiration for investigating things you may do yourself (and setting Aggregate=0 and DualReductions=0 may help). So you could look at the presolved model, see a constraint is missing, and ask yourself “is there some reason this constraint is redundant?”, but you couldn't claim the constraint is redundant based off the presolved model. Keep in mind a broken clock is correct twice a day.
- Riley
0
Please sign in to leave a comment.
Comments
3 comments