C++ Reference: class CpModelMapping

This documentation is automatically generated.

Holds the mapping between CpModel proto indices and the sat::model ones.

This also holds some information used when loading a CpModel proto.
Method
ConstraintIsAlreadyLoaded

Return type: bool

Arguments: const ConstraintProto* ct

Depending on the option, we will load constraints in stages. This is used to detect constraints that are already loaded. For instance the interval constraints and the linear constraint of size 1 (encodings) are usually loaded first.

CreateVariables

Return type: void

Arguments: const CpModelProto& model_proto, bool view_all_booleans_as_integers, Model* m

Extracts all the used variables in the CpModelProto and creates a sat::Model representation for them. More precisely - All Boolean variables will be mapped. - All Interval variables will be mapped. - All non-Boolean variable will have a corresponding IntegerVariable, and depending on the view_all_booleans_as_integers, some or all of the BooleanVariable will also have an IntegerVariable corresponding to its "integer view". Note(user): We could create IntegerVariable on the fly as they are needed, but that loose the original variable order which might be useful in heuristics later.

DetectOptionalVariables

Return type: void

Arguments: const CpModelProto& model_proto, Model* m

Automatically detect optional variables.

ExtractEncoding

Return type: void

Arguments: const CpModelProto& model_proto, Model* m

Extract the encodings (IntegerVariable <-> Booleans) present in the model. This effectively load some linear constraints of size 1 that will be marked as already loaded.

GetProtoVariableFromBooleanVariable

Return type: int

Arguments: BooleanVariable var

Note that both these functions returns positive reference or -1.

GetProtoVariableFromIntegerVariable

Return type: int

Arguments: IntegerVariable var

GetVariableMapping

Return type: const std::vector<IntegerVariable>&

Integer

Return type: IntegerVariable

Arguments: int ref

Integers

Return type: std::vector<IntegerVariable>

Arguments: const List& list

Interval

Return type: IntervalVariable

Arguments: int i

Intervals

Return type: std::vector<IntervalVariable>

Arguments: const ProtoIndices& indices

IsBoolean

Return type: bool

Arguments: int ref

Returns true if the given CpModelProto variable reference refers to a Boolean variable. Such variable will always have an associated Literal(), but not always an associated Integer().

IsHalfEncodingConstraint

Return type: bool

Arguments: const ConstraintProto* ct

Returns true if the given constraint is a "half-encoding" constraint. That is, if it is of the form (b => size 1 linear) but there is no (<=) side in the model. Such constraint are detected while we extract integer encoding and are cached here so that we can deal properly with them during the linear relaxation.

IsInteger

Return type: bool

Arguments: int ref

Literal

Return type: sat::Literal

Arguments: int ref

Literals

Return type: std::vector<sat::Literal>

Arguments: const ProtoIndices& indices

LoadAffineView

Return type: AffineExpression

Arguments: const LinearExpressionProto& exp

TODO(user): We could "easily" create an intermediate variable for more complex linear expression. We could also identify duplicate expressions to not create two identical integer variable.

LoadBooleanSymmetries

Return type: void

Arguments: const CpModelProto& model_proto, Model* m

Experimental. Loads the symmetry form the proto symmetry field, as long as they only involve Booleans. TODO(user): We currently only have the code for Booleans, it is why we currently ignore symmetries involving integer variables.

NumBooleanVariables

Return type: int

NumIntegerVariables

Return type: int

For logging only, these are not super efficient.

NumProtoVariables

Return type: int

Returns the number of variables in the loaded proto.

PotentialEncodedValues

Return type: const absl::flat_hash_set<int64_t>&

Arguments: int var

Returns a heuristic set of values that could be created for the given variable when the constraints will be loaded. Note that the pointer is not stable across calls. It returns nullptr if the set is empty.

PropagateEncodingFromEquivalenceRelations

Return type: void

Arguments: const CpModelProto& model_proto, Model* m

Process all affine relations of the form a*X + b*Y == cte. For each literals associated to (X >= bound) or (X == value) associate it to its corresponding relation on Y. Also do the other side. TODO(user): In an ideal world, all affine relations like this should be removed in the presolve.