1 constraints.Constraint

constraints.Constraint(expr, sense, name=None)

Represents an optimization constraint.

A constraint has the form: expr sense 0 where sense is one of: <=, >=, ==

The expression is normalized so RHS is always 0. For example, x + y <= 5 becomes (x + y - 5) <= 0.

1.1 Attributes

Name Type Description
expr Expression The constraint expression (LHS - RHS, so constraint is expr sense 0)
sense str The constraint type: “<=”, “>=”, or “==”
name str | None Optional name for the constraint

1.2 Methods

Name Description
evaluate Evaluate the constraint expression at a point.
get_variables Get all variables in this constraint.
is_satisfied Check if constraint is satisfied at a point.
violation Compute constraint violation (0 if satisfied).

1.2.1 evaluate

constraints.Constraint.evaluate(point)

Evaluate the constraint expression at a point.

Returns the value of expr at the point. For a satisfied constraint: - <= constraint: value <= 0 - >= constraint: value >= 0 - == constraint: value == 0

1.2.2 get_variables

constraints.Constraint.get_variables()

Get all variables in this constraint.

1.2.3 is_satisfied

constraints.Constraint.is_satisfied(point, tol=1e-08)

Check if constraint is satisfied at a point.

1.2.3.1 Parameters

Name Type Description Default
point dict[str, float] Dictionary of variable values. required
tol float Tolerance for satisfaction check. 1e-08

1.2.3.2 Returns

Name Type Description
bool True if constraint is satisfied within tolerance.

1.2.4 violation

constraints.Constraint.violation(point)

Compute constraint violation (0 if satisfied).

1.2.4.1 Parameters

Name Type Description Default
point dict[str, float] Dictionary of variable values. required

1.2.4.2 Returns

Name Type Description
float Non-negative violation amount. Zero means satisfied.