Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <cp_model_mapping.h>
Public Member Functions | |
bool | IsBoolean (int ref) const |
bool | IsInteger (int ref) const |
sat::Literal | Literal (int ref) const |
IntegerVariable | Integer (int ref) const |
AffineExpression | Affine (const LinearExpressionProto &exp) const |
IntervalVariable | Interval (int i) const |
template<typename List > | |
std::vector< IntegerVariable > | Integers (const List &list) const |
template<typename ProtoIndices > | |
std::vector< sat::Literal > | Literals (const ProtoIndices &indices) const |
template<typename List > | |
std::vector< AffineExpression > | Affines (const List &list) const |
template<typename ProtoIndices > | |
std::vector< IntervalVariable > | Intervals (const ProtoIndices &indices) const |
bool | ConstraintIsAlreadyLoaded (const ConstraintProto *ct) const |
bool | IsHalfEncodingConstraint (const ConstraintProto *ct) const |
int | GetProtoVariableFromBooleanVariable (BooleanVariable var) const |
int | GetProtoVariableFromIntegerVariable (IntegerVariable var) const |
const std::vector< IntegerVariable > & | GetVariableMapping () const |
LinearExpression | GetExprFromProto (const LinearExpressionProto &expr_proto) const |
int | NumIntegerVariables () const |
For logging only, these are not super efficient. | |
int | NumBooleanVariables () const |
int | NumProtoVariables () const |
Returns the number of variables in the loaded proto. | |
Friends | |
void | LoadVariables (const CpModelProto &model_proto, bool view_all_booleans_as_integers, Model *m) |
void | ExtractEncoding (const CpModelProto &model_proto, Model *m) |
Holds the mapping between CpModel proto indices and the sat::model ones.
This also holds some information used when loading a CpModel proto.
Definition at line 71 of file cp_model_mapping.h.
|
inline |
Definition at line 100 of file cp_model_mapping.h.
|
inline |
Definition at line 133 of file cp_model_mapping.h.
|
inline |
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.
Definition at line 152 of file cp_model_mapping.h.
|
inline |
Definition at line 179 of file cp_model_mapping.h.
|
inline |
Definition at line 166 of file cp_model_mapping.h.
|
inline |
Definition at line 170 of file cp_model_mapping.h.
|
inline |
Definition at line 175 of file cp_model_mapping.h.
|
inline |
Definition at line 91 of file cp_model_mapping.h.
|
inline |
Definition at line 117 of file cp_model_mapping.h.
|
inline |
Definition at line 109 of file cp_model_mapping.h.
|
inline |
Definition at line 141 of file cp_model_mapping.h.
|
inline |
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().
Definition at line 76 of file cp_model_mapping.h.
|
inline |
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.
Definition at line 161 of file cp_model_mapping.h.
|
inline |
Definition at line 81 of file cp_model_mapping.h.
|
inline |
Definition at line 86 of file cp_model_mapping.h.
|
inline |
Definition at line 125 of file cp_model_mapping.h.
|
inline |
Definition at line 198 of file cp_model_mapping.h.
|
inline |
For logging only, these are not super efficient.
Definition at line 191 of file cp_model_mapping.h.
|
inline |
Returns the number of variables in the loaded proto.
Definition at line 207 of file cp_model_mapping.h.
|
friend |
The logic assumes that the linear constraints have been presolved, so that equality with a domain bound have been converted to <= or >= and so that we never have any trivial inequalities.
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.
Detection of literal equivalent to (i_var == value). We collect all the half-reified constraint lit => equality or lit => inequality for a given variable, and we will later sort them to detect equivalence.
Detection of literal equivalent to (i_var >= bound). We also collect all the half-refied part and we will sort the vector for detection of the equivalence.
Loop over all constraints and fill var_to_equalities and inequalities.
ct is a linear constraint with one term and one enforcement literal.
Detect enforcement_literal => (var >= value or var <= value).
Detect implied bounds. The test is less strict than the above test.
Detect enforcement_literal => (var == value or var != value).
Detect Literal <=> X >= value
Encode the half-inequalities.
Detect Literal <=> X == value and associate them in the IntegerEncoder.
Encode the half-equalities.
If we have just an half-equality, lets not create the <=> literal but just add two implications. If we don't create hole, we don't really need the reverse literal. This way it is also possible for the ExtractElementEncoding() to detect later that actually this literal is <=> to var == value, and this way we create one less Boolean for the same result.
Update stats.
Definition at line 396 of file cp_model_loader.cc.
|
friend |
Extracts all the used variables in the CpModelProto and creates a sat::Model representation for them. More precisely
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.
All [0, 1] variables always have a corresponding Boolean, even if it is fixed to 0 (domain == [0,0]) or fixed to 1 (domain == [1,1]).
Compute the list of positive variable reference for which we need to create an IntegerVariable.
Compute the integer variable references used by the model.
We always add a linear relaxation for circuit/route except for linearization level zero.
Add the objectives variables that needs to be referenceable as integer even if they are only used as Booleans.
Make sure any unused variable, that is not already a Boolean is considered "used".
We want the variable in the problem order.
It is important for memory usage to reserve tight vector has we have many indexed by IntegerVariable. Unfortunately, we create intermediate IntegerVariable while loading large linear constraint, or when we have disjoint LP component. So this is a best effort at a tight upper bound.
Link any variable that has both views.
Associate with corresponding integer variable.
Create the interval variables.
Definition at line 126 of file cp_model_loader.cc.