Constraint

Constraint#

class Constraint#

Constraint wrapper for Python

__copy__() Constraint#
__deepcopy__(_memo: Any) Constraint#
__new__(function: ToFunction, equality: Equality, name: Optional[str] = None, subscripts: Sequence[int] = [], description: Optional[str] = None, parameters: Mapping[str, str] = {}) Constraint#

Create a new Constraint.

Args:

  • function: The constraint function (int, float, DecisionVariable, Linear, Quadratic, Polynomial, or Function)

  • equality: The equality type (EqualToZero or LessThanOrEqualToZero)

  • name: Optional name for the constraint

  • subscripts: Optional subscripts for indexing

  • description: Optional description

  • parameters: Optional key-value parameters

__repr__() str#
add_description(description: str) Constraint#

Alias for set_description (backward compatibility) Returns self for method chaining

add_name(name: str) Constraint#

Alias for set_name (backward compatibility) Returns self for method chaining

add_parameter(key: str, value: str) Constraint#

Add a parameter to the constraint Returns self for method chaining

add_parameters(parameters: Mapping[str, str]) Constraint#

Alias for set_parameters (backward compatibility) Returns self for method chaining

add_subscripts(subscripts: Sequence[int]) Constraint#

Add subscripts to the constraint Returns self for method chaining

evaluate(state: ToState, atol: Optional[float] = None) EvaluatedConstraint#

Evaluate the constraint with the given state.

Args:

  • state: A State object, dict[int, float], or iterable of (int, float) tuples

  • atol: Optional absolute tolerance for evaluation

Returns: EvaluatedConstraint containing the evaluated value and feasibility

partial_evaluate(state: ToState, atol: Optional[float] = None) Constraint#

Partially evaluate the constraint with the given state.

This modifies self in-place and returns self for method chaining.

Args:

  • state: A State object, dict[int, float], or iterable of (int, float) tuples

  • atol: Optional absolute tolerance for evaluation

Returns: Self (modified in-place) for method chaining

set_description(description: str) Constraint#

Set the description of the constraint Returns self for method chaining

set_name(name: str) Constraint#

Set the name of the constraint Returns self for method chaining

set_parameters(parameters: Mapping[str, str]) Constraint#

Set the parameters of the constraint Returns self for method chaining

set_subscripts(subscripts: Sequence[int]) Constraint#

Set the subscripts of the constraint Returns self for method chaining

with_indicator(indicator_variable: DecisionVariable) IndicatorConstraint#

Create an indicator constraint from this constraint.

Returns an IndicatorConstraint where indicator_variable = 1 this constraint.

EQUAL_TO_ZERO: Equality#

Class constant for equality type: equal to zero (==)

LESS_THAN_OR_EQUAL_TO_ZERO: Equality#

Class constant for equality type: less than or equal to zero (<=)

property description: Optional[str]#

Read-only property.

property equality: Equality#

Read-only property.

property function: Function#

Read-only property.

property name: Optional[str]#

Read-only property.

property parameters: dict[str, str]#

Read-only property.

property subscripts: list[int]#

Read-only property.