ConstraintFamilyView

ConstraintFamilyView#

class ConstraintFamilyView#

Live, read-only mapping of one constraint family, created by of_kind.

The selected family fixes the key type. Indexing, get, and membership accept integers as well as that family’s typed IDs; an ID of another family raises TypeError. Iteration and dictionary keys retain typed IDs. A known ConstraintKind constant selects the concrete key and row types for static type checking.

>>> from ommx import ConstraintKind, ConstraintID, Instance
>>> model = Instance.minimize()
>>> x = model.new_binary("x")
>>> rule = model.add_constraint(x <= 1, "limit")
>>> regular = model.constraints.of_kind(ConstraintKind.Regular)
>>> assert rule.constraint_id == ConstraintID(0)
>>> assert regular[0] == regular[ConstraintID(0)]
>>> assert list(regular) == [ConstraintID(0)]
>>> assert 0 in regular
>>> assert regular.get(99) is None
>>> regular[0].set_name("capacity")
>>> assert model.constraints[ConstraintID(0)].name == "capacity"

Pass a ConstraintKind selector, as in constraints_df(kind=...). A string such as "sos1" raises TypeError. See EvaluatedConstraintCollection for the current ID and result-type table.

The view retains its owner without collecting rows. It follows the row ownership, equality, and iterator snapshot rules of ConstraintCollection: active model rows are attached handles, while removed and result rows are independent snapshots. This applies to Instance and ParametricInstance active and removed collections, and to Solution and SampleSet result collections.

Filtering is an inspection operation. Selecting one family does not establish that a solver or transformation supports every constraint in the model. A consumer must inspect all constraints and reject unsupported families; see ConstraintIDBase.

__contains__(key: object) → bool#
__eq__(other: Any) → Any#
__getitem__(key: _K | int) → _V_co#

Fetch a row using an integer or an ID of the selected family.

__iter__() → Iterator[_K]#

Snapshot this family’s typed IDs now; fetch rows only when indexed.

__len__() → int#

Number of current rows in the selected family.

__repr__() → str#
get(key: _K | int, default: None = None) → _V_co | None#
get(key: _K | int, default: _T) → _V_co | _T
items() → ItemsView[_K, _V_co]#

Live items view; keys remain typed and rows are fetched on demand.

keys() → KeysView[_K]#

Live keys view. View iterators snapshot IDs on first advance.

values() → ValuesView[_V_co]#

Live values view; rows are fetched on demand.