20 #ifndef OR_TOOLS_SAT_ENCODING_H_
21 #define OR_TOOLS_SAT_ENCODING_H_
32 #include "ortools/sat/boolean_problem.pb.h"
88 int size()
const {
return literals_.size(); }
91 CHECK_LT(i, literals_.size());
98 return depth_ > other.depth_ ||
99 (depth_ == other.depth_ && other.for_sorting_ > for_sorting_);
132 int depth()
const {
return depth_; }
134 int lb()
const {
return lb_; }
136 int ub()
const {
return ub_; }
147 BooleanVariable for_sorting_;
157 std::function<
Literal(
int x)> create_lit_ =
nullptr;
160 std::vector<Literal> literals_;
166 EncodingNode
LazyMerge(EncodingNode*
a, EncodingNode*
b, SatSolver* solver);
178 EncodingNode*
b, SatSolver* solver);
183 const std::vector<EncodingNode*>&
nodes,
185 std::deque<EncodingNode>* repository);
192 SatSolver* solver, std::deque<EncodingNode>* repository);
199 const std::vector<Literal>& literals,
200 const std::vector<Coefficient>& coeffs,
Coefficient* offset,
201 std::deque<EncodingNode>* repository);
203 const LinearObjective& objective_proto,
Coefficient* offset,
204 std::deque<EncodingNode>* repository);
217 const std::vector<Literal>& core);
228 std::deque<EncodingNode>* repository,
229 std::vector<EncodingNode*>*
nodes, SatSolver* solver);
245 std::deque<EncodingNode>* repository,
246 std::vector<EncodingNode*>*
nodes,
void InitializeLazyCoreNode(Coefficient weight, EncodingNode *a, EncodingNode *b)
Literal GetAssumption(SatSolver *solver)
EncodingNode * child_a() const
bool IncreaseCurrentUB(SatSolver *solver)
void ApplyWeightUpperBound(Coefficient gap, SatSolver *solver)
bool AssumptionIs(Literal other) const
Coefficient Reduce(const SatSolver &solver)
void InitializeLazyNode(EncodingNode *a, EncodingNode *b, SatSolver *solver)
void InitializeFullNode(int n, EncodingNode *a, EncodingNode *b, SatSolver *solver)
Coefficient weight() const
Literal literal(int i) const
std::string DebugString(const VariablesAssignment &assignment) const
EncodingNode * child_b() const
void set_weight(Coefficient w)
Literal GreaterThan(int i) const
void set_depth(int depth)
bool operator<(const EncodingNode &other) const
std::tuple< int64_t, int64_t, const double > Coefficient
Coefficient ComputeCoreMinWeight(const std::vector< EncodingNode * > &nodes, const std::vector< Literal > &core)
EncodingNode * MergeAllNodesWithDeque(Coefficient upper_bound, const std::vector< EncodingNode * > &nodes, SatSolver *solver, std::deque< EncodingNode > *repository)
EncodingNode * LazyMergeAllNodeWithPQAndIncreaseLb(Coefficient weight, const std::vector< EncodingNode * > &nodes, SatSolver *solver, std::deque< EncodingNode > *repository)
std::vector< Literal > ReduceNodesAndExtractAssumptions(Coefficient upper_bound, Coefficient stratified_lower_bound, Coefficient *lower_bound, std::vector< EncodingNode * > *nodes, SatSolver *solver)
void IncreaseNodeSize(EncodingNode *node, SatSolver *solver)
EncodingNode LazyMerge(EncodingNode *a, EncodingNode *b, SatSolver *solver)
EncodingNode FullMerge(Coefficient upper_bound, EncodingNode *a, EncodingNode *b, SatSolver *solver)
bool ProcessCore(const std::vector< Literal > &core, Coefficient min_weight, std::deque< EncodingNode > *repository, std::vector< EncodingNode * > *nodes, SatSolver *solver)
Coefficient MaxNodeWeightSmallerThan(const std::vector< EncodingNode * > &nodes, Coefficient upper_bound)
bool ProcessCoreWithAlternativeEncoding(const std::vector< Literal > &core, Coefficient min_weight, std::deque< EncodingNode > *repository, std::vector< EncodingNode * > *nodes, SatSolver *solver)
std::vector< EncodingNode * > CreateInitialEncodingNodes(const std::vector< Literal > &literals, const std::vector< Coefficient > &coeffs, Coefficient *offset, std::deque< EncodingNode > *repository)
Collection of objects used to extend the Constraint Solver library.