E-CE0020 — Scalar fixed value for an indexed variable

Error Type

Compile Error

Phase

compiling the problem into an OMMX instance

Python exception

ValueError

Message

The scalar fixed value `{value}` is assigned to the non-scalar decision variable `{name}`, which has {...}.

Possible fix: fix each element individually.

The {...} describes the variable’s domain and reads shape `{shape}` for tensor variables and keys `{keys}` for dict-keyed variables.

Cause

When a compiler is created with fixed_variables (e.g. Compiler.from_problem(problem, instance_data, fixed_variables=...)), each entry must match the indexing structure of the decision variable it fixes: a variable declared with shape or dict_keys takes a dict mapping subscript tuples to values. The error is raised when a single scalar value (e.g. {"x": 5.0}) is assigned to such an indexed variable (e.g. problem.BinaryVar("x", shape=(4,))).

Fix

Fix elements individually with a subscript-to-value dict. Any subset of elements may be fixed; you do not have to fix all of them:

# x = problem.BinaryVar("x", shape=(n,)) with n = 4
# Incorrect: a single scalar for the whole tensor
compiler = jm.Compiler.from_problem(problem, {"N": 4}, fixed_variables={"x": 1.0})
# Correct: per-element fixing (here only elements 1 and 3)
compiler = jm.Compiler.from_problem(problem, {"N": 4}, fixed_variables={"x": {(1,): 1.0, (3,): 1.0}})