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 raisesTypeError. Iteration and dictionary keys retain typed IDs. A knownConstraintKindconstant fixes the key type. Filtered active/inactive and result collections also preserve the concrete row type. The all-state modelconstraintsview returnsConstraintViewbecause a family ID does not encode role.>>> from ommx import ConstraintKind, ConstraintID, Instance >>> model = Instance.minimize() >>> x = model.new_binary("x") >>> rule = model.add_constraint(x <= 1, "limit") >>> regular = model.active_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.active_constraints[ConstraintID(0)].name == "capacity"
Pass a
ConstraintKindselector, as inconstraints_df(kind=...). A string such as"sos1"raisesTypeError. SeeEvaluatedConstraintCollectionfor 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
ActiveConstraintCollection: active model rows are attached handles, while inactive and result rows are independent snapshots. This applies to Instance and ParametricInstance active and inactive 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 the complete Active Formulation. Such consumers must inspect all active constraints and reject unsupported families; see
ConstraintIDBase.- __contains__(key: object) bool#
- __getitem__(key: _K | int) _V_co#
Fetch a row using an integer or an ID of the selected family.
- __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.