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!
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
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
Post is closed for comments.
Comments
3 comments