E-SE0001 — Unsupported loop target in a comprehension

Error Type

Syntax Error

Phase

defining a problem with the decorator API

Python exception

SyntaxError (builtin)

Message

The loop target of this comprehension must be a plain variable name or a tuple of names.

Possible fix: rewrite it using simple names such as `i` or `(i, j)`.

Cause

Inside a decorated function, a comprehension passed to jijmodeling.sum, prod, min, max, set, genarray, gendict, or problem.Constraint has a for clause whose loop target is neither a single plain variable name nor a tuple of plain variable names. Rejected targets include nested tuples such as for (i, (j, k)) in S, list targets such as for [i, j] in S, and subscripted or dotted targets such as for x[0] in S. For tuple targets, every element must itself be a plain name; parenthesizing the tuple, as in for (i, j) in S, is fine.

Fix

Rewrite the loop target so it consists of plain names only:

problem += jm.sum(w[i, j] for [i, j] in E)   # rejected: list target
problem += jm.sum(w[i, j] for i, j in E)     # accepted: tuple of names

If your index set yields nested tuples, introduce one name per component at a single level instead of destructuring the nesting in the target.