EvaluatedConstraintCollection

EvaluatedConstraintCollection#

class EvaluatedConstraintCollection#

Live mapping of a Solution’s constraint results, including retained removed rows.

Obtained from constraints. The collection keeps its Solution alive and fetches each row on access. Each row is an independent snapshot containing labels, provenance, removal reasons, and evaluation diagnostics. Editing a fetched snapshot does not update the Solution. Use an owner method such as set_dual_variable() to update the result; subsequent collection access observes that update.

>>> from ommx import Instance
>>> model = Instance.minimize()
>>> x = model.new_binary("x")
>>> upper = model.add_constraint(x <= 1, "upper")
>>> lower = model.add_constraint(x >= 0, "lower")
>>> model.relax_constraint(lower.constraint_id, "inspect later")
>>> solution = model.evaluate({x.id: 0})
>>> rows = solution.constraints
>>> assert lower.constraint_id in rows
>>> assert rows[lower.constraint_id].removed_reason == "inspect later"
>>> snapshot = rows[upper.constraint_id]
>>> solution.set_dual_variable(upper.constraint_id, 3.0)
>>> assert snapshot.dual_variable is None
>>> assert rows[upper.constraint_id].dual_variable == 3.0
>>> snapshot.dual_variable = 8.0
>>> assert rows[upper.constraint_id].dual_variable == 3.0

Result types

The currently supported families have the following concrete result types. The set of possible families is open; use ConstraintIDBase and ConstraintView for common interfaces, and explicitly reject unsupported families when interpreting their mathematical meaning.

For the mixed-family typed-key contract, get, live views, iteration timing, and snapshot equality, see ConstraintCollection. Filter without collecting rows using of_kind and ConstraintFamilyView. constraints_df() collects one family as a DataFrame; retained removed constraints remain included. Its kind argument is required, as it is for constraint_context_df, constraint_parameters_df, constraint_provenance_df, and constraint_removed_reasons_df on all owners.

For multiple candidates, SampledConstraintCollection returns sampled rows. Their violations and feasible(atol=...) are keyed by sample ID. Per-sample objective and overall feasibility belong to summary, rather than the per-constraint rows.

__contains__(key: object) → bool#
__eq__(other: Any) → Any#
__getitem__(key: ConstraintID) → EvaluatedConstraint#
__getitem__(key: IndicatorConstraintID) → EvaluatedIndicatorConstraint
__getitem__(key: OneHotConstraintID) → EvaluatedOneHotConstraint
__getitem__(key: Sos1ConstraintID) → EvaluatedSos1Constraint
__getitem__(key: ConstraintIDBase) → ConstraintView

Fetch the constraint identified by a typed ID from the current owner.

__iter__() → Iterator[ConstraintIDBase]#

Iterate a snapshot of typed IDs; constraint rows are not collected.

__len__() → int#
__repr__() → str#
get(key: ConstraintID, default: None = None) → EvaluatedConstraint | None#
get(key: ConstraintID, default: _T) → EvaluatedConstraint | _T
get(key: IndicatorConstraintID, default: None = None) → EvaluatedIndicatorConstraint | None
get(key: IndicatorConstraintID, default: _T) → EvaluatedIndicatorConstraint | _T
get(key: OneHotConstraintID, default: None = None) → EvaluatedOneHotConstraint | None
get(key: OneHotConstraintID, default: _T) → EvaluatedOneHotConstraint | _T
get(key: Sos1ConstraintID, default: None = None) → EvaluatedSos1Constraint | None
get(key: Sos1ConstraintID, default: _T) → EvaluatedSos1Constraint | _T
get(key: ConstraintIDBase, default: None = None) → ConstraintView | None
get(key: ConstraintIDBase, default: ConstraintView) → ConstraintView
get(key: ConstraintIDBase, default: _T) → ConstraintView | _T
items() → ItemsView[ConstraintIDBase, ConstraintView]#

Live item view; each row is fetched when visited.

keys() → KeysView[ConstraintIDBase]#

Live key view. Iteration order is family order, then numeric ID.

of_kind(kind: Literal["regular"]) → ConstraintFamilyView[ConstraintID, EvaluatedConstraint]#
of_kind(kind: Literal["indicator"]) → ConstraintFamilyView[IndicatorConstraintID, EvaluatedIndicatorConstraint]
of_kind(kind: Literal["one_hot"]) → ConstraintFamilyView[OneHotConstraintID, EvaluatedOneHotConstraint]
of_kind(kind: Literal["sos1"]) → ConstraintFamilyView[Sos1ConstraintID, EvaluatedSos1Constraint]

Return a live view of one family without collecting rows. Uses the same kind strings as constraints_df. Integer keys are promoted; wrong-family IDs are rejected. The view retains this collection and its owner; row lifecycle and iteration snapshot rules match the original collection.

values() → ValuesView[ConstraintView]#

Live value view; each row is fetched when visited.