C++ Reference: class Constraint

This documentation is automatically generated.

A constraint.

This class enables you to modify the constraint that was previously added to the model.

The constraint must be built using the different \c CpModelBuilder::AddXXX methods.


Return type: ConstraintProto*

Returns the mutable underlying protobuf object (useful for model edition).


Return type: const std::string&

Returns the name of the constraint (or the empty string if not set).


Return type: Constraint

Arguments: absl::Span<const BoolVar> literals

The constraint will be enforced iff all literals listed here are true. If this is empty, then the constraint will always be enforced. An enforced constraint must be satisfied, and an un-enforced one will simply be ignored. This is also called half-reification. To have an equivalence between a literal and a constraint (full reification), one must add both a constraint (controlled by a literal l) and its negation (controlled by the negation of l). Important: as of September 2018, only a few constraint support enforcement: - bool_or, bool_and, linear: fully supported. - interval: only support a single enforcement literal. - other: no support (but can be added on a per-demand basis).


Return type: Constraint

Arguments: BoolVar literal

See OnlyEnforceIf(absl::Span literals).


Return type: const ConstraintProto&

Returns the underlying protobuf object (useful for testing).


Return type: Constraint

Arguments: const std::string& name

Sets the name of the constraint.