14#ifndef OR_TOOLS_SAT_IMPLIED_BOUNDS_H_
15#define OR_TOOLS_SAT_IMPLIED_BOUNDS_H_
24#include "absl/container/flat_hash_map.h"
25#include "absl/container/flat_hash_set.h"
26#include "absl/types/span.h"
36#include "ortools/sat/sat_parameters.pb.h"
92 : parameters_(*
model->GetOrCreate<SatParameters>()),
131 const auto it = literal_to_var_to_value_.find(
literal.Index());
132 return it != literal_to_var_to_value_.end() ? it->second
133 : empty_var_to_value_;
142 const SatParameters& parameters_;
149 std::vector<IntegerLiteral> tmp_integer_literals_;
157 absl::flat_hash_map<std::pair<LiteralIndex, IntegerVariable>, IntegerValue>
167 std::vector<ImpliedBoundEntry> empty_implied_bounds_;
173 absl::flat_hash_map<LiteralIndex,
174 absl::flat_hash_map<IntegerVariable, IntegerValue>>
175 literal_to_var_to_value_;
176 const absl::flat_hash_map<IntegerVariable, IntegerValue> empty_var_to_value_;
179 int64_t num_deductions_ = 0;
180 int64_t num_enqueued_in_var_to_bounds_ = 0;
190 void Add(IntegerVariable
var,
const std::vector<ValueLiteralPair>& encoding,
191 int exactly_one_index);
194 const absl::btree_map<int, std::vector<ValueLiteralPair>>&
Get(
195 IntegerVariable
var);
201 absl::btree_map<IntegerVariable,
202 absl::btree_map<int, std::vector<ValueLiteralPair>>>
203 var_to_index_to_element_encodings_;
204 const absl::btree_map<int, std::vector<ValueLiteralPair>>
205 empty_element_encoding_;
206 std::vector<IntegerVariable> element_encoded_variables_;
301 const absl::flat_hash_map<IntegerVariable, glop::ColIndex>& lp_vars,
306 const absl::flat_hash_map<IntegerVariable, std::vector<IntegerVariable>>&
308 return bool_rlt_candidates_;
316 IntegerVariable
b)
const {
317 if (
b <
a) std::swap(
a,
b);
318 const auto it = bool_rlt_ubs_.find({
a,
b});
324 std::array<LiteralIndex, 2> GetKey(LiteralIndex
a, LiteralIndex
b)
const;
325 void ProcessNewProduct(LiteralIndex p, LiteralIndex
a, LiteralIndex
b);
326 void ProcessNewProduct(IntegerVariable p,
Literal l, IntegerVariable
x);
327 void ProcessTernaryClauseForRLT(absl::Span<const Literal> clause);
332 IntegerVariable var1,
double lp1, IntegerVariable var2,
double lp2,
333 IntegerVariable bound_var,
double bound_lp);
337 const bool rlt_enabled_;
351 absl::flat_hash_map<std::array<LiteralIndex, 3>, std::bitset<3>> detector_;
354 absl::flat_hash_map<std::array<LiteralIndex, 2>, std::vector<LiteralIndex>>
358 absl::flat_hash_map<std::array<LiteralIndex, 2>, LiteralIndex> products_;
362 absl::flat_hash_set<std::array<LiteralIndex, 2>> has_product_;
366 absl::flat_hash_set<std::pair<LiteralIndex, IntegerVariable>>
368 absl::flat_hash_map<std::pair<LiteralIndex, IntegerVariable>,
369 std::vector<IntegerVariable>>
370 conditional_equalities_;
373 absl::flat_hash_map<std::pair<LiteralIndex, IntegerVariable>, IntegerVariable>
377 absl::flat_hash_map<IntegerVariable, std::vector<IntegerVariable>>
378 bool_rlt_candidates_;
379 absl::flat_hash_map<std::pair<IntegerVariable, IntegerVariable>,
386 std::vector<IntegerVariable> ternary_clauses_with_view_;
389 int64_t num_products_ = 0;
390 int64_t num_int_products_ = 0;
391 int64_t num_trail_updates_ = 0;
392 int64_t num_processed_binary_ = 0;
393 int64_t num_processed_ternary_ = 0;
394 int64_t num_processed_exo_ = 0;
395 int64_t num_conditional_zeros_ = 0;
396 int64_t num_conditional_equalities_ = 0;
const std::vector< IntegerType > & PositionsSetAtLeastOnce() const
void Add(IntegerVariable var, const std::vector< ValueLiteralPair > &encoding, int exactly_one_index)
ElementEncodings()=default
const absl::btree_map< int, std::vector< ValueLiteralPair > > & Get(IntegerVariable var)
Returns an empty map if there is no such encoding.
const std::vector< IntegerVariable > & GetElementEncodedVariables() const
Get an unsorted set of variables appearing in element encodings.
bool ProcessIntegerTrail(Literal first_decision)
bool EnqueueNewDeductions()
const absl::flat_hash_map< IntegerVariable, IntegerValue > & GetImpliedValues(Literal literal) const
Returns all the implied values stored for a given literal.
~ImpliedBounds()
Just display some global statistics on destruction.
ImpliedBounds(Model *model)
const std::vector< IntegerVariable > & VariablesWithImpliedBounds() const
void AddLiteralImpliesVarEqValue(Literal literal, IntegerVariable var, IntegerValue value)
Adds literal => var == value.
bool Add(Literal literal, IntegerLiteral integer_literal)
const std::vector< ImpliedBoundEntry > & GetImpliedBounds(IntegerVariable var)
Helper class to express a product as a linear constraint.
bool TryToLinearize(const AffineExpression &left, const AffineExpression &right, LinearConstraintBuilder *builder)
ProductDecomposer(Model *model)
std::vector< LiteralValueValue > TryToDecompose(const AffineExpression &left, const AffineExpression &right)
void ProcessTernaryClause(absl::Span< const Literal > ternary_clause)
void ProcessTernaryExactlyOne(absl::Span< const Literal > ternary_exo)
void ProcessImplicationGraph(BinaryImplicationGraph *graph)
Utility function to process a bunch of implication all at once.
LinearExpression ProductLowerBound(IntegerVariable a, IntegerVariable b)
LiteralIndex GetProduct(Literal a, Literal b) const
Query function mainly used for testing.
LinearExpression LinearizeProduct(IntegerVariable a, IntegerVariable b)
bool ProductIsLinearizable(IntegerVariable a, IntegerVariable b) const
void ProcessConditionalEquality(Literal l, IntegerVariable x, IntegerVariable y)
void ProcessConditionalZero(Literal l, IntegerVariable p)
IntegerVariable LiteralProductUpperBound(IntegerVariable a, IntegerVariable b) const
void ProcessTrailAtLevelOne()
const absl::flat_hash_map< IntegerVariable, std::vector< IntegerVariable > > & BoolRLTCandidates() const
void InitializeBooleanRLTCuts(const absl::flat_hash_map< IntegerVariable, glop::ColIndex > &lp_vars, const util_intops::StrongVector< IntegerVariable, double > &lp_values)
ProductDetector(Model *model)
void ProcessBinaryClause(absl::Span< const Literal > binary_clause)
Simple class to add statistics by name and print them at the end.
const IntegerVariable kNoIntegerVariable(-1)
In SWIG mode, we don't want anything besides these top-level includes.
IntegerVariable literal_view
ImpliedBoundEntry(IntegerVariable lit, IntegerValue lb, bool positive)
These constructors are needed for OR-Tools.