How to use multiple MIP starts with only some variables?
AnsweredHello,
I'm trying to use multiple starts as outlined here. (https://support.gurobi.com/hc/en-us/articles/360043834831-How-do-I-use-MIP-starts-)
With just one multiple start, I can do something like
x = model.addVars(N, vtype = GRB.BINARY, name = "x")
for i in range(N):
x[i].Start = <value>
However, when I try to do this with two variables like:
model.NumStart = 2
# iterate over all MIP starts
for s in range(model.NumStart):
# set StartNumber
model.params.StartNumber = s
for i in range(N):
x[i].Start = <value>
I get the following error:
No start values specified in MIP start
No start values specified in MIP start
I was wondering if I have to use the syntax in the support article, namely:
model.NumStart = 2
# iterate over all MIP starts
for s in range(model.NumStart):
# set StartNumber
model.params.StartNumber = s
for v in model.getVars():
v.Start = <value>
However, I only want to specify some of my variables. I have tried something like the following, but I still get the same error.
model.NumStart = 2
# iterate over all MIP starts
for s in range(model.NumStart):
# set StartNumber
model.params.StartNumber = s
for v in model.getVars():
for i in range(N):
if v.VarName == "x["+i+"]":
v.Start = <value>
Any help would be much appreciated. Thanks!
-
Hi,
At a first glance, your code looks correct. Could you try calling the update method after you set the NumStart parameter? Or run the \(\texttt{for}\)-loop over \(\texttt{range(2)}\) instead of \(\texttt{range(model.NumStart)}\)?
# first try
model.NumStart = 2
model.update()
# if this does not help try
for s in range(2):
#...If the above does not help, could you please share the corresponding model for which you are trying to set multiple MIPStarts? If possible, please try to generate a minimal reproducible example.
Best regards,
Jaromił0 -
Hello,
Calling model.update() after setting NumStart helped. I also had to call model.update() after setting StartNumber in the loop.
Thank you for your help!
0
Please sign in to leave a comment.
Comments
2 comments