Constraints

Constraint — a bound on a numeric calculation that the solver must satisfy.

class ConstraintType(*values)[source]

Constraint operator.

Values:

EQUALITY: The expression must equal the bound. INEQUALITY: The expression must lie within the lower/upper bounds.

EQUALITY = 'equality'
INEQUALITY = 'inequality'
class Constraint(constraint)[source]

A bound on a numeric Calculation that the solver must respect.

Construct via ModelConfiguration.add_constraint(); configure via the chained set_* methods. Default type is ConstraintType.INEQUALITY with upper_bound = 0 and inclusive bounds.

set_type(constraint_type)[source]

Set the constraint type (equality or inequality).

Return type:

Constraint

set_lower_bound(lower_bound)[source]

Set the lower bound. Pass a literal, Calculation, or Parameter.

Return type:

Constraint

set_upper_bound(upper_bound)[source]

Set the upper bound. See set_lower_bound() for accepted types.

Return type:

Constraint

set_lower_bound_inclusive(lower_bound_inclusive)[source]

Toggle inclusive/exclusive comparison on the lower bound.

Return type:

Constraint

set_upper_bound_inclusive(upper_bound_inclusive)[source]

Toggle inclusive/exclusive comparison on the upper bound.

Return type:

Constraint

set_priority(priority)[source]

Set the constraint Priority.

Return type:

Constraint

set_hard_score(hard_score)[source]

Set the per-violation penalty applied to the solver’s hard score.

Return type:

Constraint

set_name(name)[source]

Set an optional display name.

Return type:

Constraint

build()[source]

Serialise to a JSON-compatible dict.

Return type:

dict[str, Any]