Reputation: 31
Im new to python in general and specially in OR Tools for optimization and any model I try to run i get this error.
From the research ive done it can have something to do with ortools itself and id have to change some things in its code but im not sure. Any ideas?
Upvotes: 2
Views: 581
Reputation: 121
I hit this problem too, and it turned out that, according to the documentation, I was trying to set a coefficient on a variable that "does not belong to the solver."
For example, the following code (borrowed from this example) reproduces the problem:
from ortools.linear_solver import pywraplp
solver = pywraplp.Solver.CreateSolver('GLOP')
ct = solver.Constraint(0, 2, 'ct')
x = None # This is a contrived bug
ct.SetCoefficient(x, 1)
The value for x
is wrong, it needs to be something like x = solver.NumVar(0, 1, 'x')
so that the solver
knows about x
before we try to set a coefficient on it.
It's unlikely that you're making the mistake that I contrived in my code example, but probably somewhere in your code you've got your variables mixed up and you're sending SetCoefficient
the wrong value for its first argument, causing it to error out with SystemError: <built-in function Constraint_SetCoefficient> returned NULL without setting an error
.
Upvotes: 0