14#ifndef OR_TOOLS_SAT_CP_MODEL_MAPPING_H_
15#define OR_TOOLS_SAT_CP_MODEL_MAPPING_H_
21#include "absl/container/flat_hash_map.h"
22#include "absl/container/flat_hash_set.h"
49 std::vector<IntegerVariable>
vars;
96 if (exp.
vars().empty()) {
100 IntegerValue(exp.
offset()));
107 return intervals_[i];
110 template <
typename List>
111 std::vector<IntegerVariable>
Integers(
const List& list)
const {
112 std::vector<IntegerVariable> result;
113 for (
const auto i : list) result.push_back(
Integer(i));
117 template <
typename ProtoIndices>
118 std::vector<sat::Literal>
Literals(
const ProtoIndices& indices)
const {
119 std::vector<sat::Literal> result;
124 template <
typename List>
125 std::vector<AffineExpression>
Affines(
const List& list)
const {
126 std::vector<AffineExpression> result;
127 for (
const auto& i : list) result.push_back(
Affine(i));
131 template <
typename ProtoIndices>
132 std::vector<IntervalVariable>
Intervals(
const ProtoIndices& indices)
const {
133 std::vector<IntervalVariable> result;
134 for (
const int i : indices) result.push_back(
Interval(i));
143 return already_loaded_ct_.contains(
ct);
152 return is_half_encoding_ct_.contains(
ct);
157 if (
var.value() >= reverse_boolean_map_.size())
return -1;
158 return reverse_boolean_map_[
var];
161 if (
var.value() >= reverse_integer_map_.size())
return -1;
162 return reverse_integer_map_[
var];
173 for (
int j = 0; j < expr_proto.
coeffs_size(); ++j) {
174 expr.
coeffs.push_back(IntegerValue(expr_proto.
coeffs(j)));
183 for (
const IntegerVariable
var : integers_) {
190 for (
const BooleanVariable
var : booleans_) {
201 const auto& it = variables_to_encoded_values_.find(
var);
202 if (it != variables_to_encoded_values_.end()) {
213 bool view_all_booleans_as_integers,
Model* m);
218 std::vector<IntegerVariable> integers_;
219 std::vector<IntervalVariable> intervals_;
220 std::vector<BooleanVariable> booleans_;
230 absl::flat_hash_set<const ConstraintProto*> already_loaded_ct_;
231 absl::flat_hash_set<const ConstraintProto*> is_half_encoding_ct_;
233 absl::flat_hash_map<int, absl::flat_hash_set<int64_t>>
234 variables_to_encoded_values_;
235 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
int GetProtoVariableFromIntegerVariable(IntegerVariable var) const
friend void LoadVariables(const CpModelProto &model_proto, bool view_all_booleans_as_integers, Model *m)
const absl::flat_hash_set< int64_t > & PotentialEncodedValues(int var)
bool IsBoolean(int ref) const
int NumBooleanVariables() const
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
AffineExpression Affine(const LinearExpressionProto &exp) const
bool IsHalfEncodingConstraint(const ConstraintProto *ct) const
int GetProtoVariableFromBooleanVariable(BooleanVariable var) const
IntegerVariable Integer(int ref) const
std::vector< AffineExpression > Affines(const List &list) const
sat::Literal Literal(int ref) const
LinearExpression GetExprFromProto(const LinearExpressionProto &expr_proto) const
const std::vector< IntegerVariable > & GetVariableMapping() const
friend void ExtractEncoding(const CpModelProto &model_proto, Model *m)
int NumProtoVariables() const
std::vector< sat::Literal > Literals(const ProtoIndices &indices) const
int32_t vars(int index) const
int64_t coeffs(int index) const
Class that owns everything related to a particular optimization model.
CpModelProto const * model_proto
bool RefIsPositive(int ref)
const IntegerVariable kNoIntegerVariable(-1)
const IntervalVariable kNoIntervalVariable(-1)
LinearExpression CanonicalizeExpr(const LinearExpression &expr)
std::vector< IntegerVariable > NegationOf(const std::vector< IntegerVariable > &vars)
const BooleanVariable kNoBooleanVariable(-1)
double ToDouble(IntegerValue value)
Collection of objects used to extend the Constraint Solver library.
std::vector< IntegerValue > coeffs
std::vector< IntegerVariable > vars
std::vector< IntegerValue > coeffs
std::vector< IntegerVariable > vars
IntegerVariable objective_var
double ScaleIntegerObjective(IntegerValue value) const
absl::flat_hash_set< IntegerVariable > objective_impacting_variables