Re-optimization
AnsweredI am solving a MILP in python by first initialising my model, then I allow the solver to run for 15s, once the time limit is reached I take the binary variable x:
x = m.addVars(arcs, vehicles, vtype=GRB.BINARY, name = 'x') # x binary variable equal to 1 if arc (i, j) is traversed by ship s"
I modify some values of x by randomly selecting some indices i and set their corresponding x[i, j] and x[j, i] to 0 by using x[i, j, s].VarHintVal=0 and similarly for x[j, i, s]. Also, for any variables equal to one i want to fix them to 1 so i do this with VarHintVal and i set a large integer for VarHintPri. Then i reoptimize by calling model.optimise().
My issue is that when I pass this modified solution back to the solver i find that i have this message in the solver output
Using variable hints.
MIP start from previous solve produced solution with objective 617.658 (0.00s)
Loaded MIP start from previous solve with objective 617.658
Am I using the hints correctly? Similarly when I use .Start the model can not find an incumbent solution and reverts to the last solution before I chose to fix some variables.
I have read the similar posts to .Start however I couldn't fix the issue.
This is the code for using hints:
for i in IR:
for j in range(distance_matrix.shape[0]):
for s in vehicles:
x[i, j, s].VarHintVal = 0
x[j, i, s].VarHintVal = 0
x[i, j, s].VarHintPri = 10000
for i in ports_and_depot:
for j in range(distance_matrix.shape[0]):
for s in vehicles:
if x[i, j, s].X > 0.99:
x[i, j, s].VarHintVal = 1
if x[j, i, s].X > 0.99:
x[j, i, s].VarHintVal = 1
x[i, j, s].VarHintPri = 10000
m.update()
m.Params.TimeLimit = 5
m.optimize()
-
I now realise that when we set these variable values and call optimize again, the hints are being considered and the solver starts from the last objective value anyway. So can we do something along the lines of:
m.optimize()
x[i, j, s].Start = 0
x[j, i, s].Start = 0
m.write('m.sol')
m.update()
m.read('m.sol')
m.optimize()to force these values?
0 -
Hi Darragh,
I think you might be confusing variable hints with MIP starts (which is set using the Start attribute). A hint is just used to guide the solver in its search - in things like heuristics - and there is no guarantee that the solver will even evaluate a solution that could be constructed by setting variables to their hint values.
From what you are describing I suspect you want to use MIP starts. You could alternatively also use a MIPSOL callback, where you use cbGetSolution to retrieve the solution, modify it, then give it back to the solver with cbSetSolution.
Note that you can always use Model.reset() to clear previous solution information between solves. If you use MIP starts, do not call reset(), and the model still resumes with the previous solution instead of the solution specified by the MIP start then either the MIP start was rejected for being infeasible, or perhaps ignored because it was only a partial solution and extending it to a full solution was proving costly, or lastly it could be that the solution specified by the MIP start is worse than the one previously found.
- Riley
0 -
You can also have a look at our Knowledge Base article What are the differences between MIP Starts and Variable Hints? G.
0
Please sign in to leave a comment.
Comments
3 comments