Infeasible solution in a callback
AnsweredIs there a reason why a solution in a callback (provided by cbGetNodeRel) should not satisfy variable bounds and constrains given before optimize is called?
To be more specific, I tried to solve capacitated vehicle routing problem using algorithm described in Lysgaard, Jens, Adam N. Letchford, and Richard W. Eglese. "A new branch-and-cut algorithm for the capacitated vehicle routing problem." Mathematical Programming 100.2 (2004): 423-445. I implemented only constrains (1)-(4) and the first heuristic stated in section 2.1.
Although all variables are binary, a solution obtained in my callback contains values -0.6405124664306641, -1.0, -1.078719139099121 etc. Furthermore, the sum of variables corresponding to edges incident to any vertex should be 2, but these sums the solution have values 5.524e-321, -2.156909942626953, -13.08715560611898, 922232768286381.9. Even a bug in lazy constraint generation should not cause such values.
Below, you can find the source code, the testing data, and the program output (I do not see how to add an attachment). Thanks for help.
import xml.etree.ElementTree as ET
import math
import numpy
import gurobipy as gp
from gurobipy import GRB
class Instance:
def __init__(self, requests, distances, capacity, coordinates):
self.nodes = len(requests) # The number of nodes (including the depot)
self.depot = 0 # Index of a node representing depot
self.capacity = capacity # The capacity of identical vehicles
self.requests = requests # Weight of requests on every node (the depot has no request)
self.distances = distances # Symetrical matrix of distances between every pair of nodes
self.coordinates = coordinates # Positions of all nodes
# https://www.coin-or.org/SYMPHONY/branchandcut/VRP/data/index.htm.old
# http://www.vrp-rep.org/variants/item/cvrp.html
def load(filename):
root = ET.parse(filename).getroot()
requests = {r.attrib['node']: round(float(r.find('quantity').text)) for r in root.find('requests')}
nodes = sorted([(int(n.attrib['id']), float(n.find('cx').text), float(n.find('cy').text), n.attrib['type'], requests.get(n.attrib['id'],0)) for n in root.find('network').find('nodes')])
requests = numpy.array([ n[4] for n in nodes ], numpy.int32)
distances = numpy.array([ [round(math.sqrt((a[1]-b[1])**2+(a[2]-b[2])**2)) for a in nodes] for b in nodes ], numpy.int32)
profile = root.find('fleet').find('vehicle_profile')
capacity = round(float(profile.find('capacity').text))
coordinates = [ (n[1],n[2]) for n in nodes ]
# Simplification of loading: Depot should be the first node
assert all(nodes[i][3] == ('0' if i == 0 else '1') for i in range(len(nodes)))
assert profile.find('departure_node').text == '1' and profile.find('arrival_node').text == '1'
assert requests[0] == 0
return Instance(requests, distances, capacity, coordinates)
def mycallback(model, where):
nodes = model._instance.nodes
if where == GRB.Callback.MIPSOL:
sol = [ [ model.cbGetSolution(model._vars[u][v]) for v in range(nodes) ] for u in range(nodes) ]
elif where == GRB.Callback.MIPNODE:
sol = [ [ model.cbGetNodeRel(model._vars[u][v]) for v in range(nodes) ] for u in range(nodes) ]
else:
return
for u in range(nodes):
for v in range(nodes):
if sol[u][v] < -model.Params.IntFeasTol or sol[u][v] > 1+model.Params.IntFeasTol:
print("BUG where", where, "nodes", u, v, "value", sol[u][v])
model.terminate()
for u in range(1,nodes):
if abs(sum(sol[u])-2) > model.Params.IntFeasTol:
print("BUG where", where, "node", u, "sum", sum(sol[u]), "neigh", sol[u])
model.terminate()
visited = [ False ] * nodes
visited[0] = True
for start in range(1, nodes): # Run DFS from every node
if not visited[start]: # which has not been visited yet
stack = [ start ]
component = [ start ]
inside = [ False ] * nodes
visited[start] = True
delta = 0
while stack:
u = stack.pop()
inside[u] = True
for v in range(nodes): # Process all edges uv
if sol[u][v] > model.Params.IntFeasTol:
if inside[v]:
delta -= sol[u][v]
else:
delta += sol[u][v]
if not visited[v]:
stack.append(v)
component.append(v)
visited[v] = True
requests = sum(model._instance.requests[u] for u in component)
bound = 2 * math.ceil(requests / model._instance.capacity)
if delta + model.Params.IntFeasTol < bound:
print("Component", component, "requests", requests, "delta", delta, "bound", bound)
test_delta = sum(sol[u][v] for u in range(nodes) if not inside[u] for v in component)
assert abs(test_delta - delta) < model.Params.IntFeasTol, (test_delta, delta)
assert all((u in component) == inside[u] for u in range(nodes))
model.cbLazy(sum(model._vars[u][v] for u in range(nodes) if not inside[u] for v in component) >= bound)
def solve_capacitated_vehicle_routing_problem(instance):
env = gp.Env("")
model = gp.Model(env=env)
model.setParam('LazyConstraints', 1)
model.setParam('Threads', 1)
model.setParam('Method', 4)
model._instance = instance
model._vars = vars = [[ model.addVar(vtype=GRB.BINARY, obj=instance.distances[u][v]) for v in range(instance.nodes) ] for u in range(instance.nodes) ]
model.addConstrs(vars[u][v] - vars[v][u] == 0.0 for u in range(instance.nodes) for v in range(instance.nodes))
model.addConstrs(vars[u][u] == 0.0 for u in range(instance.nodes))
model.addConstrs((sum(vars[u][v] for v in range(instance.nodes)) == 2.0 for u in range(1, instance.nodes)))
model.optimize(mycallback)
if __name__ == "__main__":
solve_capacitated_vehicle_routing_problem(load("A-n32-k05.xml"))
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<instance>
<info>
<dataset>Augerat 1995 — Set A</dataset>
<name>A-n32-k05</name>
</info>
<network>
<nodes>
<node id="1" type="0">
<cx>82.0</cx>
<cy>76.0</cy>
</node>
<node id="2" type="1">
<cx>96.0</cx>
<cy>44.0</cy>
</node>
<node id="3" type="1">
<cx>50.0</cx>
<cy>5.0</cy>
</node>
<node id="4" type="1">
<cx>49.0</cx>
<cy>8.0</cy>
</node>
<node id="5" type="1">
<cx>13.0</cx>
<cy>7.0</cy>
</node>
<node id="6" type="1">
<cx>29.0</cx>
<cy>89.0</cy>
</node>
<node id="7" type="1">
<cx>58.0</cx>
<cy>30.0</cy>
</node>
<node id="8" type="1">
<cx>84.0</cx>
<cy>39.0</cy>
</node>
<node id="9" type="1">
<cx>14.0</cx>
<cy>24.0</cy>
</node>
<node id="10" type="1">
<cx>2.0</cx>
<cy>39.0</cy>
</node>
<node id="11" type="1">
<cx>3.0</cx>
<cy>82.0</cy>
</node>
<node id="12" type="1">
<cx>5.0</cx>
<cy>10.0</cy>
</node>
<node id="13" type="1">
<cx>98.0</cx>
<cy>52.0</cy>
</node>
<node id="14" type="1">
<cx>84.0</cx>
<cy>25.0</cy>
</node>
<node id="15" type="1">
<cx>61.0</cx>
<cy>59.0</cy>
</node>
<node id="16" type="1">
<cx>1.0</cx>
<cy>65.0</cy>
</node>
<node id="17" type="1">
<cx>88.0</cx>
<cy>51.0</cy>
</node>
<node id="18" type="1">
<cx>91.0</cx>
<cy>2.0</cy>
</node>
<node id="19" type="1">
<cx>19.0</cx>
<cy>32.0</cy>
</node>
<node id="20" type="1">
<cx>93.0</cx>
<cy>3.0</cy>
</node>
<node id="21" type="1">
<cx>50.0</cx>
<cy>93.0</cy>
</node>
<node id="22" type="1">
<cx>98.0</cx>
<cy>14.0</cy>
</node>
<node id="23" type="1">
<cx>5.0</cx>
<cy>42.0</cy>
</node>
<node id="24" type="1">
<cx>42.0</cx>
<cy>9.0</cy>
</node>
<node id="25" type="1">
<cx>61.0</cx>
<cy>62.0</cy>
</node>
<node id="26" type="1">
<cx>9.0</cx>
<cy>97.0</cy>
</node>
<node id="27" type="1">
<cx>80.0</cx>
<cy>55.0</cy>
</node>
<node id="28" type="1">
<cx>57.0</cx>
<cy>69.0</cy>
</node>
<node id="29" type="1">
<cx>23.0</cx>
<cy>15.0</cy>
</node>
<node id="30" type="1">
<cx>20.0</cx>
<cy>70.0</cy>
</node>
<node id="31" type="1">
<cx>85.0</cx>
<cy>60.0</cy>
</node>
<node id="32" type="1">
<cx>98.0</cx>
<cy>5.0</cy>
</node>
</nodes>
<euclidean/>
<decimals>0</decimals>
</network>
<fleet>
<vehicle_profile type="0">
<departure_node>1</departure_node>
<arrival_node>1</arrival_node>
<capacity>100.0</capacity>
</vehicle_profile>
</fleet>
<requests>
<request id="1" node="2">
<quantity>19.0</quantity>
</request>
<request id="2" node="3">
<quantity>21.0</quantity>
</request>
<request id="3" node="4">
<quantity>6.0</quantity>
</request>
<request id="4" node="5">
<quantity>19.0</quantity>
</request>
<request id="5" node="6">
<quantity>7.0</quantity>
</request>
<request id="6" node="7">
<quantity>12.0</quantity>
</request>
<request id="7" node="8">
<quantity>16.0</quantity>
</request>
<request id="8" node="9">
<quantity>6.0</quantity>
</request>
<request id="9" node="10">
<quantity>16.0</quantity>
</request>
<request id="10" node="11">
<quantity>8.0</quantity>
</request>
<request id="11" node="12">
<quantity>14.0</quantity>
</request>
<request id="12" node="13">
<quantity>21.0</quantity>
</request>
<request id="13" node="14">
<quantity>16.0</quantity>
</request>
<request id="14" node="15">
<quantity>3.0</quantity>
</request>
<request id="15" node="16">
<quantity>22.0</quantity>
</request>
<request id="16" node="17">
<quantity>18.0</quantity>
</request>
<request id="17" node="18">
<quantity>19.0</quantity>
</request>
<request id="18" node="19">
<quantity>1.0</quantity>
</request>
<request id="19" node="20">
<quantity>24.0</quantity>
</request>
<request id="20" node="21">
<quantity>8.0</quantity>
</request>
<request id="21" node="22">
<quantity>12.0</quantity>
</request>
<request id="22" node="23">
<quantity>4.0</quantity>
</request>
<request id="23" node="24">
<quantity>8.0</quantity>
</request>
<request id="24" node="25">
<quantity>24.0</quantity>
</request>
<request id="25" node="26">
<quantity>24.0</quantity>
</request>
<request id="26" node="27">
<quantity>2.0</quantity>
</request>
<request id="27" node="28">
<quantity>20.0</quantity>
</request>
<request id="28" node="29">
<quantity>15.0</quantity>
</request>
<request id="29" node="30">
<quantity>2.0</quantity>
</request>
<request id="30" node="31">
<quantity>14.0</quantity>
</request>
<request id="31" node="32">
<quantity>9.0</quantity>
</request>
</requests>
</instance>
Changed value of parameter LazyConstraints to 1
Prev: 0 Min: 0 Max: 1 Default: 0
Changed value of parameter Threads to 1
Prev: 0 Min: 0 Max: 1024 Default: 0
Changed value of parameter Method to 4
Prev: -1 Min: -1 Max: 5 Default: -1
Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
Thread count: 2 physical cores, 4 logical processors, using up to 1 threads
Optimize a model with 1087 rows, 1024 columns and 3008 nonzeros
Model fingerprint: 0x0020cb2f
Variable types: 0 continuous, 1024 integer (1024 binary)
Coefficient statistics:
Matrix range [1e+00, 1e+00]
Objective range [2e+00, 1e+02]
Bounds range [1e+00, 1e+00]
RHS range [2e+00, 2e+00]
Presolve removed 1056 rows and 528 columns
Presolve time: 0.00s
Presolved: 31 rows, 496 columns, 961 nonzeros
Variable types: 0 continuous, 496 integer (496 binary)
Found heuristic solution: objective 3850.0000000
Root relaxation: objective 8.160000e+02, 43 iterations, 0.00 seconds
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
0 0 816.00000 0 6 3850.00000 816.00000 78.8% - 0s
Component [1, 7, 12, 21, 31, 19, 17, 2, 3, 23, 4, 11, 28, 18, 8, 9, 22, 25, 10, 15, 29, 5, 20, 27, 24, 14, 6, 13] requests 376 delta 0.0 bound 8
Component [16, 26, 30] requests 34 delta 0.0 bound 2
H 0 0 3746.0000000 816.00000 78.2% - 0s
H 0 0 2950.0000000 816.00000 72.3% - 0s
Component [1, 7, 12, 16, 30, 26, 13, 6, 14, 24, 27, 20, 5, 25, 29, 15, 10] requests 236 delta 0.0 bound 6
Component [2, 3, 23] requests 35 delta 0.0 bound 2
Component [4, 11, 28] requests 48 delta 0.0 bound 2
Component [8, 9, 18, 22] requests 27 delta 0.0 bound 2
Component [17, 19, 21, 31] requests 64 delta 0.0 bound 2
0 0 945.00000 0 6 2950.00000 945.00000 68.0% - 0s
Component [1, 26, 30, 12, 16, 7] requests 90 delta 0.0 bound 2
Component [2, 3, 23, 6] requests 47 delta 0.0 bound 2
Component [4, 9, 18, 22] requests 40 delta 0.0 bound 2
Component [5, 25, 29, 15, 10] requests 63 delta 0.0 bound 2
Component [8, 11, 28] requests 35 delta 0.0 bound 2
... skipped ...
Component [9, 22, 26, 15, 10, 25, 16, 12] requests 115 delta 2.0 bound 4
Component [5, 27, 30, 22, 9, 15, 10, 25, 16, 12] requests 154 delta 2.0 bound 4
Component [8, 9, 28, 26, 22, 15, 10, 25, 16, 12] requests 136 delta 1.9999999999999996 bound 4
Component [8, 9, 28, 18, 22, 15, 10, 25, 16, 12] requests 135 delta 2.0 bound 4
Component [2, 3, 17, 23, 11, 4, 9, 22, 15, 10, 25, 16, 12] requests 200 delta 2.0 bound 4
Component [4, 9, 11, 23, 18, 22, 15, 10, 25, 16, 12] requests 155 delta 2.0 bound 4
Component [2, 3, 17, 28, 8, 9, 22, 15, 10, 25, 16, 12] requests 180 delta 2.0 bound 4
Component [4, 11, 30, 5, 27, 23, 9, 22, 15, 10, 25, 16, 12] requests 195 delta 2.0 bound 4
BUG where 5 nodes 0 5 value -0.00823331152423479
BUG where 5 nodes 0 6 value -0.008233311524234802
BUG where 5 nodes 0 7 value -0.008233311524234796
BUG where 5 nodes 0 9 value -0.05763318066964363
BUG where 5 nodes 0 10 value -0.05763318066964364
BUG where 5 nodes 0 15 value -0.00823331152423479
BUG where 5 nodes 0 17 value -0.00823331152423479
BUG where 5 nodes 0 23 value -0.07409980371811321
BUG where 5 nodes 0 24 value -0.01646662304846961
... skipped ...
BUG where 5 nodes 31 14 value 3.4351409855651e+228
BUG where 5 nodes 31 15 value 9.020926277062751e+227
BUG where 5 nodes 31 21 value 5.224112396445427e+257
BUG where 5 nodes 31 24 value 6.026696098515304e+175
BUG where 5 nodes 31 25 value 6.226552322778575e+228
BUG where 5 nodes 31 31 value 9.620089727120577e+140
BUG where 5 node 1 sum -0.6668982334630191 neigh [-0.07409980371811321, -0.06586649219387844, -0.06586649219387844, -0.07409980371811321, -0.01646662304846961, -0.01646662304846961, -0.01646662304846961, 0.05763318066964364, -0.01646662304846961, -0.008233311524234807, -0.008233311524234803, -0.07409980371811321, -0.008233311524234803, -0.06586649219387843, -0.008233311524234805, 0.008233311524234808, 0.008233311524234807, -0.008233311524234803, -0.008233311524234808, -0.01646662304846961, -0.008233311524234807, -0.06586649219387843, -0.05763318066964363, -0.05763318066964363, 0.008233311524234805, 0.008233311524234803, 0.0082333115242348, -0.06586649219387843, -0.008233311524234805, -0.008233311524234803, -0.008233311524234805, 0.06586649219387844]
BUG where 5 node 2 sum -0.6092650527933756 neigh [-0.008233311524234803, 0.008233311524234803, -0.06586649219387843, 0.0082333115242348, -0.07409980371811323, 0.00823331152423481, -0.008233311524234807, 0.008233311524234803, -0.016466623048469613, -0.07409980371811323, -0.04939986914540882, -0.04939986914540883, -0.008233311524234805, -0.07409980371811323, -0.01646662304846961, 0.008233311524234805, 0.05763318066964363, -0.008233311524234807, 0.008233311524234805, -0.07409980371811323, -0.057633180669643604, 0.016466623048469613, 0.008233311524234808, 0.008233311524234808, -0.057633180669643604, -0.04939986914540882, -0.04939986914540882, 0.008233311524234808, 0.016466623048469613, 0.016466623048469617, -0.057633180669643604, 0.00823331152423481]
BUG where 5 node 3 sum -0.32109914944515733 neigh [0.07409980371811326, 0.008233311524234808, 0.02469993457270442, -0.057633180669643604, 0.016466623048469613, 0.016466623048469617, -0.05763318066964362, 0.008233311524234805, -0.008233311524234805, -0.05763318066964362, -0.04939986914540883, -0.04939986914540884, 0.008233311524234807, 0.01646662304846961, 0.016466623048469613, -0.05763318066964362, 0.07409980371811324, 0.008233311524234805, 0.01646662304846961, -0.05763318066964362, 0.008233311524234807, 0.016466623048469613, -0.06586649219387843, -0.008233311524234807, -0.01646662304846961, 0.0082333115242348, -0.008233311524234807, -0.06586649219387843, -0.04939986914540882, -0.04939986914540883, 0.008233311524234802, 0.008233311524234807]
BUG where 5 node 4 sum -0.6751315449872537 neigh [-0.06586649219387843, -0.008233311524234805, -0.008233311524234807, 0.06586649219387844, 0.008233311524234803, -0.008233311524234807, -0.06586649219387843, 0.008233311524234807, -0.07409980371811323, -0.008233311524234805, 0.008233311524234803, -0.016466623048469613, -0.07409980371811323, -0.04939986914540882, -0.04939986914540883, -0.07409980371811323, -0.01646662304846961, 0.05763318066964363, -0.008233311524234807, 0.008233311524234805, -0.07409980371811323, -0.008233311524234805, -0.08233311524234803, 0.04939986914540882, -0.008233311524234807, 0.04939986914540882, -0.02469993457270442, -0.08233311524234803, -0.008233311524234803, -0.00823331152423479, -0.08233311524234803, -0.02469993457270442]
BUG where 5 node 5 sum -0.625731675841845 neigh [0.04939986914540882, 0.04939986914540884, 0.04939986914540882, -0.08233311524234803, -0.008233311524234803, -0.00823331152423479, -0.08233311524234803, -0.008233311524234808, 0.049399869145408816, -0.02469993457270442, -0.08233311524234803, -0.008233311524234808, -0.008233311524234802, -0.08233311524234803, -0.02469993457270442, 0.04939986914540882, 0.04939986914540882, 0.04939986914540882, -0.08233311524234803, -0.008233311524234808, -0.008233311524234802, -0.08233311524234803, -0.02469993457270442, -0.08233311524234803, -0.05763318066964363, -0.05763318066964363, -0.01646662304846961, -0.008233311524234807, -0.008233311524234796, -0.08233311524234803, -0.02469993457270441, -0.008233311524234807]
BUG where 5 node 6 sum -0.6174983643176102 neigh [0.04939986914540883, -0.008233311524234807, -0.016466623048469613, -0.008233311524234805, -0.08233311524234803, -0.008233311524234805, -0.008233311524234796, -0.07409980371811321, -0.016466623048469613, -0.07409980371811321, 0.008233311524234795, -0.07409980371811321, -0.016466623048469613, 0.04939986914540882, 0.008233311524234803, 0.05763318066964364, 0.04939986914540882, 0.0082333115242348, 0.008233311524234796, 0.008233311524234803, -0.07409980371811321, -0.07409980371811323, -0.07409980371811323, -0.07409980371811323, -0.07409980371811324, -0.008233311524234807, -0.07409980371811323, -0.016466623048469613, -0.02469993457270442, -0.016466623048469613, 0.05763318066964363, -0.02469993457270442]
BUG where 5 node 7 sum -1.9183615851467088 neigh [-0.008233311524234807, -0.016466623048469613, -0.07409980371811323, -0.008233311524234807, -0.13173298438775685, -0.13173298438775685, -0.06586649219387843, -0.05763318066964362, 0.07409980371811323, -0.07409980371811323, -0.08233311524234803, -0.07409980371811323, -0.08233311524234803, -0.06586649219387843, -0.05763318066964362, -0.07409980371811323, -0.06586649219387843, 0.07409980371811323, -0.13173298438775685, -0.04939986914540882, -0.05763318066964363, -0.04939986914540883, -0.05763318066964363, -0.13173298438775685, -0.07409980371811323, -0.04939986914540882, -0.04939986914540883, -0.04939986914540883, -0.04939986914540882, -0.13173298438775685, -0.05763318066964363, -0.05763318066964363]
BUG where 5 node 8 sum -1.1361969903444027 neigh [-0.13173298438775685, -0.05763318066964363, -0.04939986914540883, -0.05763318066964364, -0.13173298438775685, -0.07409980371811323, -0.04939986914540883, -0.04939986914540883, -0.04939986914540883, -0.04939986914540883, -0.13173298438775685, -0.05763318066964363, -0.05763318066964364, -0.06586649219387843, 0.008233311524234803, 0.0082333115242348, -0.06586649219387843, -0.008233311524234805, -0.008233311524234803, -0.008233311524234805, 0.06586649219387844, -0.008233311524234803, 0.008233311524234803, -0.06586649219387843, 0.0082333115242348, -0.05763318066964362, 0.016466623048469613, -0.05763318066964362, 0.07409980371811324, 0.008233311524234802, 0.016466623048469606, -0.05763318066964362]
BUG where 5 node 9 sum -0.23876603420280934 neigh [0.008233311524234803, 0.016466623048469613, 0.07409980371811323, 0.07409980371811323, -0.00823331152423479, 0.07409980371811324, -0.00823331152423479, 0.008233311524234807, 0.016466623048469606, 0.07409980371811323, 0.0082333115242348, 0.14819960743622645, -0.07409980371811323, -0.08233311524234803, -0.07409980371811323, -0.08233311524234803, -0.06586649219387843, -0.05763318066964362, -0.07409980371811323, -0.06586649219387843, 0.07409980371811323, -0.07409980371811323, -0.02469993457270442, -0.01646662304846961, 0.05763318066964363, -0.02469993457270442, -0.008233311524234807, -0.01646662304846961, -0.07409980371811323, -0.008233311524234805, -0.08233311524234803, 0.04939986914540884]
BUG where 5 node 10 sum -0.36226570706633116 neigh [0.04939986914540882, -0.08233311524234803, -0.008233311524234803, -0.00823331152423479, -0.07409980371811323, 0.05763318066964363, -0.008233311524234807, 0.008233311524234805, -0.07409980371811323, 0.04939986914540884, 0.06586649219387844, 0.07409980371811324, 0.05763318066964363, 0.06586649219387844, 0.07409980371811324, -0.08233311524234803, -0.08233311524234803, -0.008233311524234803, -0.00823331152423479, -0.06586649219387843, 0.008233311524234803, -0.008233311524234807, -0.06586649219387843, 0.008233311524234807, -0.05763318066964362, -0.05763318066964362, 0.01646662304846961, 0.016466623048469606, -0.07409980371811323, -0.07409980371811323, -0.008233311524234805, -0.06586649219387843]
BUG where 5 node 11 sum 0.09056642676658283 neigh [0.07409980371811323, -0.06586649219387843, 0.0082333115242348, 0.07409980371811323, 1.415e-320, 9.88e-321, 4.2439915824e-314, 4.2439915824e-314, 2.1219957915e-314, 4.2439915824e-314, 2.1219957915e-314, 4.2439915824e-314, 2.121995792e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 2.121995792e-314, 2.1219957915e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 4.243991583e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 4.243991583e-314, 2.121995792e-314, 2.1219957915e-314]
BUG where 5 node 12 sum 7.8513844288e-313 neigh [2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 2.1219957915e-314, 2.121995792e-314, 2.1219957915e-314, 4.2439915824e-314, 2.121995792e-314, 2.1219957915e-314, 2.121995792e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 2.121995792e-314, 2.121995792e-314, 2.1219957915e-314, 2.121995792e-314, 4.243991583e-314, 4.243991583e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 4.243991583e-314, 2.1219957915e-314, 2.121995792e-314, 4.2439915824e-314, 2.1219957915e-314, 2.121995792e-314]
BUG where 5 node 13 sum 9.1245819033e-313 neigh [4.243991583e-314, 2.1219957915e-314, 4.2439915824e-314, 4.243991583e-314, 2.121995792e-314, 2.121995792e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 4.243991583e-314, 2.1219957915e-314, 2.121995792e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 4.2439915824e-314, 4.243991583e-314, 4.2439915824e-314, 2.121995792e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 4.243991583e-314, 2.121995792e-314, 2.121995792e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 4.2439915824e-314, 2.121995792e-314, 2.1219957915e-314, 2.1219957915e-314]
BUG where 5 node 14 sum 9.54898106137e-313 neigh [4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 4.2439915824e-314, 2.121995792e-314, 2.1219957915e-314, 2.121995792e-314, 4.2439915824e-314, 2.121995792e-314, 2.1219957915e-314, 2.1219957915e-314, 4.2439915824e-314, 4.243991583e-314, 2.1219957915e-314, 4.243991583e-314, 4.2439915824e-314, 4.2439915824e-314, 2.1219957915e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 4.243991583e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 4.2439915824e-314, 4.243991583e-314, 2.1219957915e-314, 2.1219957915e-314]
BUG where 5 node 15 sum 8.91238232393e-313 neigh [2.1219957915e-314, 2.1219957915e-314, 4.243991583e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 4.2439915824e-314, 4.243991583e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 4.2439915824e-314, 2.1219957915e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 4.2439915824e-314, 4.243991583e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 4.243991583e-314, 2.1219957915e-314]
BUG where 5 node 16 sum 8.06358400764e-313 neigh [2.1219957915e-314, 4.2439915824e-314, 2.121995792e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 2.1219957915e-314, 4.243991583e-314, 2.1219957915e-314, 2.1219957915e-314, 4.2439915824e-314, 2.1219957915e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 4.243991583e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 4.243991583e-314, 2.1219957915e-314]
BUG where 5 node 17 sum 8.48798316574e-313 neigh [2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 4.2439915824e-314, 4.2439915824e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 4.243991583e-314, 2.121995792e-314, 2.121995792e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 4.2439915824e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 2.121995792e-314, 2.1219957915e-314, 2.121995792e-314, 2.1219957915e-314, 2.121995792e-314, 2.1219957915e-314, 4.2439915824e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314]
BUG where 5 node 18 sum 8.27578392587e-313 neigh [2.121995792e-314, 2.1219957915e-314, 2.121995792e-314, 2.121995792e-314, 4.2439915824e-314, 4.243991583e-314, 2.1219957915e-314, 2.1219957915e-314, 4.2439915824e-314, 2.1219957915e-314, 2.121995792e-314, 4.243991583e-314, 2.121995792e-314, 2.1219957915e-314, 4.2439915824e-314, 2.1219957915e-314, 4.2439915824e-314, 4.243991583e-314, 2.1219957915e-314, 2.1219957915e-314, 2.1219957915e-314, 4.2439915824e-314, 2.1219957915e-314, 2.121995792e-314, 2.1219957915e-314, 2.1219957915e-314, 4.2439915824e-314, 2.121995792e-314, 2.1219957915e-314, 2.1219957915e-314, 2.403e-320, 9.88e-321]
BUG where 5 node 19 sum 4.7122131751734814e+257 neigh [6.90030591306087e-310, 6.90030591306087e-310, 0.0, 0.0, 0.0, 4.576724571519468e-72, 4.154940265e-315, 0.0, 0.0, 0.0, 2.66939915e-315, 3.830163056e-315, 0.0, 4.7122131751734814e+257, 0.0, 0.0, 4.23783069e-315, 4.576725400147601e-72, 0.0, 0.0, 0.0, 0.0, 0.0, 7.580522210078908e-96, 3.66440458e-315, 0.0, 0.0, 0.0, 9.155975073e-315, 0.0, 4.339809966e-315, 0.0]
BUG where 5 node 20 sum 1.5003789960419247e+248 neigh [7.501894980209624e+247, 4.403701745e-315, 0.0, 9.155975073e-315, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.658096027e-315, 2.666812524e-315, 4.07204981e-315, 0.0, 4.154940226e-315, 2.999394279595894e-67, 5.561117015929471e+180, 0.0, 0.0, 0.0, 1.881256767963911e-153, 0.0, 9.319165514e-315, 8.954020349881432e-96, 0.0, 2.666807465e-315, 4.57672108206333e-72, 0.0, 7.501894980209624e+247, 2.00627652677374e+174, 8.078071515e-315, 4.74328471e-315]
BUG where 5 node 21 sum 6.5058556142261936e+252 neigh [0.0, 0.0, 0.0, 1.0859524438207382e-95, 0.0, 3.66440458e-315, 1.0524891420998612e-153, 0.0, 0.0, 6.5058556142261765e+252, 3.435123510253565e+228, 9.020910903347914e+227, 9.154033647e-315, 0.0, 0.0, 0.0, 4.576725114193553e-72, 4.154940265e-315, 4.07204979e-315, 1.965682671938347e-62, 0.0, 0.0, 1.7456165665776496e+238, 9.6526577e-315, 0.0, 0.0, 4.857874402831079e-33, 0.0, 0.0, 2.690194107e-315, 7.679416644716942e-43, 4.740662697e-315]
BUG where 5 node 22 sum 1.7456165665776557e+238 neigh [0.0, 8.40888961e-315, 2.0038589417262814e+174, 8.078071515e-315, 0.0, 0.0, 1.6362609366062437e-259, 6.197507958756772e+223, 0.0, 8.986853895876604e-96, 1.7456165665776496e+238, 8.20726948532971e-67, 0.0, 1.9175678237849444e-76, 0.0, 0.0, 0.0, 9.124750331611583e+130, 1.9656845265414222e-62, 0.0, 0.0, 4.15494025e-315, 4.700991133010392e+180, 4.655466784769953e-72, 0.0, 0.0, 0.0, 0.0, 1.0358524682949276e-95, 1.05176078851283e-153, 0.0, 0.0]
BUG where 5 node 23 sum 1.4299007508667195e+248 neigh [4.160753264e-315, 1.892408391763662e-52, 7.679418093138845e-43, 0.0, 0.0, 4.409424996e-315, 0.0, 0.0, 0.0, 0.0, 2.438129035791793e-152, 0.0, 9.69278650547314e-72, 0.0, 0.0, 0.0, 1.7456165665776496e+238, 3.298494321178247e-33, 1.041469152328078e-152, 0.0, 0.0, 0.0, 0.0, 0.0, 1.7880038201745978e-52, 0.0, 0.0, 1.4299007506921578e+248, 3.995641367e-315, 0.0, 0.0, 0.0]
BUG where 5 node 24 sum 1.859466365794913e+224 neigh [3.663161274e-315, 0.0, 9.620089727120577e+140, 0.0, 0.0, 1.2067931256173953e-153, 0.0, 6.197506020910276e+223, 0.0, 0.0, 2.666803754e-315, 0.0, 0.0, 0.0, 0.0, 8.40435632e-315, 1.2397157637038853e+224, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.74036035e-315, 4.661077651060343e+164, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
BUG where 5 node 25 sum 7.501894980209624e+247 neigh [7.501894980209624e+247, 2.004830737050673e+174, 1.3038801260146376e-76, 0.0, 0.0, 1.9656740590948455e-62, 4.569392533e-315, 4.574881776e-315, 2.887586047002658e-57, 0.0, 0.0, 1.1325862060216063e-95, 9.921359153808403e-96, 0.0, 0.0, 2.66680873e-315, 0.0, 9.45999171e-315, 0.0, 9.65039108e-315, 0.0, 1.8812565135757096e-153, 0.0, 0.0, 0.0, 0.0, 3.665050897e-315, 0.0, 2.6668062e-315, 4.320721186e-315, 8.048688611931524e-96, 1.0523532163407868e-153]
BUG where 5 node 26 sum 5.455804490943341e+241 neigh [0.0, 0.0, 5.455804490942997e+241, 0.0, 2.66907283e-315, 3.435123510430066e+228, 2.68501353e-315, 0.0, 5.532889182313139e-48, 0.0, 9.422187985350652e-96, 4.576725114193553e-72, 0.0, 0.0, 0.0, 4.576724571519468e-72, 0.0, 2.689877974e-315, 0.0, 0.0, 9.091546700750836e+223, 2.690194107e-315, 0.0, 0.0, 1.132586329415246e-95, 5.4787e-320, 6.9004416449332e-310, 2.50278637e-316, 0.0, 0.0, 4.8578750597230484e-33, 4.8578750597249806e-33]
BUG where 5 node 27 sum 6.964257548469046e+252 neigh [6.0266960985165705e+175, 6.226552322778575e+228, 1.0466338790981406e-95, 1.0524892403370788e-153, 1.0511878506014034e-153, 8.714828628494737e-153, 1.4299012401367288e+248, 1.4402582951333969e+214, 4.661077651060343e+164, 921957890379437.9, 6.964114558345015e+252, 1.0520522281862506e-153, 1.051333521318742e-153, 1.965686744282115e-62, 3.298284967713639e-33, 9.890356965831112e-96, 1.745617018824271e+238, 7.67990555888565e-43, 1.0414695129168648e-152, 1.2397157637038853e+224, 3.6558219969685686e+233, 4.024752264471078e-66, 1.0520522281929338e-153, 1.0524988870581275e-153, 2.999391251237701e-67, 5.561117015929473e+180, 1.4317077195016407e-153, 3.644809997773729e-86, 1.2190794810927775e-152, 9.091548618506491e+223, 1.0517944332001939e-153, 2.999380119043039e-67]
BUG where 5 node 28 sum 1.5003794188182377e+248 neigh [4.576721098930842e-72, 6.723186442263826e-67, 1.4790021209569653e-76, 1.1717862039971318e-47, 7.501897094091188e+247, 2.004346144993444e+174, 1.3038803768416811e-76, 1.305722860445559e-57, 3.9466184252000937e+180, 1.9656740590948455e-62, 4.576725400147601e-72, 8.485854141072405e-96, 8.048689845330546e-96, 1.0523537853668571e-153, 6.723186442263826e-67, 1.4790021209569653e-76, 1.1717862039971318e-47, 7.501897094091188e+247, 2.002896950793333e+174, 1.3038803768416811e-76, 5.608036983253248e-48, 3.9466184252000937e+180, 1.965675913697921e-62, 1.1327692073978511e-95, 1.0513335213187735e-153, 4.576712159939451e-72, 2.9994027582407354e-67, 2.999385778842459e-67, 5.561117015929471e+180, 1.6574973314813344e-153, 3.443733529435134e-86, 4.8578750597249806e-33]
BUG where 5 node 29 sum 6.506074063262558e+252 neigh [1.4276011724267993e-71, 1.305722860445559e-57, 3.9466184252000937e+180, 1.965675913697921e-62, 7.67941814659414e-43, 1.025876837727037e-71, 2.8875865330987854e-57, 7.501897094091188e+247, 2.0033743496690524e+174, 2.907374247138779e-33, 4.8578750597249806e-33, 1.2845895094678944e-153, 1.636261471865146e-259, 6.197507958756772e+223, 9.692788271703333e-72, 1.1294860095369492e-95, 1.0514797610625892e-153, 1.0511878506014034e-153, 1.052061874905841e-153, 5.455805130285471e+241, 2.3216186759010554e-152, 6.505856054113045e+252, 3.435123510253565e+228, 9.020911818111283e+227, 2.4381298212991525e-152, 2.999394081137777e-67, 1.2882239519562425e-57, 1.1294860095369492e-95, 1.0514797610625892e-153, 1.0511878506014034e-153, 8.714828628494737e-153, 1.4299012401367288e+248]
BUG where 5 node 30 sum 6.964257548469063e+252 neigh [1.440258307298304e+214, 4.661077651060343e+164, 921957890379437.9, 6.964114558345015e+252, 1.0857695658163323e-95, 1.1794030929628898e-95, 8.985025116050978e-96, 1.745617018767416e+238, 1.4790960085923863e-76, 1.0414695129168634e-152, 1.2397157637038853e+224, 3.6558219969685686e+233, 4.024752264471078e-66, 1.0523435696277463e-153, 4.576703523772183e-72, 5.53289020445466e-48, 3.298284967713639e-33, 9.890356965831112e-96, 1.745617018824271e+238, 5.0331029070713e-38, 1.041469512916864e-152, 1.2397157637038853e+224, 3.6558219969685686e+233, 4.024752264471078e-66, 1.0524892403451526e-153, 1.051916204188333e-153, 1.051916773214505e-153, 1.0522075456232811e-153, 1.0513340903451852e-153, 8.712502449225612e-153, 1.4299012401367288e+248, 1.4402582951491345e+214]
BUG where 5 node 31 sum 5.224182039020912e+257 neigh [4.661077651060343e+164, 922232768286381.9, 6.964114558345015e+252, 1.0516152160340319e-153, 1.051333521318742e-153, 2.376369458436868e-38, 8.518686261272196e-96, 1.0522075456232788e-153, 1.0513340903451852e-153, 8.712502449225612e-153, 1.4299012401367288e+248, 1.440258303175465e+214, 4.857842640680845e-33, 4.8578750597249806e-33, 3.4351409855651e+228, 9.020926277062751e+227, 2.4381298212991525e-152, 2.376358090814435e-38, 9.422189553492613e-96, 8.986853895876604e-96, 1.0522075456232788e-153, 5.224112396445427e+257, 3.216755481127087e-57, 3.0379664568103346e-67, 6.026696098515304e+175, 6.226552322778575e+228, 8.593668249104526e-96, 2.999399740937331e-67, 9.692788263934519e-72, 1.0358524684906225e-95, 8.050518625592187e-96, 9.620089727120577e+140]
Cutting planes:
MIR: 1
Zero half: 2
Lazy constraints: 204
Explored 204 nodes (1602 simplex iterations) in 2.11 seconds
Thread count was 1 (of 4 available processors)
Solution count 3: 2950 3746 3850
Solve interrupted
Best objective 2.950000000000e+03, best bound 1.422000000000e+03, gap 51.7966%
User-callback calls 997, time in user-callback 1.66 sec
-
Official comment
This post is more than three 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 why not try our AI Gurobot?. -
From the documentation for Model.cbGetNodeRel():
Note that this method can only be invoked when the \( \texttt{where} \) value on the callback function is equal to \( \texttt{GRB.Callback.MIPNODE} \) and \( \texttt{GRB.Callback.MIPNODE_STATUS} \) is equal to \( \texttt{GRB.OPTIMAL} \)
Before calling Model.cbGetNodeRel(), can you try using Model.cbGet() to verify that the MIPNODE_STATUS is optimal? E.g.:
elif where == GRB.Callback.MIPNODE and model.cbGet(GRB.Callback.MIPNODE_STATUS) == GRB.OPTIMAL:
...0 -
Thank you for your help. I misunderstood this sentence. Therefore, I followed an example on the documentation for https://www.gurobi.com/documentation/9.1/refman/py_model_cbgetnoderel.html
def mycallback(model, where): if where == GRB.Callback.MIPNODE: print(model.cbGetNodeRel(model._vars))I think it would be better to update this example to check the value of as required by the documentation. Furthermore, it would be helpful to generate some kind of error when cbGetNodeRel is improperly used; e.g. if is used when where != GRB.Callback., then the following message is printed.
0 -
Hi Jiří,
Gurobi 9.5 was recently released. Included in this release is a fix to the strange behaviour of the Model.cbGetNodeRel() method you saw when MIPNODE_STATUS is not equal to GRB.OPTIMAL. With the new fix, an exception is raised if asking for a solution when MIPNODE_STATUS != GRB.OPTIMAL and the solution vector is initialized to GRB.UNDEFINED (1e+101) values.
The code snippet in the documentation of Model.cbGetNodeRel() is also fixed to check the model status before asking for a solution.
We hope this new fix works well for you. Please let us know if you find any issues using this.
Best regards,
Maliheh
0 -
Great. Thank you.
0
Post is closed for comments.
Comments
5 comments