14 #ifndef OR_TOOLS_SAT_CP_MODEL_LOADER_H_
15 #define OR_TOOLS_SAT_CP_MODEL_LOADER_H_
21 #include "absl/container/flat_hash_set.h"
48 std::vector<IntegerVariable>
vars;
79 bool view_all_booleans_as_integers,
Model* m);
134 if (exp.vars().empty()) {
138 IntegerValue(exp.offset()));
145 return intervals_[i];
148 template <
typename List>
149 std::vector<IntegerVariable>
Integers(
const List& list)
const {
150 std::vector<IntegerVariable> result;
151 for (
const auto i : list) result.push_back(
Integer(i));
155 template <
typename ProtoIndices>
156 std::vector<sat::Literal>
Literals(
const ProtoIndices& indices)
const {
157 std::vector<sat::Literal> result;
162 template <
typename ProtoIndices>
163 std::vector<IntervalVariable>
Intervals(
const ProtoIndices& indices)
const {
164 std::vector<IntervalVariable> result;
165 for (
const int i : indices) result.push_back(
Interval(i));
174 return already_loaded_ct_.contains(
ct);
183 return is_half_encoding_ct_.contains(
ct);
188 if (
var.value() >= reverse_boolean_map_.
size())
return -1;
189 return reverse_boolean_map_[
var];
192 if (
var.value() >= reverse_integer_map_.
size())
return -1;
193 return reverse_integer_map_[
var];
203 for (
const IntegerVariable
var : integers_) {
210 for (
const BooleanVariable
var : booleans_) {
221 const auto& it = variables_to_encoded_values_.find(
var);
222 if (it != variables_to_encoded_values_.end()) {
234 std::vector<IntegerVariable> integers_;
235 std::vector<IntervalVariable> intervals_;
236 std::vector<BooleanVariable> booleans_;
246 absl::flat_hash_set<const ConstraintProto*> already_loaded_ct_;
247 absl::flat_hash_set<const ConstraintProto*> is_half_encoding_ct_;
249 absl::flat_hash_map<int, absl::flat_hash_set<int64_t>>
250 variables_to_encoded_values_;
251 const absl::flat_hash_set<int64_t> empty_set_;
#define CHECK_LT(val1, val2)
#define CHECK_GE(val1, val2)
#define CHECK_NE(val1, val2)
#define DCHECK_LT(val1, val2)
#define DCHECK(condition)
#define CHECK_LE(val1, val2)
IntervalVariable Interval(int i) const
std::vector< sat::Literal > Literals(const ProtoIndices &indices) const
int GetProtoVariableFromIntegerVariable(IntegerVariable var) const
AffineExpression LoadAffineView(const LinearExpressionProto &exp) const
std::vector< IntegerVariable > Integers(const List &list) const
const std::vector< IntegerVariable > & GetVariableMapping() const
std::vector< IntervalVariable > Intervals(const ProtoIndices &indices) const
bool IsBoolean(int ref) const
int NumBooleanVariables() const
void LoadBooleanSymmetries(const CpModelProto &model_proto, Model *m)
bool IsInteger(int ref) const
const absl::flat_hash_set< int64_t > & PotentialEncodedValues(int var)
int NumIntegerVariables() const
bool ConstraintIsAlreadyLoaded(const ConstraintProto *ct) const
bool IsHalfEncodingConstraint(const ConstraintProto *ct) const
int GetProtoVariableFromBooleanVariable(BooleanVariable var) const
IntegerVariable Integer(int ref) const
sat::Literal Literal(int ref) const
void DetectOptionalVariables(const CpModelProto &model_proto, Model *m)
void ExtractEncoding(const CpModelProto &model_proto, Model *m)
void PropagateEncodingFromEquivalenceRelations(const CpModelProto &model_proto, Model *m)
int NumProtoVariables() const
void CreateVariables(const CpModelProto &model_proto, bool view_all_booleans_as_integers, Model *m)
Class that owns everything related to a particular optimization model.
CpModelProto const * model_proto
void LoadTableConstraint(const ConstraintProto &ct, Model *m)
void LoadCircuitCoveringConstraint(const ConstraintProto &ct, Model *m)
void LoadExactlyOneConstraint(const ConstraintProto &ct, Model *m)
void LoadIntProdConstraint(const ConstraintProto &ct, Model *m)
bool LoadConstraint(const ConstraintProto &ct, Model *m)
void LoadBoolOrConstraint(const ConstraintProto &ct, Model *m)
bool RefIsPositive(int ref)
void MaybeFullyEncodeMoreVariables(const CpModelProto &model_proto, Model *m)
void LoadCumulativeConstraint(const ConstraintProto &ct, Model *m)
void LoadRoutesConstraint(const ConstraintProto &ct, Model *m)
void LoadReservoirConstraint(const ConstraintProto &ct, Model *m)
void LoadBoolAndConstraint(const ConstraintProto &ct, Model *m)
void LoadLinMaxConstraint(const ConstraintProto &ct, Model *m)
void LoadBoolXorConstraint(const ConstraintProto &ct, Model *m)
LinearExpression GetExprFromProto(const LinearExpressionProto &expr_proto, const CpModelMapping &mapping)
const IntegerVariable kNoIntegerVariable(-1)
const IntervalVariable kNoIntervalVariable(-1)
void LoadIntDivConstraint(const ConstraintProto &ct, Model *m)
void LoadLinearConstraint(const ConstraintProto &ct, Model *m)
void LoadAtMostOneConstraint(const ConstraintProto &ct, Model *m)
void LoadCircuitConstraint(const ConstraintProto &ct, Model *m)
void LoadIntMaxConstraint(const ConstraintProto &ct, Model *m)
void LoadNoOverlapConstraint(const ConstraintProto &ct, Model *m)
void LoadAllDiffConstraint(const ConstraintProto &ct, Model *m)
void LoadElementConstraint(const ConstraintProto &ct, Model *m)
std::vector< IntegerVariable > NegationOf(const std::vector< IntegerVariable > &vars)
void LoadAutomatonConstraint(const ConstraintProto &ct, Model *m)
void LoadNoOverlap2dConstraint(const ConstraintProto &ct, Model *m)
void LoadIntMinConstraint(const ConstraintProto &ct, Model *m)
void LoadInverseConstraint(const ConstraintProto &ct, Model *m)
const BooleanVariable kNoBooleanVariable(-1)
void LoadElementConstraintAC(const ConstraintProto &ct, Model *m)
double ToDouble(IntegerValue value)
void LoadElementConstraintBounds(const ConstraintProto &ct, Model *m)
Collection of objects used to extend the Constraint Solver library.
std::vector< IntegerValue > coeffs
std::vector< IntegerVariable > vars
IntegerVariable objective_var
double ScaleIntegerObjective(IntegerValue value) const
absl::flat_hash_set< IntegerVariable > objective_impacting_variables