gurobipy.GurobiError: Element 302194 of a double array is Nan or Inf

Viewed 105

I am trying to solve an ILP that optimises a problem on graphs using Gurobi. Unfortunately, I get the following error when creating the problem:

gurobipy.GurobiError: Element 302194 of a double array is Nan or Inf.

The error is thrown when setting the objective.

m.setObjective(quicksum([G.G.nodes[node]['prize'] * node_var for node, node_var in nodes.items()]) - quicksum([mod_var * mod[1][1] for mod, mod_var in modules.items()]), GRB.MAXIMIZE)

All my variables are initialised and have a finite value. I don't understand which double array is being referenced. I have not found a solution online.

Can anyone help me?

1 Answers

It's difficult to debug inside a Python generator expression. Try debugging by rewriting as loops, like the following:

obj = 0
for node, node_var in nodes.items():
  # print(f"node={node}, prize={G.G.nodes[node]['prize']}, node_var={node_var}")
  obj += G.G.nodes[node]['prize'] * node_var

for mod, mod_var in modules.items():
  # print(f"mod_var={mod_var}, mod={mod[1][1]}")
  obj -= mod_var * mod[1][1]

m.setObjective(obj, GRB.MAXIMIZE)

Since I can't test this code, it's possible there may be errors, but this should give you some ideas how to debug your issue.

Related