E-CE0601 — Invalid key in a fixed-variables dictionary
Error Type |
|
|---|---|
Phase |
configuring |
Python exception |
|
Message
Invalid key of type `{type_name}` in the dictionary fixing an indexed variable in `fixed_variables`.
Each key must be one of the following:
- an integer
- a string
- a tuple of integers and strings
Possible fix: use the variable's subscripts as the key (e.g. `(0, 1)` or `"label"`).
({type_name} is the Python type of the offending key)
Cause
An entry in the fixed_variables argument (of Problem.eval, Problem.generate_random_instance, or the Compiler constructor) fixes an indexed decision variable with a dictionary mapping subscripts to values, and one of the keys was neither an integer, a string, nor a tuple.
For example, fixed_variables={"x": {0.5: 1.0}} raises this error because 0.5 is not a valid subscript.
Keys identify which element of the variable to fix: for a variable with a single index the key can be a plain integer or string, and for multiple indices it must be a tuple of integers and strings.
Fix
Use the variable’s subscripts as the dictionary keys:
problem.eval(
instance_data,
fixed_variables={
"x": {0: 1.0, 1: 0.0}, # one subscript per element
"y": {(0, "a"): 2.0}, # multiple subscripts as a tuple
},
)
Make sure the subscripts are plain Python int or str values (or tuples of them), matching how the variable is indexed in the model.