14 #ifndef OR_TOOLS_SAT_IMPLIED_BOUNDS_H_
15 #define OR_TOOLS_SAT_IMPLIED_BOUNDS_H_
24 #include "absl/container/flat_hash_map.h"
32 #include "ortools/sat/sat_parameters.pb.h"
88 : parameters_(*
model->GetOrCreate<SatParameters>()),
127 const auto it = literal_to_var_to_value_.find(
literal.Index());
128 return it != literal_to_var_to_value_.end() ? it->second
129 : empty_var_to_value_;
136 const std::vector<ValueLiteralPair>& encoding,
137 int exactly_one_index);
140 const absl::flat_hash_map<int, std::vector<ValueLiteralPair>>&
152 const SatParameters& parameters_;
159 std::vector<IntegerLiteral> tmp_integer_literals_;
167 absl::flat_hash_map<std::pair<LiteralIndex, IntegerVariable>, IntegerValue>
177 std::vector<ImpliedBoundEntry> empty_implied_bounds_;
183 absl::flat_hash_map<LiteralIndex,
184 absl::flat_hash_map<IntegerVariable, IntegerValue>>
185 literal_to_var_to_value_;
186 const absl::flat_hash_map<IntegerVariable, IntegerValue> empty_var_to_value_;
188 absl::flat_hash_map<IntegerVariable,
189 absl::flat_hash_map<int, std::vector<ValueLiteralPair>>>
190 var_to_index_to_element_encodings_;
191 const absl::flat_hash_map<int, std::vector<ValueLiteralPair>>
192 empty_element_encoding_;
193 std::vector<IntegerVariable> element_encoded_variables_;
196 int64_t num_deductions_ = 0;
197 int64_t num_enqueued_in_var_to_bounds_ = 0;
275 std::array<LiteralIndex, 2> GetKey(LiteralIndex
a, LiteralIndex
b)
const;
276 void ProcessNewProduct(LiteralIndex p, LiteralIndex
a, LiteralIndex
b);
277 void ProcessNewProduct(IntegerVariable p,
Literal l, IntegerVariable x);
294 absl::flat_hash_map<std::array<LiteralIndex, 3>, std::bitset<3>> detector_;
297 absl::flat_hash_map<std::array<LiteralIndex, 2>, std::vector<LiteralIndex>>
301 absl::flat_hash_map<std::array<LiteralIndex, 2>, LiteralIndex> products_;
305 absl::flat_hash_set<std::array<LiteralIndex, 2>> has_product_;
309 absl::flat_hash_set<std::pair<LiteralIndex, IntegerVariable>>
311 absl::flat_hash_map<std::pair<LiteralIndex, IntegerVariable>,
312 std::vector<IntegerVariable>>
313 conditional_equalities_;
316 absl::flat_hash_map<std::pair<LiteralIndex, IntegerVariable>, IntegerVariable>
320 int64_t num_products_ = 0;
321 int64_t num_int_products_ = 0;
322 int64_t num_trail_updates_ = 0;
323 int64_t num_processed_binary_ = 0;
324 int64_t num_processed_ternary_ = 0;
325 int64_t num_processed_exo_ = 0;
326 int64_t num_conditional_zeros_ = 0;
327 int64_t num_conditional_equalities_ = 0;
const std::vector< IntegerType > & PositionsSetAtLeastOnce() const
ImpliedBounds(Model *model)
bool EnqueueNewDeductions()
const std::vector< ImpliedBoundEntry > & GetImpliedBounds(IntegerVariable var)
void AddLiteralImpliesVarEqValue(Literal literal, IntegerVariable var, IntegerValue value)
bool Add(Literal literal, IntegerLiteral integer_literal)
const absl::flat_hash_map< int, std::vector< ValueLiteralPair > > & GetElementEncodings(IntegerVariable var)
void AddElementEncoding(IntegerVariable var, const std::vector< ValueLiteralPair > &encoding, int exactly_one_index)
const absl::flat_hash_map< IntegerVariable, IntegerValue > & GetImpliedValues(Literal literal) const
const std::vector< IntegerVariable > & GetElementEncodedVariables() const
const std::vector< IntegerVariable > & VariablesWithImpliedBounds() const
bool ProcessIntegerTrail(Literal first_decision)
Class that owns everything related to a particular optimization model.
void ProcessTernaryExactlyOne(absl::Span< const Literal > ternary_exo)
void ProcessTrailAtLevelOne()
LinearExpression ProductLowerBound(IntegerVariable a, IntegerVariable b)
ProductDetector(Model *model)
void ProcessConditionalZero(Literal l, IntegerVariable p)
LiteralIndex GetProduct(Literal a, Literal b) const
void ProcessBinaryClause(absl::Span< const Literal > binary_clause)
bool ProductIsLinearizable(IntegerVariable a, IntegerVariable b) const
LinearExpression LinearizeProduct(IntegerVariable a, IntegerVariable b)
void ProcessImplicationGraph(BinaryImplicationGraph *graph)
void ProcessTernaryClause(absl::Span< const Literal > ternary_clause)
void ProcessConditionalEquality(Literal l, IntegerVariable x, IntegerVariable y)
const IntegerVariable kNoIntegerVariable(-1)
bool DetectLinearEncodingOfProducts(const AffineExpression &left, const AffineExpression &right, Model *model, LinearConstraintBuilder *builder)
std::vector< LiteralValueValue > TryToDecomposeProduct(const AffineExpression &left, const AffineExpression &right, Model *model)
Collection of objects used to extend the Constraint Solver library.
ImpliedBoundEntry(IntegerVariable lit, IntegerValue lb, bool positive)
IntegerVariable literal_view