E-SE0012 — Decorated function parameter has no matching problem variable
Error Type |
|
|---|---|
Phase |
applying |
Python exception |
|
Message
The parameter `{name}` does not match any decision variable, placeholder, category label, or named expression already defined in the problem.
Possible fix: define `{name}` in the problem before this `@problem.update` call, or rename the parameter to match an existing name.
Cause
A function decorated with @problem.update may take extra parameters after the leading problem parameter; each one is looked up by name among the decision variables, placeholders, category labels, and named expressions already defined in the problem, and the matching object is passed in automatically. This error is raised when a parameter’s name does not match any of them — either because of a typo, or because the variable hasn’t been defined yet (for example, it is only created later in the same function, or in a @problem.update call that runs after this one).
Fix
Rename the parameter to match an existing variable, or make sure the variable is defined in an earlier @problem.update call (or earlier in the same problem’s construction) before this one runs:
problem = jm.Problem("example")
@problem.update
def _(problem: jm.DecoratedProblem):
x = problem.BinaryVar("x")
@problem.update
def _(problem: jm.DecoratedProblem, x: jm.DecisionVar):
problem += x <= 1