Fixing all variables results in a better objective than fixing only some variables
Awaiting user inputI'm implementing an algorithm where part of the solution remains fixed (fixing using the .ub and .lb commands) and the rest is allowed to change subject to those fixed. I also have a criteria that the objective is not allowed to worsen.
I have reached a solution where if I fix every variable (in the way mentioned above) I get an objective value of 893 and Gurobi doesn't see this as infeasible. However, if I fix only a subset of these variables, the best solution it can find is 892.
The fixing of the variables is all that is happening and there are no changes in model constraints.
Fixed model mps: maryfal_allfixed.mps
Partially fixed model mps: maryfal_somefixed.mps
-
Hi Matthew,
It doesn't look like all your variables are fixed as you suggest:
>> import gurobipy as gp
>> m = gp.read("maryfal_allfixed.mps")
>> fixed = [v.lb == v.ub for v in m.getVars()]
>> print(f"fixed {sum(fixed)}/{len(fixed)}")
fixed 597383/634494It also appears that there are variables fixed in maryfal_somefixed.mps that are not fixed in maryfal_allfixed.mps
>> m2 = gp.read("maryfal_somefixed.mps")
>> also_fixed = [
m.getVarByName(v.VarName).lb == m.getVarByName(v.VarName).ub
for v in m2.getVars()
if v.lb == v.ub
]
>>> print(f"also fixed {sum(also_fixed)}/{len(also_fixed)}")
also fixed 495655/512447If the feasible region of one model is a superset of the other then it should accept a solution that is produced by the more constrained model.
If I run the following
>> m.optimize()
>> m2.setAttr("Start", m2.getVars(), m.X)
>> m2.optimize()Then the log complains that "User MIP start violates constraint c117566 by 1.000000000"
The evidence is pointing to the situation being different to what you're expecting.
- Riley
0 -
Hi Riley Clement,
Thank you for the response.
For your first comment, I am aware that not every variable is fixed (apologies for not being fully clear on this) but the remaining variables should be determined by what is fixed.
For your second comment, this surprised me as there should be overlap. For example, every variable that is fixed in m2 should be fixed in m1. Is there some naming issue when I output to .mps format using the "write" function of a model?
In any case, I think there is an issue with my constraints and model building that I have spotted. I'm happy for this issue to be closed but thank you for the help. (The code snippets helped me spot my error)
0 -
Hi Matthew,
If you're using a Gurobi API and the variables are being created in the same order then I'd expect the names to be the same.
When I look at the result of m.getObjective() and m2.getObjective() the resulting linear expressions look the same which is good evidence to suggest the names of the variables are the same.
- Riley
0
Please sign in to leave a comment.
Comments
3 comments