E-CE0022 — Constraint is infeasible under fixed_variables
Error Type |
|
|---|---|
Phase |
compiling the problem into an OMMX instance |
Python exception |
|
Message
Constraint `{constraint}` is infeasible under the given `fixed_variables`: {reason}.
Possible fix: adjust `fixed_variables` so that constraint `{constraint}` can be satisfied.
{constraint} is the constraint name, with a subscript when the constraint is a family (for example `onehot[2]`).
{reason} names the conflicting fixed values, for example:
all variables in the one-hot constraint are fixed to
0, so their sum cannot equal1multiple variables in the one-hot constraint are fixed to
1(`x[0]`, `x[2]`)variable
`x[0]`in the one-hot constraint is fixed to0.5, which is neither0nor1multiple variables in the SOS1 constraint are fixed to non-zero values (
`x[0]` = `1`, `x[1]` = `1`)
Cause
When eval_problem (or Problem.eval) runs with constraint detection enabled, a detected one-hot or SOS1 constraint is checked against fixed_variables.
The error is raised when those fixed values already make the constraint unsatisfiable:
a one-hot constraint (
sum == 1) with every variable in the set fixed to0a one-hot constraint with two or more variables fixed to
1a one-hot constraint with a variable fixed to a value other than
0or1an SOS1 constraint (
sum <= 1) with two or more variables fixed to a non-zero value
Fixing one variable to 1 (or, for SOS1, to any non-zero value) and the rest to 0 is feasible; the compiler then drops the hint because it is already satisfied, and does not raise this error.
Fix
Change fixed_variables so the named constraint can still be satisfied. Typical cases:
# x = problem.BinaryVar("x", shape=(n,)) with n = 3
# problem += problem.Constraint("onehot", x.sum() == 1)
# Incorrect: every variable in the one-hot set is 0
compiler = jm.Compiler.from_problem(
problem, {"N": 3}, fixed_variables={"x": {0: 0, 1: 0, 2: 0}}
)
# Incorrect: two variables are 1
compiler = jm.Compiler.from_problem(
problem, {"N": 3}, fixed_variables={"x": {0: 1, 2: 1}}
)
# Correct: at most one variable is 1
compiler = jm.Compiler.from_problem(
problem, {"N": 3}, fixed_variables={"x": {0: 1, 1: 0}}
)