Obtain the set of fractional solutions when I stop the running of a MIP
OngoingHi,
I would like to obtain all fractional solutions that Gurobi is exploring when the MIP optimization finishes due to a WorkLimit.
I have used this callback in python:
def mycallback(m, where):
if where == GRB.Callback.MIPNODE:
status = m.cbGet(GRB.Callback.MIPNODE_STATUS)
if status == GRB.OPTIMAL:
fractional = m.cbGetNodeRel(m._xnm)
m._solutions = np.r_[m._solutions, fractional]
xnm = m.addVars(XNM, vtype = GRB.BINARY, name = "xnm")
m._solutions = np.zeros([0])
m._xnm = xnm
m.optimize(mycallback)
But with this callback I get the fractional variables of all the nodes that are being explored and I would like to get only the information of those nodes that are being explored at the moment I finish the MIP.
-
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 Marina,
I guess this will work; you will get the relaxation solution for all the nodes, including the last one explored before hitting the work limit.
If you keep and over-write \(\texttt{fractional}\) every time, you will end up with the last relaxation available before hitting the work limit.I guess you can also check the \(\texttt{WORK}\) callback attribute manually if you want. Something like:
def my_callback(model, where):
if where == GRB.Callback.MIPNODE:
status = m.cbGet(GRB.Callback.MIPNODE_STATUS)
work = m.cbGet(GRB.Callback.WORK)
if status == GRB.OPTIMAL and work > myworklimit - smallnumber:
fractional = m.cbGetNodeRel(m._x)Or, even better, pair relaxation solutions with the current work and then you can filter them as you like at the end.
Cheers,
David0 -
Hi David,
Thanks for your response, I have edited the code because I did not add the code lines where I store all the fractional solutions.
The idea to get fractional solutions is to take advantage of the results obtained by MIP during the WorkLimit specified. If I get relaxed solution I would lose some information.
Is there any way to get the state of the tree to know which binary variables have been discarded as 0/1 (the leaf nodes that have been disposed) and thus know with certainty what value they will have?
Cheers,
Marina
0
Post is closed for comments.
Comments
3 comments