E-SE0011 — Category label iterated outside the decorator API
Error Type |
|
|---|---|
Phase |
using comprehension syntax on a |
Python exception |
|
Message
The category label `{name}` supports comprehension syntax only inside the decorator API.
Possible fix: move the comprehension into a function decorated with `@problem.update` or `@jijmodeling.Problem.define`, or build the expression with `map`/`filter`/`flat_map` instead.
Cause
Comprehension syntax was used on a CategoryLabel outside the decorator API, for example jm.sum(c[k] for k in K) in plain-API code, or the label was iterated directly with next(label).
Category labels support the iteration protocol only so that such comprehensions can be written inside a function decorated with @problem.update or @jm.Problem.define; there, the comprehension is rewritten before execution and the label is never actually iterated.
Outside that rewriting, the label behaves as an empty iterator: for loops and list(...) silently produce no items (the StopIteration is consumed as normal exhaustion), and an explicit next(label) call surfaces this message.
Fix
Either move the comprehension into the decorator API:
@problem.update
def _(problem):
K = problem.CategoryLabel("K")
c = problem.Float("c", dict_keys=K)
problem += jm.sum(c[k] for k in K)
or build the same expression in the plain API with map/filter/flat_map:
problem += jm.sum(K.map(lambda k: c[k]))