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"
35#include "ortools/sat/sat_parameters.pb.h"
60 void Add(
Literal x, absl::Span<const Literal> clause);
78 BooleanVariable>& mapping);
90 std::vector<Literal>
Clause(
int i)
const {
94 const int begin = clauses_start_[
i];
95 const int end =
i + 1 < clauses_start_.size() ? clauses_start_[
i + 1]
96 : clauses_literals_.size();
97 std::vector<Literal> result(clauses_literals_.begin() + begin,
98 clauses_literals_.begin() +
end);
99 for (
int j = 0; j < result.size(); ++j) {
100 if (result[j] == associated_literal_[
i]) {
101 std::swap(result[0], result[j]);
119 const int initial_num_variables_;
124 std::vector<int> clauses_start_;
125 std::deque<Literal> clauses_literals_;
126 std::vector<Literal> associated_literal_;
157 : postsolver_(postsolver),
158 num_trivial_clauses_(0),
159 drat_proof_handler_(nullptr),
173 equiv_mapping_ = mapping;
179 void AddClause(absl::Span<const Literal> clause);
190 bool Presolve(
const std::vector<bool>& var_that_can_be_removed);
201 int NumVariables()
const {
return literal_to_clause_sizes_.size() / 2; }
236 drat_proof_handler_ = drat_proof_handler;
241 bool ProcessClauseToSimplifyOthersUsingLiteral(
ClauseIndex clause_index,
247 void AddClauseInternal(std::vector<Literal>* clause);
252 void RemoveAndRegisterForPostsolveAllClauseContaining(
Literal x);
258 bool ProcessAllClauses();
262 Literal FindLiteralWithShortestOccurrenceList(
263 const std::vector<Literal>& clause);
264 LiteralIndex FindLiteralWithShortestOccurrenceListExcluding(
265 const std::vector<Literal>& clause,
Literal to_exclude);
277 void SimpleBva(LiteralIndex l);
280 void DisplayStats(
double elapsed_seconds);
285 uint64_t ComputeSignatureOfClauseVariables(
ClauseIndex ci);
290 void InitializePriorityQueue();
291 void UpdatePriorityQueue(BooleanVariable
var);
293 PQElement() : heap_index(-1), variable(-1), weight(0.0) {}
296 void SetHeapIndex(
int h) { heap_index = h; }
297 int GetHeapIndex()
const {
return heap_index; }
301 bool operator<(
const PQElement& other)
const {
302 return weight > other.weight;
306 BooleanVariable variable;
314 void InitializeBvaPriorityQueue();
315 void UpdateBvaPriorityQueue(LiteralIndex
lit);
316 void AddToBvaPriorityQueue(LiteralIndex
lit);
317 struct BvaPqElement {
318 BvaPqElement() : heap_index(-1), literal(-1), weight(0.0) {}
321 void SetHeapIndex(
int h) { heap_index = h; }
322 int GetHeapIndex()
const {
return heap_index; }
326 bool operator<(
const BvaPqElement& other)
const {
327 return weight < other.weight;
331 LiteralIndex literal;
334 std::deque<BvaPqElement> bva_pq_elements_;
338 absl::btree_set<LiteralIndex> m_lit_;
339 std::vector<ClauseIndex> m_cls_;
341 std::vector<std::pair<LiteralIndex, ClauseIndex>> flattened_p_;
342 std::vector<Literal> tmp_new_clause_;
346 std::vector<bool> in_clause_to_process_;
347 std::deque<ClauseIndex> clause_to_process_;
351 std::vector<std::vector<Literal>> clauses_;
354 std::vector<uint64_t> signatures_;
355 int64_t num_inspected_signatures_ = 0;
356 int64_t num_inspected_literals_ = 0;
368 SatPostsolver* postsolver_;
373 int num_trivial_clauses_;
374 SatParameters parameters_;
375 DratProofHandler* drat_proof_handler_;
376 TimeLimit* time_limit_ =
nullptr;
377 SolverLogger* logger_;
394 LiteralIndex* opposite_literal,
395 int64_t* num_inspected_literals =
nullptr);
402 const std::vector<Literal>&
b, Literal l);
415 const std::vector<Literal>&
b, std::vector<Literal>* out);
420 const std::vector<Literal>&
b);
435 SatSolver* solver, SatPostsolver* postsolver,
436 DratProofHandler* drat_proof_handler,
438 SolverLogger* =
nullptr);
SatPostsolver & operator=(const SatPostsolver &)=delete
std::vector< Literal > Clause(int i) const
const VariablesAssignment & assignment()
std::vector< bool > PostsolveSolution(const std::vector< bool > &solution)
void ApplyMapping(const util_intops::StrongVector< BooleanVariable, BooleanVariable > &mapping)
SatPostsolver(int num_variables)
void Add(Literal x, absl::Span< const Literal > clause)
SatPostsolver(const SatPostsolver &)=delete
This type is neither copyable nor movable.
std::vector< bool > ExtractAndPostsolveSolution(const SatSolver &solver)
void FixVariable(Literal x)
void AddBinaryClause(Literal a, Literal b)
void SetEquivalentLiteralMapping(const util_intops::StrongVector< LiteralIndex, LiteralIndex > &mapping)
const std::vector< Literal > & Clause(ClauseIndex ci) const
void SetParameters(const SatParameters ¶ms)
bool CrossProduct(Literal x)
SatPresolver(SatPostsolver *postsolver, SolverLogger *logger)
SatPresolver & operator=(const SatPresolver &)=delete
void SetNumVariables(int num_variables)
Adds new clause to the SatPresolver.
bool ProcessClauseToSimplifyOthers(ClauseIndex clause_index)
util_intops::StrongVector< BooleanVariable, BooleanVariable > VariableMapping() const
void AddClause(absl::Span< const Literal > clause)
void LoadProblemIntoSatSolver(SatSolver *solver)
void SetDratProofHandler(DratProofHandler *drat_proof_handler)
void SetTimeLimit(TimeLimit *time_limit)
void PresolveWithBva()
Visible for testing. Just applies the BVA step of the presolve.
SatPresolver(const SatPresolver &)=delete
This type is neither copyable nor movable.
LiteralIndex DifferAtGivenLiteral(const std::vector< Literal > &a, const std::vector< Literal > &b, Literal l)
void ProbeAndFindEquivalentLiteral(SatSolver *solver, SatPostsolver *postsolver, DratProofHandler *drat_proof_handler, util_intops::StrongVector< LiteralIndex, LiteralIndex > *mapping, SolverLogger *logger)
int ComputeResolvantSize(Literal x, const std::vector< Literal > &a, const std::vector< Literal > &b)
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)
In SWIG mode, we don't want anything besides these top-level includes.
std::optional< int64_t > end