14#ifndef OR_TOOLS_SAT_CP_MODEL_LOADER_H_
15#define OR_TOOLS_SAT_CP_MODEL_LOADER_H_
20#include "absl/container/flat_hash_set.h"
26#include "ortools/sat/cp_model.pb.h"
47 std::vector<IntegerVariable>
vars;
78 bool view_all_booleans_as_integers,
Model* m);
133 if (exp.vars().empty()) {
137 IntegerValue(exp.offset()));
144 return intervals_[i];
147 template <
typename List>
148 std::vector<IntegerVariable>
Integers(
const List& list)
const {
149 std::vector<IntegerVariable> result;
150 for (
const auto i : list) result.push_back(
Integer(i));
154 template <
typename ProtoIndices>
155 std::vector<sat::Literal>
Literals(
const ProtoIndices& indices)
const {
156 std::vector<sat::Literal> result;
161 template <
typename ProtoIndices>
162 std::vector<IntervalVariable>
Intervals(
const ProtoIndices& indices)
const {
163 std::vector<IntervalVariable> result;
164 for (
const int i : indices) result.push_back(
Interval(i));
173 return already_loaded_ct_.contains(
ct);
182 return is_half_encoding_ct_.contains(
ct);
187 if (
var.value() >= reverse_boolean_map_.
size())
return -1;
188 return reverse_boolean_map_[
var];
191 if (
var.value() >= reverse_integer_map_.
size())
return -1;
192 return reverse_integer_map_[
var];
202 for (
const IntegerVariable
var : integers_) {
209 for (
const BooleanVariable
var : booleans_) {
220 const auto& it = variables_to_encoded_values_.find(
var);
221 if (it != variables_to_encoded_values_.end()) {
230 std::vector<IntegerVariable> integers_;
231 std::vector<IntervalVariable> intervals_;
232 std::vector<BooleanVariable> booleans_;
242 absl::flat_hash_set<const ConstraintProto*> already_loaded_ct_;
243 absl::flat_hash_set<const ConstraintProto*> is_half_encoding_ct_;
245 absl::flat_hash_map<int, absl::flat_hash_set<int64>>
246 variables_to_encoded_values_;
247 const absl::flat_hash_set<int64> 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
int GetProtoVariableFromIntegerVariable(IntegerVariable var) const
AffineExpression LoadAffineView(const LinearExpressionProto &exp) const
bool IsBoolean(int ref) const
int NumBooleanVariables() const
void LoadBooleanSymmetries(const CpModelProto &model_proto, Model *m)
bool IsInteger(int ref) const
std::vector< IntegerVariable > Integers(const List &list) const
std::vector< IntervalVariable > Intervals(const ProtoIndices &indices) const
int NumIntegerVariables() const
bool ConstraintIsAlreadyLoaded(const ConstraintProto *ct) const
bool IsHalfEncodingConstraint(const ConstraintProto *ct) const
const absl::flat_hash_set< int64 > & PotentialEncodedValues(int var)
int GetProtoVariableFromBooleanVariable(BooleanVariable var) const
IntegerVariable Integer(int ref) const
sat::Literal Literal(int ref) const
const std::vector< IntegerVariable > & GetVariableMapping() 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)
void CreateVariables(const CpModelProto &model_proto, bool view_all_booleans_as_integers, Model *m)
std::vector< sat::Literal > Literals(const ProtoIndices &indices) const
Class that owns everything related to a particular optimization model.
CpModelProto const * model_proto
void LoadTableConstraint(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)
void MaybeFullyEncodeMoreVariables(const CpModelProto &model_proto, Model *m)
void LoadCircuitCoveringConstraint(const ConstraintProto &ct, 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)
void LoadIntDivConstraint(const ConstraintProto &ct, Model *m)
const IntervalVariable kNoIntervalVariable(-1)
const BooleanVariable kNoBooleanVariable(-1)
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)
double ToDouble(IntegerValue value)
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)
bool RefIsPositive(int ref)
void LoadElementConstraintAC(const ConstraintProto &ct, Model *m)
void LoadElementConstraintBounds(const ConstraintProto &ct, Model *m)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
std::vector< IntegerValue > coeffs
std::vector< IntegerVariable > vars
IntegerVariable objective_var
double ScaleIntegerObjective(IntegerValue value) const
absl::flat_hash_set< IntegerVariable > objective_impacting_variables