19#ifndef OR_TOOLS_SAT_SIMPLIFICATION_H_
20#define OR_TOOLS_SAT_SIMPLIFICATION_H_
28#include "absl/container/btree_set.h"
29#include "absl/types/span.h"
36#include "ortools/sat/sat_parameters.pb.h"
57 void Add(
Literal x,
const absl::Span<const Literal> clause);
87 std::vector<Literal>
Clause(
int i)
const {
91 const int begin = clauses_start_[i];
92 const int end = i + 1 < clauses_start_.size() ? clauses_start_[i + 1]
93 : clauses_literals_.size();
94 std::vector<Literal> result(clauses_literals_.begin() + begin,
95 clauses_literals_.begin() +
end);
96 for (
int j = 0; j < result.size(); ++j) {
97 if (result[j] == associated_literal_[i]) {
112 const int initial_num_variables_;
117 std::vector<int> clauses_start_;
118 std::deque<Literal> clauses_literals_;
119 std::vector<Literal> associated_literal_;
152 : postsolver_(postsolver),
153 num_trivial_clauses_(0),
154 drat_proof_handler_(nullptr),
164 equiv_mapping_ = mapping;
170 void AddClause(absl::Span<const Literal> clause);
181 bool Presolve(
const std::vector<bool>& var_that_can_be_removed);
226 drat_proof_handler_ = drat_proof_handler;
231 bool ProcessClauseToSimplifyOthersUsingLiteral(
ClauseIndex clause_index,
237 void AddClauseInternal(std::vector<Literal>* clause);
242 void RemoveAndRegisterForPostsolveAllClauseContaining(
Literal x);
248 bool ProcessAllClauses();
252 Literal FindLiteralWithShortestOccurrenceList(
253 const std::vector<Literal>& clause);
254 LiteralIndex FindLiteralWithShortestOccurrenceListExcluding(
255 const std::vector<Literal>& clause,
Literal to_exclude);
267 void SimpleBva(LiteralIndex l);
270 void DisplayStats(
double elapsed_seconds);
275 uint64_t ComputeSignatureOfClauseVariables(
ClauseIndex ci);
280 void InitializePriorityQueue();
281 void UpdatePriorityQueue(BooleanVariable
var);
283 PQElement() : heap_index(-1), variable(-1),
weight(0.0) {}
286 void SetHeapIndex(
int h) { heap_index = h; }
287 int GetHeapIndex()
const {
return heap_index; }
291 bool operator<(
const PQElement& other)
const {
292 return weight > other.weight;
296 BooleanVariable variable;
304 void InitializeBvaPriorityQueue();
305 void UpdateBvaPriorityQueue(LiteralIndex lit);
306 void AddToBvaPriorityQueue(LiteralIndex lit);
307 struct BvaPqElement {
311 void SetHeapIndex(
int h) { heap_index = h; }
312 int GetHeapIndex()
const {
return heap_index; }
316 bool operator<(
const BvaPqElement& other)
const {
317 return weight < other.weight;
324 std::deque<BvaPqElement> bva_pq_elements_;
328 absl::btree_set<LiteralIndex> m_lit_;
329 std::vector<ClauseIndex> m_cls_;
331 std::vector<std::pair<LiteralIndex, ClauseIndex>> flattened_p_;
332 std::vector<Literal> tmp_new_clause_;
336 std::vector<bool> in_clause_to_process_;
337 std::deque<ClauseIndex> clause_to_process_;
341 std::vector<std::vector<Literal>> clauses_;
344 std::vector<uint64_t> signatures_;
345 int64_t num_inspected_signatures_ = 0;
346 int64_t num_inspected_literals_ = 0;
358 SatPostsolver* postsolver_;
363 int num_trivial_clauses_;
364 SatParameters parameters_;
365 DratProofHandler* drat_proof_handler_;
366 TimeLimit* time_limit_ =
nullptr;
367 SolverLogger* logger_;
386 LiteralIndex* opposite_literal,
387 int64_t* num_inspected_literals =
nullptr);
394 const std::vector<Literal>&
b, Literal l);
407 const std::vector<Literal>&
b, std::vector<Literal>* out);
412 const std::vector<Literal>&
b);
427 SatSolver* solver, SatPostsolver* postsolver,
428 DratProofHandler* drat_proof_handler,
442 std::unique_ptr<SatSolver>* solver, TimeLimit*
time_limit,
443 std::vector<bool>* solution ,
444 DratProofHandler* drat_proof_handler ,
445 SolverLogger* logger);
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
void Add(Literal x, const absl::Span< const Literal > clause)
SatPostsolver(int num_variables)
void FixVariable(Literal x)
void ApplyMapping(const absl::StrongVector< BooleanVariable, BooleanVariable > &mapping)
std::vector< bool > PostsolveSolution(const std::vector< bool > &solution)
std::vector< Literal > Clause(int i) const
std::vector< bool > ExtractAndPostsolveSolution(const SatSolver &solver)
void SetNumVariables(int num_variables)
const std::vector< Literal > & Clause(ClauseIndex ci) const
void LoadProblemIntoSatSolver(SatSolver *solver)
void AddBinaryClause(Literal a, Literal b)
SatPresolver(SatPostsolver *postsolver, SolverLogger *logger)
void SetEquivalentLiteralMapping(const absl::StrongVector< LiteralIndex, LiteralIndex > &mapping)
void SetParameters(const SatParameters ¶ms)
absl::StrongVector< BooleanVariable, BooleanVariable > VariableMapping() const
void SetDratProofHandler(DratProofHandler *drat_proof_handler)
void AddClause(absl::Span< const Literal > clause)
bool ProcessClauseToSimplifyOthers(ClauseIndex clause_index)
void SetTimeLimit(TimeLimit *time_limit)
bool CrossProduct(Literal x)
ModelSharedTimeLimit * time_limit
void swap(IdMap< K, V > &a, IdMap< K, V > &b)
int ComputeResolvantSize(Literal x, const std::vector< Literal > &a, const std::vector< Literal > &b)
LiteralIndex DifferAtGivenLiteral(const std::vector< Literal > &a, const std::vector< Literal > &b, Literal l)
bool SimplifyClause(const std::vector< Literal > &a, std::vector< Literal > *b, LiteralIndex *opposite_literal, int64_t *num_inspected_literals)
bool ComputeResolvant(Literal x, const std::vector< Literal > &a, const std::vector< Literal > &b, std::vector< Literal > *out)
SatSolver::Status SolveWithPresolve(std::unique_ptr< SatSolver > *solver, TimeLimit *time_limit, std::vector< bool > *solution, DratProofHandler *drat_proof_handler, SolverLogger *logger)
void ProbeAndFindEquivalentLiteral(SatSolver *solver, SatPostsolver *postsolver, DratProofHandler *drat_proof_handler, absl::StrongVector< LiteralIndex, LiteralIndex > *mapping)
Collection of objects used to extend the Constraint Solver library.
std::optional< int64_t > end