19#ifndef OR_TOOLS_SAT_SIMPLIFICATION_H_
20#define OR_TOOLS_SAT_SIMPLIFICATION_H_
28#include "absl/types/span.h"
56 void Add(
Literal x,
const absl::Span<const Literal> clause);
86 std::vector<Literal>
Clause(
int i)
const {
90 const int begin = clauses_start_[i];
91 const int end = i + 1 < clauses_start_.size() ? clauses_start_[i + 1]
92 : clauses_literals_.size();
93 std::vector<Literal> result(clauses_literals_.begin() + begin,
94 clauses_literals_.begin() + end);
95 for (
int j = 0; j < result.size(); ++j) {
96 if (result[j] == associated_literal_[i]) {
111 const int initial_num_variables_;
116 std::vector<int> clauses_start_;
117 std::deque<Literal> clauses_literals_;
118 std::vector<Literal> associated_literal_;
151 : postsolver_(postsolver),
152 num_trivial_clauses_(0),
153 drat_proof_handler_(nullptr),
163 equiv_mapping_ = mapping;
169 void AddClause(absl::Span<const Literal> clause);
180 bool Presolve(
const std::vector<bool>& var_that_can_be_removed);
191 int NumVariables()
const {
return literal_to_clause_sizes_.size() / 2; }
225 drat_proof_handler_ = drat_proof_handler;
230 bool ProcessClauseToSimplifyOthersUsingLiteral(
ClauseIndex clause_index,
236 void AddClauseInternal(std::vector<Literal>* clause);
241 void RemoveAndRegisterForPostsolveAllClauseContaining(
Literal x);
247 bool ProcessAllClauses();
251 Literal FindLiteralWithShortestOccurrenceList(
252 const std::vector<Literal>& clause);
253 LiteralIndex FindLiteralWithShortestOccurrenceListExcluding(
254 const std::vector<Literal>& clause,
Literal to_exclude);
266 void SimpleBva(LiteralIndex l);
269 void DisplayStats(
double elapsed_seconds);
274 uint64_t ComputeSignatureOfClauseVariables(
ClauseIndex ci);
279 void InitializePriorityQueue();
280 void UpdatePriorityQueue(BooleanVariable
var);
282 PQElement() : heap_index(-1), variable(-1),
weight(0.0) {}
285 void SetHeapIndex(
int h) { heap_index = h; }
286 int GetHeapIndex()
const {
return heap_index; }
290 bool operator<(
const PQElement& other)
const {
291 return weight > other.weight;
295 BooleanVariable variable;
303 void InitializeBvaPriorityQueue();
304 void UpdateBvaPriorityQueue(LiteralIndex lit);
305 void AddToBvaPriorityQueue(LiteralIndex lit);
306 struct BvaPqElement {
310 void SetHeapIndex(
int h) { heap_index = h; }
311 int GetHeapIndex()
const {
return heap_index; }
315 bool operator<(
const BvaPqElement& other)
const {
316 return weight < other.weight;
323 std::deque<BvaPqElement> bva_pq_elements_;
327 std::set<LiteralIndex> m_lit_;
328 std::vector<ClauseIndex> m_cls_;
330 std::vector<std::pair<LiteralIndex, ClauseIndex>> flattened_p_;
331 std::vector<Literal> tmp_new_clause_;
335 std::vector<bool> in_clause_to_process_;
336 std::deque<ClauseIndex> clause_to_process_;
340 std::vector<std::vector<Literal>> clauses_;
343 std::vector<uint64_t> signatures_;
344 int64_t num_inspected_signatures_ = 0;
345 int64_t num_inspected_literals_ = 0;
357 SatPostsolver* postsolver_;
362 int num_trivial_clauses_;
363 SatParameters parameters_;
364 DratProofHandler* drat_proof_handler_;
365 TimeLimit* time_limit_ =
nullptr;
366 SolverLogger* logger_;
385 LiteralIndex* opposite_literal,
386 int64_t* num_inspected_literals =
nullptr);
393 const std::vector<Literal>&
b, Literal l);
406 const std::vector<Literal>&
b, std::vector<Literal>* out);
411 const std::vector<Literal>&
b);
426 SatSolver* solver, SatPostsolver* postsolver,
427 DratProofHandler* drat_proof_handler,
441 std::unique_ptr<SatSolver>* solver, TimeLimit*
time_limit,
442 std::vector<bool>* solution ,
443 DratProofHandler* drat_proof_handler ,
444 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.