How to extract fractional solution from GUROBI ILP?
AnsweredHi,
I would like to get the solution and fractional values at each row in the following column. I am working with the Python API. Could you please let me know how this could be done? Additionally, is it possible to terminate the optimization after the first row is produced?
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
0 0 1351975.00 0 70 - 1351975.00 - - 1s
0 0 1354280.00 0 99 - 1354280.00 - - 2s
0 0 1356820.00 0 102 - 1356820.00 - - 3s
0 0 1357000.00 0 84 - 1357000.00 - - 4s
0 0 1357195.45 0 138 - 1357195.45 - - 4s
0 0 1357204.55 0 139 - 1357204.55 - - 4s
0 0 1357283.57 0 132 - 1357283.57 - - 5s
0 0 1357950.00 0 132 - 1357950.00 - - 6s
0 0 1357950.00 0 142 - 1357950.00 - - 6s
0 0 1357976.25 0 146 - 1357976.25 - - 6s
0 0 1357976.25 0 151 - 1357976.25 - - 7s
0 0 1358337.50 0 130 - 1358337.50 - - 8s
0 0 1358337.50 0 135 - 1358337.50 - - 8s
0 0 1358725.00 0 145 - 1358725.00 - - 8s
0 0 1358752.63 0 148 - 1358752.63 - - 9s
0 0 1358772.83 0 180 - 1358772.83 - - 9s
0 0 1358774.12 0 176 - 1358774.12 - - 9s
0 0 1358774.12 0 176 - 1358774.12 - - 9s
0 0 1358817.49 0 170 - 1358817.49 - - 10s
0 0 1358817.49 0 175 - 1358817.49 - - 10s
0 0 1358817.49 0 175 - 1358817.49 - - 10s
0 0 1358880.95 0 157 - 1358880.95 - - 12s
0 0 1358892.71 0 168 - 1358892.71 - - 12s
0 0 1358893.83 0 173 - 1358893.83 - - 12s
0 0 1358922.22 0 111 - 1358922.22 - - 12s
0 0 1358925.45 0 157 - 1358925.45 - - 12s
0 0 1358927.27 0 158 - 1358927.27 - - 13s
0 0 1358929.17 0 158 - 1358929.17 - - 13s
0 0 1359020.00 0 127 - 1359020.00 - - 13s
0 0 1359088.37 0 162 - 1359088.37 - - 14s
0 0 1359141.67 0 151 - 1359141.67 - - 14s
0 0 1359166.67 0 154 - 1359166.67 - - 14s
0 0 1359315.45 0 156 - 1359315.45 - - 14s
0 0 1359328.57 0 159 - 1359328.57 - - 14s
0 0 1359465.32 0 165 - 1359465.32 - - 15s
0 0 1359609.69 0 187 - 1359609.69 - - 15s
0 0 1359634.44 0 195 - 1359634.44 - - 16s
0 0 1359642.19 0 183 - 1359642.19 - - 16s
0 0 1359642.98 0 189 - 1359642.98 - - 16s
0 0 1359643.80 0 193 - 1359643.80 - - 16s
0 0 1359644.07 0 195 - 1359644.07 - - 16s
0 0 1359687.09 0 197 - 1359687.09 - - 17s
0 0 1359687.09 0 202 - 1359687.09 - - 17s
0 0 1359702.04 0 194 - 1359702.04 - - 17s
0 0 1359733.69 0 188 - 1359733.69 - - 18s
0 0 1359733.81 0 193 - 1359733.81 - - 18s
0 0 1359733.84 0 202 - 1359733.84 - - 19s
0 0 1359737.45 0 194 - 1359737.45 - - 19s
0 0 1359737.45 0 186 - 1359737.45 - - 21s
0 2 1359737.45 0 185 - 1359737.45 - - 22s
* 18 20 4 1364410.0000 1361754.00 0.19% 975 24s
Cutting planes:
Gomory: 2
MIR: 7
StrongCG: 3
Zero half: 14
Mod-K: 1
-
Hi Tarun,
Can you explain in detail what you mean by "solution and fractional values"?
- Riley
0 -
Hi Tarun,
The easiest way to get the relaxed solution is to use model.relax():
with model.relax() as r:
r.optimize()
r.printAttr("X")Cheers,
David0 -
Hey Riley,
By "fractional values and solution", I mean the .X that produced the Obj = 1351975.00 in the first row and the 70 "IntInf" values. I want to see which values are violating integer feasibility. Is it possible to do this?
0 0 1351975.00 0 70 - 1351975.00 - - 1s
I am trying to speed up the search by stopping it early even if some values are fractional. However, I don't want to relax all values.
0 -
Hi Tarun,
This code could serve as the basis for what you want to do
def cb(model, where):
if where == gp.GRB.Callback.MIPNODE:
# Found a new MIP incumbent
if model.cbGet(gp.GRB.Callback.MIPNODE_STATUS) == gp.GRB.OPTIMAL:
m._lp_x = model.cbGetNodeRel(model._vars)
if where == gp.GRB.Callback.MESSAGE:
if m._lp_x:
print(m._lp_x)
m = gp.Model()
# build model
m._vars = m.getVars()
m._lp_x = 0
m.optimize(cb)- Riley
0 -
So it is not possible to get the information at each row? Is it possible to see which constraints are producing the "IntInf"?
Additionally, are there any other parameters and callbacks I should consider to speedup the search based on the above results?
This is the current combination I am using:
Set parameter Heuristics to value 0
Set parameter Presolve to value 0
Set parameter Method to value 1
Set parameter SolutionLimit to value 10 -
Hey David,
Is it possible to get
r.printAttr("X")
in list or array format? I have two matrix variables "x" and "y". I want to get the nonzero values for "x" and "y" in two separate lists.
0 -
Hi Tarun,
Sorry, I misunderstood what you were wanting to do. Can you take a look at the updated code in my answer above?
- Riley
0
Please sign in to leave a comment.
Comments
7 comments