OR-Tools  8.0
clause.h
Go to the documentation of this file.
1 // Copyright 2010-2018 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 // This file contains the solver internal representation of the clauses and the
15 // classes used for their propagation.
16 
17 #ifndef OR_TOOLS_SAT_CLAUSE_H_
18 #define OR_TOOLS_SAT_CLAUSE_H_
19 
20 #include <deque>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 
25 #include "absl/container/flat_hash_map.h"
26 #include "absl/container/flat_hash_set.h"
27 #include "absl/container/inlined_vector.h"
28 #include "absl/types/span.h"
29 #include "ortools/base/hash.h"
30 #include "ortools/base/int_type.h"
33 #include "ortools/base/macros.h"
35 #include "ortools/sat/model.h"
36 #include "ortools/sat/sat_base.h"
38 #include "ortools/util/bitset.h"
40 #include "ortools/util/stats.h"
42 
43 namespace operations_research {
44 namespace sat {
45 
46 // This is how the SatSolver stores a clause. A clause is just a disjunction of
47 // literals. In many places, we just use vector<literal> to encode one. But in
48 // the critical propagation code, we use this class to remove one memory
49 // indirection.
50 class SatClause {
51  public:
52  // Creates a sat clause. There must be at least 2 literals. Smaller clause are
53  // treated separatly and never constructed. In practice, we do use
54  // BinaryImplicationGraph for the clause of size 2, so this is mainly used for
55  // size at least 3.
56  static SatClause* Create(absl::Span<const Literal> literals);
57 
58  // Non-sized delete because this is a tail-padded class.
59  void operator delete(void* p) {
60  ::operator delete(p); // non-sized delete
61  }
62 
63  // Number of literals in the clause.
64  int size() const { return size_; }
65  int empty() const { return size_ == 0; }
66 
67  // Allows for range based iteration: for (Literal literal : clause) {}.
68  const Literal* const begin() const { return &(literals_[0]); }
69  const Literal* const end() const { return &(literals_[size_]); }
70 
71  // Returns the first and second literals. These are always the watched
72  // literals if the clause is attached in the LiteralWatchers.
73  Literal FirstLiteral() const { return literals_[0]; }
74  Literal SecondLiteral() const { return literals_[1]; }
75 
76  // Returns the literal that was propagated to true. This only works for a
77  // clause that just propagated this literal. Otherwise, this will just returns
78  // a literal of the clause.
79  Literal PropagatedLiteral() const { return literals_[0]; }
80 
81  // Returns the reason for the last unit propagation of this clause. The
82  // preconditions are the same as for PropagatedLiteral(). Note that we don't
83  // need to include the propagated literal.
84  absl::Span<const Literal> PropagationReason() const {
85  return absl::Span<const Literal>(&(literals_[1]), size_ - 1);
86  }
87 
88  // Returns a Span<> representation of the clause.
89  absl::Span<const Literal> AsSpan() const {
90  return absl::Span<const Literal>(&(literals_[0]), size_);
91  }
92 
93  // Removes literals that are fixed. This should only be called at level 0
94  // where a literal is fixed iff it is assigned. Aborts and returns true if
95  // they are not all false.
96  //
97  // Note that the removed literal can still be accessed in the portion [size,
98  // old_size) of literals().
100 
101  // Returns true if the clause is satisfied for the given assignment. Note that
102  // the assignment may be partial, so false does not mean that the clause can't
103  // be satisfied by completing the assignment.
104  bool IsSatisfied(const VariablesAssignment& assignment) const;
105 
106  // Returns true if the clause is attached to a LiteralWatchers.
107  bool IsAttached() const { return size_ > 0; }
108 
109  std::string DebugString() const;
110 
111  private:
112  // LiteralWatchers needs to permute the order of literals in the clause and
113  // call Clear()/Rewrite.
114  friend class LiteralWatchers;
115 
116  Literal* literals() { return &(literals_[0]); }
117 
118  // Marks the clause so that the next call to CleanUpWatchers() can identify it
119  // and actually detach it. We use size_ = 0 for this since the clause will
120  // never be used afterwards.
121  void Clear() { size_ = 0; }
122 
123  // Rewrites a clause with another shorter one. Note that the clause shouldn't
124  // be attached when this is called.
125  void Rewrite(absl::Span<const Literal> new_clause) {
126  size_ = 0;
127  for (const Literal l : new_clause) literals_[size_++] = l;
128  }
129 
130  int32 size_;
131 
132  // This class store the literals inline, and literals_ mark the starts of the
133  // variable length portion.
134  Literal literals_[0];
135 
136  DISALLOW_COPY_AND_ASSIGN(SatClause);
137 };
138 
139 // Clause information used for the clause database management. Note that only
140 // the clauses that can be removed have an info. The problem clauses and
141 // the learned one that we wants to keep forever do not have one.
142 struct ClauseInfo {
143  double activity = 0.0;
144  int32 lbd = 0;
146 };
147 
149 
150 // Stores the 2-watched literals data structure. See
151 // http://www.cs.berkeley.edu/~necula/autded/lecture24-sat.pdf for
152 // detail.
153 //
154 // This class is also responsible for owning the clause memory and all related
155 // information.
156 //
157 // TODO(user): Rename ClauseManager. This does more than just watching the
158 // clauses and is the place where all the clauses are stored.
160  public:
161  explicit LiteralWatchers(Model* model);
162  ~LiteralWatchers() override;
163 
164  // Must be called before adding clauses refering to such variables.
165  void Resize(int num_variables);
166 
167  // SatPropagator API.
168  bool Propagate(Trail* trail) final;
169  absl::Span<const Literal> Reason(const Trail& trail,
170  int trail_index) const final;
171 
172  // Returns the reason of the variable at given trail_index. This only works
173  // for variable propagated by this class and is almost the same as Reason()
174  // with a different return format.
175  SatClause* ReasonClause(int trail_index) const;
176 
177  // Adds a new clause and perform initial propagation for this clause only.
178  bool AddClause(absl::Span<const Literal> literals, Trail* trail);
179  bool AddClause(absl::Span<const Literal> literals);
180 
181  // Same as AddClause() for a removable clause. This is only called on learned
182  // conflict, so this should never have all its literal at false (CHECKED).
183  SatClause* AddRemovableClause(const std::vector<Literal>& literals,
184  Trail* trail);
185 
186  // Lazily detach the given clause. The deletion will actually occur when
187  // CleanUpWatchers() is called. The later needs to be called before any other
188  // function in this class can be called. This is DCHECKed.
189  //
190  // Note that we remove the clause from clauses_info_ right away.
191  void LazyDetach(SatClause* clause);
192  void CleanUpWatchers();
193 
194  // Detaches the given clause right away.
195  //
196  // TODO(user): It might be better to have a "slower" mode in
197  // PropagateOnFalse() that deal with detached clauses in the watcher list and
198  // is activated until the next CleanUpWatchers() calls.
199  void Detach(SatClause* clause);
200 
201  // Attaches the given clause. The first two literal of the clause must
202  // be unassigned and the clause must not be already attached.
203  void Attach(SatClause* clause, Trail* trail);
204 
205  // Reclaims the memory of the lazily removed clauses (their size was set to
206  // zero) and remove them from AllClausesInCreationOrder() this work in
207  // O(num_clauses()).
208  void DeleteRemovedClauses();
209  int64 num_clauses() const { return clauses_.size(); }
210  const std::vector<SatClause*>& AllClausesInCreationOrder() const {
211  return clauses_;
212  }
213 
214  // True if removing this clause will not change the set of feasible solution.
215  // This is the case for clauses that were learned during search. Note however
216  // that some learned clause are kept forever (heuristics) and do not appear
217  // here.
218  bool IsRemovable(SatClause* const clause) const {
219  return gtl::ContainsKey(clauses_info_, clause);
220  }
221  int64 num_removable_clauses() const { return clauses_info_.size(); }
222  absl::flat_hash_map<SatClause*, ClauseInfo>* mutable_clauses_info() {
223  return &clauses_info_;
224  }
225 
226  // Total number of clauses inspected during calls to PropagateOnFalse().
227  int64 num_inspected_clauses() const { return num_inspected_clauses_; }
229  return num_inspected_clause_literals_;
230  }
231 
232  // The number of different literals (always twice the number of variables).
233  int64 literal_size() const { return needs_cleaning_.size().value(); }
234 
235  // Number of clauses currently watched.
236  int64 num_watched_clauses() const { return num_watched_clauses_; }
237 
238  void SetDratProofHandler(DratProofHandler* drat_proof_handler) {
239  drat_proof_handler_ = drat_proof_handler;
240  }
241 
242  // Really basic algorithm to return a clause to try to minimize. We simply
243  // loop over the clause that we keep forever, in creation order. This starts
244  // by the problem clauses and then the learned one that we keep forever.
246  for (; to_minimize_index_ < clauses_.size(); ++to_minimize_index_) {
247  if (!clauses_[to_minimize_index_]->IsAttached()) continue;
248  if (!IsRemovable(clauses_[to_minimize_index_])) {
249  return clauses_[to_minimize_index_++];
250  }
251  }
252  return nullptr;
253  }
254 
255  // Restart the scan in NextClauseToMinimize() from the first problem clause.
256  void ResetToMinimizeIndex() { to_minimize_index_ = 0; }
257 
258  // During an inprocessing phase, it is easier to detach all clause first,
259  // then simplify and then reattach them. Note however that during these
260  // two calls, it is not possible to use the solver unit-progation.
261  //
262  // Important: When reattach is called, we assume that none of their literal
263  // are fixed, so we don't do any special checks.
264  //
265  // These functions can be called multiple-time and do the right things. This
266  // way before doing something, you can call the corresponding function and be
267  // sure to be in a good state. I.e. always AttachAllClauses() before
268  // propagation and DetachAllClauses() before going to do an inprocessing pass
269  // that might transform them.
270  void DetachAllClauses();
271  void AttachAllClauses();
272 
273  // These must only be called between [Detach/Attach]AllClauses() calls.
274  void InprocessingRemoveClause(SatClause* clause);
275  ABSL_MUST_USE_RESULT bool InprocessingFixLiteral(Literal true_literal);
276  ABSL_MUST_USE_RESULT bool InprocessingRewriteClause(
277  SatClause* clause, absl::Span<const Literal> new_clause);
278 
279  // This can return nullptr if new_clause was of size one or two as these are
280  // treated differently. Note that none of the variable should be fixed in the
281  // given new clause.
282  SatClause* InprocessingAddClause(absl::Span<const Literal> new_clause);
283 
284  // Contains, for each literal, the list of clauses that need to be inspected
285  // when the corresponding literal becomes false.
286  struct Watcher {
287  Watcher() {}
288  Watcher(SatClause* c, Literal b, int i = 2)
289  : blocking_literal(b), start_index(i), clause(c) {}
290 
291  // Optimization. A literal from the clause that sometimes allow to not even
292  // look at the clause memory when true.
294 
295  // Optimization. An index in the clause. Instead of looking for another
296  // literal to watch from the start, we will start from here instead, and
297  // loop around if needed. This allows to avoid bad quadratric corner cases
298  // and lead to an "optimal" complexity. See "Optimal Implementation of
299  // Watched Literals and more General Techniques", Ian P. Gent.
300  //
301  // Note that ideally, this should be part of a SatClause, so it can be
302  // shared across watchers. However, since we have 32 bits for "free" here
303  // because of the struct alignment, we store it here instead.
305 
307  };
308 
309  // This is exposed since some inprocessing code can heuristically exploit the
310  // currently watched literal and blocking literal to do some simplification.
311  const std::vector<Watcher>& WatcherListOnFalse(Literal false_literal) const {
312  return watchers_on_false_[false_literal.Index()];
313  }
314 
315  private:
316  // Attaches the given clause. This eventually propagates a literal which is
317  // enqueued on the trail. Returns false if a contradiction was encountered.
318  bool AttachAndPropagate(SatClause* clause, Trail* trail);
319 
320  // Launches all propagation when the given literal becomes false.
321  // Returns false if a contradiction was encountered.
322  bool PropagateOnFalse(Literal false_literal, Trail* trail);
323 
324  // Attaches the given clause to the event: the given literal becomes false.
325  // The blocking_literal can be any literal from the clause, it is used to
326  // speed up PropagateOnFalse() by skipping the clause if it is true.
327  void AttachOnFalse(Literal literal, Literal blocking_literal,
328  SatClause* clause);
329 
330  // Common code between LazyDetach() and Detach().
331  void InternalDetach(SatClause* clause);
332 
334 
335  // SatClause reasons by trail_index.
336  std::vector<SatClause*> reasons_;
337 
338  // Indicates if the corresponding watchers_on_false_ list need to be
339  // cleaned. The boolean is_clean_ is just used in DCHECKs.
340  SparseBitset<LiteralIndex> needs_cleaning_;
341  bool is_clean_ = true;
342 
343  BinaryImplicationGraph* implication_graph_;
344  Trail* trail_;
345 
346  int64 num_inspected_clauses_;
347  int64 num_inspected_clause_literals_;
348  int64 num_watched_clauses_;
349  mutable StatsGroup stats_;
350 
351  // For DetachAllClauses()/AttachAllClauses().
352  bool all_clauses_are_attached_ = true;
353 
354  // All the clauses currently in memory. This vector has ownership of the
355  // pointers. We currently do not use std::unique_ptr<SatClause> because it
356  // can't be used with some STL algorithms like std::partition.
357  //
358  // Note that the unit clauses are not kept here and if the parameter
359  // treat_binary_clauses_separately is true, the binary clause are not kept
360  // here either.
361  std::vector<SatClause*> clauses_;
362 
363  int to_minimize_index_ = 0;
364 
365  // Only contains removable clause.
366  absl::flat_hash_map<SatClause*, ClauseInfo> clauses_info_;
367 
368  DratProofHandler* drat_proof_handler_ = nullptr;
369 
370  DISALLOW_COPY_AND_ASSIGN(LiteralWatchers);
371 };
372 
373 // A binary clause. This is used by BinaryClauseManager.
374 struct BinaryClause {
375  BinaryClause(Literal _a, Literal _b) : a(_a), b(_b) {}
376  bool operator==(BinaryClause o) const { return a == o.a && b == o.b; }
377  bool operator!=(BinaryClause o) const { return a != o.a || b != o.b; }
380 };
381 
382 // A simple class to manage a set of binary clauses.
384  public:
386  int NumClauses() const { return set_.size(); }
387 
388  // Adds a new binary clause to the manager and returns true if it wasn't
389  // already present.
390  bool Add(BinaryClause c) {
391  std::pair<int, int> p(c.a.SignedValue(), c.b.SignedValue());
392  if (p.first > p.second) std::swap(p.first, p.second);
393  if (set_.find(p) == set_.end()) {
394  set_.insert(p);
395  newly_added_.push_back(c);
396  return true;
397  }
398  return false;
399  }
400 
401  // Returns the newly added BinaryClause since the last ClearNewlyAdded() call.
402  const std::vector<BinaryClause>& newly_added() const { return newly_added_; }
403  void ClearNewlyAdded() { newly_added_.clear(); }
404 
405  private:
406  absl::flat_hash_set<std::pair<int, int>> set_;
407  std::vector<BinaryClause> newly_added_;
408  DISALLOW_COPY_AND_ASSIGN(BinaryClauseManager);
409 };
410 
411 // Special class to store and propagate clauses of size 2 (i.e. implication).
412 // Such clauses are never deleted. Together, they represent the 2-SAT part of
413 // the problem. Note that 2-SAT satisfiability is a polynomial problem, but
414 // W2SAT (weighted 2-SAT) is NP-complete.
415 //
416 // TODO(user): Most of the note below are done, but we currently only applies
417 // the reduction before the solve. We should consider doing more in-processing.
418 // The code could probably still be improved too.
419 //
420 // Note(user): All the variables in a strongly connected component are
421 // equivalent and can be thus merged as one. This is relatively cheap to compute
422 // from time to time (linear complexity). We will also get contradiction (a <=>
423 // not a) this way. This is done by DetectEquivalences().
424 //
425 // Note(user): An implication (a => not a) implies that a is false. I am not
426 // sure it is worth detecting that because if the solver assign a to true, it
427 // will learn that right away. I don't think we can do it faster.
428 //
429 // Note(user): The implication graph can be pruned. This is called the
430 // transitive reduction of a graph. For instance If a => {b,c} and b => {c},
431 // then there is no need to store a => {c}. The transitive reduction is unique
432 // on an acyclic graph. Computing it will allow for a faster propagation and
433 // memory reduction. It is however not cheap. Maybe simple lazy heuristics to
434 // remove redundant arcs are better. Note that all the learned clauses we add
435 // will never be redundant (but they could introduce cycles). This is done
436 // by ComputeTransitiveReduction().
437 //
438 // Note(user): This class natively support at most one constraints. This is
439 // a way to reduced significantly the memory and size of some 2-SAT instances.
440 // However, it is not fully exploited for pure SAT problems. See
441 // TransformIntoMaxCliques().
442 //
443 // Note(user): Add a preprocessor to remove duplicates in the implication lists.
444 // Note that all the learned clauses we add will never create duplicates.
445 //
446 // References for most of the above and more:
447 // - Brafman RI, "A simplifier for propositional formulas with many binary
448 // clauses", IEEE Trans Syst Man Cybern B Cybern. 2004 Feb;34(1):52-9.
449 // http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.28.4911
450 // - Marijn J. H. Heule, Matti Järvisalo, Armin Biere, "Efficient CNF
451 // Simplification Based on Binary Implication Graphs", Theory and Applications
452 // of Satisfiability Testing - SAT 2011, Lecture Notes in Computer Science
453 // Volume 6695, 2011, pp 201-215
454 // http://www.cs.helsinki.fi/u/mjarvisa/papers/heule-jarvisalo-biere.sat11.pdf
456  public:
458  : SatPropagator("BinaryImplicationGraph"),
459  stats_("BinaryImplicationGraph"),
460  time_limit_(model->GetOrCreate<TimeLimit>()),
461  trail_(model->GetOrCreate<Trail>()) {
462  trail_->RegisterPropagator(this);
463  }
464 
467  LOG(INFO) << stats_.StatString();
468  LOG(INFO) << "num_redundant_implications " << num_redundant_implications_;
469  });
470  }
471 
472  // SatPropagator interface.
473  bool Propagate(Trail* trail) final;
474  absl::Span<const Literal> Reason(const Trail& trail,
475  int trail_index) const final;
476 
477  // Resizes the data structure.
478  void Resize(int num_variables);
479 
480  // Returns true if there is no constraints in this class.
481  bool IsEmpty() { return num_implications_ == 0 && at_most_ones_.empty(); }
482 
483  // Adds the binary clause (a OR b), which is the same as (not a => b).
484  // Note that it is also equivalent to (not b => a).
487  return AddBinaryClause(a.Negated(), b);
488  }
489 
490  // Same as AddBinaryClause() but enqueues a possible unit propagation. Note
491  // that if the binary clause propagates, it must do so at the last level, this
492  // is DCHECKed.
493  //
494  // Return false and do nothing if both a and b are currently false.
496 
497  // An at most one constraint of size n is a compact way to encode n * (n - 1)
498  // implications. This must only be called at level zero.
499  //
500  // Returns false if this creates a conflict. Currently this can only happens
501  // if there is duplicate literal already assigned to true in this constraint.
502  ABSL_MUST_USE_RESULT bool AddAtMostOne(absl::Span<const Literal> at_most_one);
503 
504  // Uses the binary implication graph to minimize the given conflict by
505  // removing literals that implies others. The idea is that if a and b are two
506  // literals from the given conflict and a => b (which is the same as not(b) =>
507  // not(a)) then a is redundant and can be removed.
508  //
509  // Note that removing as many literals as possible is too time consuming, so
510  // we use different heuristics/algorithms to do this minimization.
511  // See the binary_minimization_algorithm SAT parameter and the .cc for more
512  // details about the different algorithms.
513  void MinimizeConflictWithReachability(std::vector<Literal>* c);
514  void MinimizeConflictExperimental(const Trail& trail,
515  std::vector<Literal>* c);
516  void MinimizeConflictFirst(const Trail& trail, std::vector<Literal>* c,
519  const Trail& trail, std::vector<Literal>* c,
521 
522  // This must only be called at decision level 0 after all the possible
523  // propagations. It:
524  // - Removes the variable at true from the implications lists.
525  // - Frees the propagation list of the assigned literals.
526  void RemoveFixedVariables();
527 
528  // Returns false if the model is unsat, otherwise detects equivalent variable
529  // (with respect to the implications only) and reorganize the propagation
530  // lists accordingly.
531  //
532  // TODO(user): Completely get rid of such literal instead? it might not be
533  // reasonable code-wise to remap our literals in all of our constraints
534  // though.
535  bool DetectEquivalences(bool log_info = false);
536 
537  // Returns true if DetectEquivalences() has been called and no new binary
538  // clauses have been added since then. When this is true then there is no
539  // cycle in the binary implication graph (modulo the redundant literals that
540  // form a cycle with their representative).
541  bool IsDag() const { return is_dag_; }
542 
543  // One must call DetectEquivalences() first, this is CHECKed.
544  // Returns a list so that if x => y, then x is after y.
545  const std::vector<LiteralIndex>& ReverseTopologicalOrder() const {
546  CHECK(is_dag_);
547  return reverse_topological_order_;
548  }
549 
550  // Returns the list of literal "directly" implied by l. Beware that this can
551  // easily change behind your back if you modify the solver state.
552  const absl::InlinedVector<Literal, 6>& Implications(Literal l) const {
553  return implications_[l.Index()];
554  }
555 
556  // Returns the representative of the equivalence class of l (or l itself if it
557  // is on its own). Note that DetectEquivalences() should have been called to
558  // get any non-trival results.
560  if (l.Index() >= representative_of_.size()) return l;
561  if (representative_of_[l.Index()] == kNoLiteralIndex) return l;
562  return Literal(representative_of_[l.Index()]);
563  }
564 
565  // Prunes the implication graph by calling first DetectEquivalences() to
566  // remove cycle and then by computing the transitive reduction of the
567  // remaining DAG.
568  //
569  // Note that this can be slow (num_literals graph traversals), so we abort
570  // early if we start doing too much work.
571  //
572  // Returns false if the model is detected to be UNSAT (this needs to call
573  // DetectEquivalences() if not already done).
574  bool ComputeTransitiveReduction(bool log_info = false);
575 
576  // Another way of representing an implication graph is a list of maximal "at
577  // most one" constraints, each forming a max-clique in the incompatibility
578  // graph. This representation is useful for having a good linear relaxation.
579  //
580  // This function will transform each of the given constraint into a maximal
581  // one in the underlying implication graph. Constraints that are redundant
582  // after other have been expanded (i.e. included into) will be cleared.
583  //
584  // Returns false if the model is detected to be UNSAT (this needs to call
585  // DetectEquivalences() if not already done).
586  bool TransformIntoMaxCliques(std::vector<std::vector<Literal>>* at_most_ones,
587  int64 max_num_explored_nodes = 1e8);
588 
589  // Number of literal propagated by this class (including conflicts).
590  int64 num_propagations() const { return num_propagations_; }
591 
592  // Number of literals inspected by this class during propagation.
593  int64 num_inspections() const { return num_inspections_; }
594 
595  // MinimizeClause() stats.
596  int64 num_minimization() const { return num_minimization_; }
597  int64 num_literals_removed() const { return num_literals_removed_; }
598 
599  // Returns true if this literal is fixed or is equivalent to another literal.
600  // This means that it can just be ignored in most situation.
601  //
602  // Note that the set (and thus number) of redundant literal can only grow over
603  // time. This is because we always use the lowest index as representative of
604  // an equivalent class, so a redundant literal will stay that way.
605  bool IsRedundant(Literal l) const { return is_redundant_[l.Index()]; }
607  CHECK_EQ(num_redundant_literals_ % 2, 0);
608  return num_redundant_literals_;
609  }
610 
611  // Number of implications removed by transitive reduction.
613  return num_redundant_implications_;
614  }
615 
616  // Returns the number of current implications. Note that a => b and not(b) =>
617  // not(a) are counted separately since they appear separately in our
618  // propagation lists. The number of size 2 clauses that represent the same
619  // thing is half this number.
620  int64 num_implications() const { return num_implications_; }
621  int64 literal_size() const { return implications_.size(); }
622 
623  // Extract all the binary clauses managed by this class. The Output type must
624  // support an AddBinaryClause(Literal a, Literal b) function.
625  //
626  // Important: This currently does NOT include at most one constraints.
627  //
628  // TODO(user): When extracting to cp_model.proto we could be more efficient
629  // by extracting bool_and constraint with many lhs terms.
630  template <typename Output>
631  void ExtractAllBinaryClauses(Output* out) const {
632  // TODO(user): Ideally we should just never have duplicate clauses in this
633  // class. But it seems we do in some corner cases, so lets not output them
634  // twice.
635  absl::flat_hash_set<std::pair<LiteralIndex, LiteralIndex>>
636  duplicate_detection;
637  for (LiteralIndex i(0); i < implications_.size(); ++i) {
638  const Literal a = Literal(i).Negated();
639  for (const Literal b : implications_[i]) {
640  // Note(user): We almost always have both a => b and not(b) => not(a) in
641  // our implications_ database. Except if ComputeTransitiveReduction()
642  // was aborted early, but in this case, if only one is present, the
643  // other could be removed, so we shouldn't need to output it.
644  if (a < b &&
645  duplicate_detection.insert({a.Index(), b.Index()}).second) {
646  out->AddBinaryClause(a, b);
647  }
648  }
649  }
650  }
651 
652  void SetDratProofHandler(DratProofHandler* drat_proof_handler) {
653  drat_proof_handler_ = drat_proof_handler;
654  }
655 
656  // Changes the reason of the variable at trail index to a binary reason.
657  // Note that the implication "new_reason => trail_[trail_index]" should be
658  // part of the implication graph.
659  void ChangeReason(int trail_index, Literal new_reason) {
660  CHECK(trail_->Assignment().LiteralIsTrue(new_reason));
661  reasons_[trail_index] = new_reason.Negated();
662  trail_->ChangeReason(trail_index, propagator_id_);
663  }
664 
665  // The literals that are "directly" implied when literal is set to true. This
666  // is not a full "reachability". It includes at most ones propagation. The set
667  // of all direct implications is enough to describe the implications graph
668  // completely.
669  //
670  // When doing blocked clause elimination of bounded variable elimination, one
671  // only need to consider this list and not the full reachability.
672  const std::vector<Literal>& DirectImplications(Literal literal);
673 
674  // A proxy for DirectImplications().size(), However we currently do not
675  // maintain it perfectly. It is exact each time DirectImplications() is
676  // called, and we update it in some situation but we don't deal with fixed
677  // variables, at_most ones and duplicates implications for now.
679  return estimated_sizes_[literal.Index()];
680  }
681 
682  // Variable elimination by replacing everything of the form a => var => b by a
683  // => b. We ignore any a => a so the number of new implications is not always
684  // just the product of the two direct implication list of var and not(var).
685  // However, if a => var => a, then a and var are equivalent, so this case will
686  // be removed if one run DetectEquivalences() before this. Similarly, if a =>
687  // var => not(a) then a must be false and this is detected and dealt with by
688  // FindFailedLiteralAroundVar().
689  bool FindFailedLiteralAroundVar(BooleanVariable var, bool* is_unsat);
690  int64 NumImplicationOnVariableRemoval(BooleanVariable var);
692  BooleanVariable var, std::deque<std::vector<Literal>>* postsolve_clauses);
693  bool IsRemoved(Literal l) const { return is_removed_[l.Index()]; }
694 
695  // TODO(user): consider at most ones.
697 
698  private:
699  // Simple wrapper to not forget to output newly fixed variable to the DRAT
700  // proof if needed. This will propagate rigth away the implications.
701  bool FixLiteral(Literal true_literal);
702 
703  // Propagates all the direct implications of the given literal becoming true.
704  // Returns false if a conflict was encountered, in which case
705  // trail->SetFailingClause() will be called with the correct size 2 clause.
706  // This calls trail->Enqueue() on the newly assigned literals.
707  bool PropagateOnTrue(Literal true_literal, Trail* trail);
708 
709  // Remove any literal whose negation is marked (except the first one).
710  void RemoveRedundantLiterals(std::vector<Literal>* conflict);
711 
712  // Fill is_marked_ with all the descendant of root.
713  // Note that this also use dfs_stack_.
714  void MarkDescendants(Literal root);
715 
716  // Expands greedily the given at most one until we get a maximum clique in
717  // the underlying incompatibility graph. Note that there is no guarantee that
718  // if this is called with any sub-clique of the result we will get the same
719  // maximal clique.
720  std::vector<Literal> ExpandAtMostOne(
721  const absl::Span<const Literal> at_most_one);
722 
723  // Process all at most one constraints starting at or after base_index in
724  // at_most_one_buffer_. This replace literal by their representative, remove
725  // fixed literals and deal with duplicates. Return false iff the model is
726  // UNSAT.
727  bool CleanUpAndAddAtMostOnes(const int base_index);
728 
729  mutable StatsGroup stats_;
730  TimeLimit* time_limit_;
731  Trail* trail_;
732  DratProofHandler* drat_proof_handler_ = nullptr;
733 
734  // Binary reasons by trail_index. We need a deque because we kept pointers to
735  // elements of this array and this can dynamically change size.
736  std::deque<Literal> reasons_;
737 
738  // This is indexed by the Index() of a literal. Each list stores the
739  // literals that are implied if the index literal becomes true.
740  //
741  // Using InlinedVector helps quite a bit because on many problems, a literal
742  // only implies a few others. Note that on a 64 bits computer we get exactly
743  // 6 inlined int32 elements without extra space, and the size of the inlined
744  // vector is 4 times 64 bits.
745  //
746  // TODO(user): We could be even more efficient since a size of int32 is enough
747  // for us and we could store in common the inlined/not-inlined size.
749  int64 num_implications_ = 0;
750 
751  // Internal representation of at_most_one constraints. Each entry point to the
752  // start of a constraint in the buffer. Contraints are terminated by
753  // kNoLiteral. When LiteralIndex is true, then all entry in the at most one
754  // constraint must be false except the one refering to LiteralIndex.
755  //
756  // TODO(user): We could be more cache efficient by combining this with
757  // implications_ in some way. Do some propagation speed benchmark.
759  std::vector<Literal> at_most_one_buffer_;
760 
761  // Some stats.
762  int64 num_propagations_ = 0;
763  int64 num_inspections_ = 0;
764  int64 num_minimization_ = 0;
765  int64 num_literals_removed_ = 0;
766  int64 num_redundant_implications_ = 0;
767  int64 num_redundant_literals_ = 0;
768 
769  // Bitset used by MinimizeClause().
770  // TODO(user): use the same one as the one used in the classic minimization
771  // because they are already initialized. Moreover they contains more
772  // information.
773  SparseBitset<LiteralIndex> is_marked_;
774  SparseBitset<LiteralIndex> is_simplified_;
775 
776  // Temporary stack used by MinimizeClauseWithReachability().
777  std::vector<Literal> dfs_stack_;
778 
779  // Used to limit the work done by ComputeTransitiveReduction() and
780  // TransformIntoMaxCliques().
781  int64 work_done_in_mark_descendants_ = 0;
782 
783  // Filled by DetectEquivalences().
784  bool is_dag_ = false;
785  std::vector<LiteralIndex> reverse_topological_order_;
788 
789  // For in-processing and removing variables.
790  std::vector<Literal> direct_implications_;
791  std::vector<Literal> direct_implications_of_negated_literal_;
792  gtl::ITIVector<LiteralIndex, bool> in_direct_implications_;
794  gtl::ITIVector<LiteralIndex, int> estimated_sizes_;
795 
796  // For RemoveFixedVariables().
797  int num_processed_fixed_variables_ = 0;
798 
799  DISALLOW_COPY_AND_ASSIGN(BinaryImplicationGraph);
800 };
801 
802 } // namespace sat
803 } // namespace operations_research
804 
805 #endif // OR_TOOLS_SAT_CLAUSE_H_
operations_research::sat::BinaryImplicationGraph::IsEmpty
bool IsEmpty()
Definition: clause.h:481
operations_research::sat::Trail
Definition: sat_base.h:233
operations_research::sat::BinaryImplicationGraph::Propagate
bool Propagate(Trail *trail) final
Definition: clause.cc:729
operations_research::sat::LiteralWatchers
Definition: clause.h:159
var
IntVar * var
Definition: expr_array.cc:1858
operations_research::sat::VariablesAssignment::LiteralIsTrue
bool LiteralIsTrue(Literal literal) const
Definition: sat_base.h:150
operations_research::sat::BinaryImplicationGraph::MinimizeConflictWithReachability
void MinimizeConflictWithReachability(std::vector< Literal > *c)
Definition: clause.cc:753
operations_research::sat::ClauseInfo::activity
double activity
Definition: clause.h:143
operations_research::StatsGroup
Definition: stats.h:131
integral_types.h
operations_research::sat::BinaryImplicationGraph::~BinaryImplicationGraph
~BinaryImplicationGraph() override
Definition: clause.h:465
operations_research::sat::SatClause::DebugString
std::string DebugString() const
Definition: clause.cc:1838
time_limit.h
IF_STATS_ENABLED
#define IF_STATS_ENABLED(instructions)
Definition: stats.h:430
operations_research::SparseBitset::size
IntegerType size() const
Definition: bitset.h:771
operations_research::sat::SatClause::SecondLiteral
Literal SecondLiteral() const
Definition: clause.h:74
operations_research::sat::BinaryImplicationGraph::DetectEquivalences
bool DetectEquivalences(bool log_info=false)
Definition: clause.cc:1122
operations_research::sat::LiteralWatchers::NextClauseToMinimize
SatClause * NextClauseToMinimize()
Definition: clause.h:245
operations_research::sat::kNoLiteralIndex
const LiteralIndex kNoLiteralIndex(-1)
operations_research::sat::BinaryImplicationGraph::BinaryImplicationGraph
BinaryImplicationGraph(Model *model)
Definition: clause.h:457
operations_research::sat::BinaryImplicationGraph::num_propagations
int64 num_propagations() const
Definition: clause.h:590
operations_research::sat::BinaryImplicationGraph::ComputeTransitiveReduction
bool ComputeTransitiveReduction(bool log_info=false)
Definition: clause.cc:1309
operations_research::sat::LiteralWatchers::num_clauses
int64 num_clauses() const
Definition: clause.h:209
operations_research::sat::LiteralWatchers::Reason
absl::Span< const Literal > Reason(const Trail &trail, int trail_index) const final
Definition: clause.cc:191
operations_research::sat::ClauseInfo::lbd
int32 lbd
Definition: clause.h:144
operations_research::sat::LiteralWatchers::Detach
void Detach(SatClause *clause)
Definition: clause.cc:300
operations_research::sat::LiteralWatchers::WatcherListOnFalse
const std::vector< Watcher > & WatcherListOnFalse(Literal false_literal) const
Definition: clause.h:311
operations_research::sat::BinaryImplicationGraph::MinimizeConflictFirst
void MinimizeConflictFirst(const Trail &trail, std::vector< Literal > *c, SparseBitset< BooleanVariable > *marked)
Definition: clause.cc:830
operations_research::sat::SatClause::IsAttached
bool IsAttached() const
Definition: clause.h:107
operations_research::sat::VariablesAssignment
Definition: sat_base.h:122
operations_research::sat::BinaryImplicationGraph::IsRedundant
bool IsRedundant(Literal l) const
Definition: clause.h:605
operations_research::sat::BinaryClause::operator==
bool operator==(BinaryClause o) const
Definition: clause.h:376
operations_research::sat::BinaryImplicationGraph::num_inspections
int64 num_inspections() const
Definition: clause.h:593
operations_research::sat::BinaryClauseManager::Add
bool Add(BinaryClause c)
Definition: clause.h:390
operations_research::sat::LiteralWatchers::Attach
void Attach(SatClause *clause, Trail *trail)
Definition: clause.cc:273
operations_research::sat::BinaryImplicationGraph::DirectImplicationsEstimatedSize
int DirectImplicationsEstimatedSize(Literal literal) const
Definition: clause.h:678
model.h
operations_research::sat::BinaryImplicationGraph::num_implications
int64 num_implications() const
Definition: clause.h:620
operations_research::sat::LiteralWatchers::InprocessingRemoveClause
void InprocessingRemoveClause(SatClause *clause)
Definition: clause.cc:357
macros.h
operations_research::sat::BinaryImplicationGraph::ExtractAllBinaryClauses
void ExtractAllBinaryClauses(Output *out) const
Definition: clause.h:631
operations_research
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Definition: dense_doubly_linked_list.h:21
operations_research::sat::BinaryClauseManager
Definition: clause.h:383
operations_research::sat::LiteralWatchers::InprocessingFixLiteral
ABSL_MUST_USE_RESULT bool InprocessingFixLiteral(Literal true_literal)
Definition: clause.cc:338
operations_research::sat::LiteralWatchers::mutable_clauses_info
absl::flat_hash_map< SatClause *, ClauseInfo > * mutable_clauses_info()
Definition: clause.h:222
operations_research::sat::BinaryClause
Definition: clause.h:374
operations_research::sat::BinaryClause::operator!=
bool operator!=(BinaryClause o) const
Definition: clause.h:377
operations_research::sat::BinaryImplicationGraph::num_literals_removed
int64 num_literals_removed() const
Definition: clause.h:597
operations_research::sat::ClauseInfo
Definition: clause.h:142
operations_research::sat::LiteralWatchers::SetDratProofHandler
void SetDratProofHandler(DratProofHandler *drat_proof_handler)
Definition: clause.h:238
int64
int64_t int64
Definition: integral_types.h:34
operations_research::sat::BinaryImplicationGraph::AddImplication
void AddImplication(Literal a, Literal b)
Definition: clause.h:486
operations_research::sat::LiteralWatchers::Watcher
Definition: clause.h:286
gtl::ITIVector::size
size_type size() const
Definition: int_type_indexed_vector.h:146
operations_research::sat::BinaryImplicationGraph::MinimizeConflictExperimental
void MinimizeConflictExperimental(const Trail &trail, std::vector< Literal > *c)
Definition: clause.cc:910
gtl::ITIVector::empty
bool empty() const
Definition: int_type_indexed_vector.h:155
operations_research::sat::BinaryImplicationGraph::AddBinaryClauseDuringSearch
bool AddBinaryClauseDuringSearch(Literal a, Literal b)
Definition: clause.cc:507
operations_research::sat::Model
Class that owns everything related to a particular optimization model.
Definition: sat/model.h:38
operations_research::sat::BinaryImplicationGraph::IsRemoved
bool IsRemoved(Literal l) const
Definition: clause.h:693
operations_research::sat::BinaryImplicationGraph::ChangeReason
void ChangeReason(int trail_index, Literal new_reason)
Definition: clause.h:659
random_engine.h
operations_research::sat::LiteralWatchers::ReasonClause
SatClause * ReasonClause(int trail_index) const
Definition: clause.cc:196
operations_research::sat::SatClause::RemoveFixedLiteralsAndTestIfTrue
bool RemoveFixedLiteralsAndTestIfTrue(const VariablesAssignment &assignment)
Definition: clause.cc:1807
operations_research::sat::LiteralWatchers::LazyDetach
void LazyDetach(SatClause *clause)
Definition: clause.cc:293
sat_base.h
int32
int int32
Definition: integral_types.h:33
drat_proof_handler.h
operations_research::sat::BinaryImplicationGraph::Implications
const absl::InlinedVector< Literal, 6 > & Implications(Literal l) const
Definition: clause.h:552
operations_research::sat::Trail::ChangeReason
void ChangeReason(int trail_index, int propagator_id)
Definition: sat_base.h:335
operations_research::sat::DratProofHandler
Definition: drat_proof_handler.h:40
operations_research::sat::LiteralWatchers::DeleteRemovedClauses
void DeleteRemovedClauses()
Definition: clause.cc:453
operations_research::sat::Literal
Definition: sat_base.h:64
operations_research::sat::LiteralWatchers::~LiteralWatchers
~LiteralWatchers() override
Definition: clause.cc:63
stats.h
operations_research::sat::BinaryImplicationGraph::RemoveBooleanVariable
void RemoveBooleanVariable(BooleanVariable var, std::deque< std::vector< Literal >> *postsolve_clauses)
Definition: clause.cc:1734
a
int64 a
Definition: constraint_solver/table.cc:42
operations_research::sat::BinaryImplicationGraph::AddBinaryClause
void AddBinaryClause(Literal a, Literal b)
Definition: clause.cc:490
operations_research::sat::LiteralWatchers::ResetToMinimizeIndex
void ResetToMinimizeIndex()
Definition: clause.h:256
operations_research::sat::BinaryImplicationGraph::NumImplicationOnVariableRemoval
int64 NumImplicationOnVariableRemoval(BooleanVariable var)
Definition: clause.cc:1714
operations_research::sat::Literal::Negated
Literal Negated() const
Definition: sat_base.h:91
sat_parameters.pb.h
operations_research::sat::SatClause
Definition: clause.h:50
operations_research::sat::LiteralWatchers::num_inspected_clauses
int64 num_inspected_clauses() const
Definition: clause.h:227
operations_research::sat::ClauseInfo::protected_during_next_cleanup
bool protected_during_next_cleanup
Definition: clause.h:145
int_type.h
operations_research::sat::BinaryImplicationGraph::Reason
absl::Span< const Literal > Reason(const Trail &trail, int trail_index) const final
Definition: clause.cc:741
operations_research::sat::LiteralWatchers::AllClausesInCreationOrder
const std::vector< SatClause * > & AllClausesInCreationOrder() const
Definition: clause.h:210
operations_research::sat::LiteralWatchers::InprocessingAddClause
SatClause * InprocessingAddClause(absl::Span< const Literal > new_clause)
Definition: clause.cc:414
operations_research::TimeLimit
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
Definition: time_limit.h:105
operations_research::sat::LiteralWatchers::DetachAllClauses
void DetachAllClauses()
Definition: clause.cc:310
operations_research::sat::BinaryClauseManager::ClearNewlyAdded
void ClearNewlyAdded()
Definition: clause.h:403
operations_research::sat::LiteralWatchers::Watcher::start_index
int32 start_index
Definition: clause.h:304
operations_research::sat::BinaryImplicationGraph::TransformIntoMaxCliques
bool TransformIntoMaxCliques(std::vector< std::vector< Literal >> *at_most_ones, int64 max_num_explored_nodes=1e8)
Definition: clause.cc:1498
operations_research::sat::LiteralWatchers::num_watched_clauses
int64 num_watched_clauses() const
Definition: clause.h:236
operations_research::sat::SatPropagator::propagator_id_
int propagator_id_
Definition: sat_base.h:505
operations_research::sat::LiteralWatchers::Watcher::Watcher
Watcher()
Definition: clause.h:287
int_type_indexed_vector.h
operations_research::sat::LiteralWatchers::AddClause
bool AddClause(absl::Span< const Literal > literals, Trail *trail)
Definition: clause.cc:204
operations_research::sat::LiteralWatchers::AddRemovableClause
SatClause * AddRemovableClause(const std::vector< Literal > &literals, Trail *trail)
Definition: clause.cc:211
operations_research::sat::Trail::Assignment
const VariablesAssignment & Assignment() const
Definition: sat_base.h:380
operations_research::sat::LiteralWatchers::literal_size
int64 literal_size() const
Definition: clause.h:233
operations_research::sat::BinaryImplicationGraph
Definition: clause.h:455
operations_research::sat::LiteralWatchers::Propagate
bool Propagate(Trail *trail) final
Definition: clause.cc:182
operations_research::sat::BinaryClauseManager::newly_added
const std::vector< BinaryClause > & newly_added() const
Definition: clause.h:402
operations_research::sat::BinaryImplicationGraph::MinimizeConflictFirstWithTransitiveReduction
void MinimizeConflictFirstWithTransitiveReduction(const Trail &trail, std::vector< Literal > *c, SparseBitset< BooleanVariable > *marked, random_engine_t *random)
Definition: clause.cc:848
operations_research::sat::LiteralWatchers::Watcher::Watcher
Watcher(SatClause *c, Literal b, int i=2)
Definition: clause.h:288
operations_research::sat::SatClause::PropagatedLiteral
Literal PropagatedLiteral() const
Definition: clause.h:79
operations_research::sat::Trail::RegisterPropagator
void RegisterPropagator(SatPropagator *propagator)
Definition: sat_base.h:550
operations_research::sat::LiteralWatchers::AttachAllClauses
void AttachAllClauses()
Definition: clause.cc:321
operations_research::sat::LiteralWatchers::Watcher::clause
SatClause * clause
Definition: clause.h:306
operations_research::sat::BinaryImplicationGraph::AddAtMostOne
ABSL_MUST_USE_RESULT bool AddAtMostOne(absl::Span< const Literal > at_most_one)
Definition: clause.cc:530
operations_research::sat::SatClause::IsSatisfied
bool IsSatisfied(const VariablesAssignment &assignment) const
Definition: clause.cc:1831
operations_research::sat::SatClause::FirstLiteral
Literal FirstLiteral() const
Definition: clause.h:73
operations_research::sat::LiteralWatchers::Watcher::blocking_literal
Literal blocking_literal
Definition: clause.h:293
operations_research::sat::BinaryImplicationGraph::CleanupAllRemovedVariables
void CleanupAllRemovedVariables()
Definition: clause.cc:1777
operations_research::sat::LiteralWatchers::InprocessingRewriteClause
ABSL_MUST_USE_RESULT bool InprocessingRewriteClause(SatClause *clause, absl::Span< const Literal > new_clause)
Definition: clause.cc:366
model
GRBmodel * model
Definition: gurobi_interface.cc:195
operations_research::sat::SatClause::end
const Literal *const end() const
Definition: clause.h:69
operations_research::sat::LiteralWatchers::LiteralWatchers
LiteralWatchers(Model *model)
Definition: clause.cc:52
operations_research::sat::BinaryImplicationGraph::SetDratProofHandler
void SetDratProofHandler(DratProofHandler *drat_proof_handler)
Definition: clause.h:652
operations_research::sat::SatPropagator
Definition: sat_base.h:444
operations_research::sat::LiteralWatchers::num_inspected_clause_literals
int64 num_inspected_clause_literals() const
Definition: clause.h:228
operations_research::sat::SatClause::PropagationReason
absl::Span< const Literal > PropagationReason() const
Definition: clause.h:84
operations_research::sat::BinaryImplicationGraph::literal_size
int64 literal_size() const
Definition: clause.h:621
operations_research::sat::LiteralWatchers::num_removable_clauses
int64 num_removable_clauses() const
Definition: clause.h:221
operations_research::sat::BinaryImplicationGraph::DirectImplications
const std::vector< Literal > & DirectImplications(Literal literal)
Definition: clause.cc:1646
operations_research::sat::BinaryImplicationGraph::Resize
void Resize(int num_variables)
Definition: clause.cc:476
operations_research::StatsGroup::StatString
std::string StatString() const
Definition: stats.cc:71
hash.h
operations_research::sat::BinaryClause::BinaryClause
BinaryClause(Literal _a, Literal _b)
Definition: clause.h:375
operations_research::sat::BinaryImplicationGraph::IsDag
bool IsDag() const
Definition: clause.h:541
b
int64 b
Definition: constraint_solver/table.cc:43
operations_research::sat::BinaryClause::b
Literal b
Definition: clause.h:379
DISALLOW_COPY_AND_ASSIGN
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:29
operations_research::sat::BinaryImplicationGraph::FindFailedLiteralAroundVar
bool FindFailedLiteralAroundVar(BooleanVariable var, bool *is_unsat)
Definition: clause.cc:1689
operations_research::sat::SatClause::empty
int empty() const
Definition: clause.h:65
operations_research::sat::BinaryClauseManager::NumClauses
int NumClauses() const
Definition: clause.h:386
operations_research::sat::LiteralWatchers::IsRemovable
bool IsRemovable(SatClause *const clause) const
Definition: clause.h:218
gtl::ITIVector
Definition: int_type_indexed_vector.h:76
operations_research::sat::SatClause::begin
const Literal *const begin() const
Definition: clause.h:68
operations_research::sat::BinaryClause::a
Literal a
Definition: clause.h:378
operations_research::sat::Literal::SignedValue
int SignedValue() const
Definition: sat_base.h:87
operations_research::sat::SatClause::AsSpan
absl::Span< const Literal > AsSpan() const
Definition: clause.h:89
operations_research::sat::BinaryImplicationGraph::num_redundant_implications
int64 num_redundant_implications() const
Definition: clause.h:612
operations_research::sat::BinaryImplicationGraph::ReverseTopologicalOrder
const std::vector< LiteralIndex > & ReverseTopologicalOrder() const
Definition: clause.h:545
operations_research::SparseBitset< LiteralIndex >
literal
Literal literal
Definition: optimization.cc:84
operations_research::sat::LiteralWatchers::CleanUpWatchers
void CleanUpWatchers()
Definition: clause.cc:440
operations_research::sat::LiteralWatchers::Resize
void Resize(int num_variables)
Definition: clause.cc:68
operations_research::sat::Literal::Index
LiteralIndex Index() const
Definition: sat_base.h:84
operations_research::sat::SatClause::Create
static SatClause * Create(absl::Span< const Literal > literals)
Definition: clause.cc:1794
operations_research::sat::BinaryClauseManager::BinaryClauseManager
BinaryClauseManager()
Definition: clause.h:385
operations_research::sat::BinaryImplicationGraph::RemoveFixedVariables
void RemoveFixedVariables()
Definition: clause.cc:961
operations_research::sat::BinaryImplicationGraph::RepresentativeOf
Literal RepresentativeOf(Literal l) const
Definition: clause.h:559
bitset.h
operations_research::random_engine_t
std::mt19937 random_engine_t
Definition: random_engine.h:23
operations_research::sat::BinaryImplicationGraph::num_redundant_literals
int64 num_redundant_literals() const
Definition: clause.h:606
operations_research::sat::SatClause::size
int size() const
Definition: clause.h:64
operations_research::sat::BinaryImplicationGraph::num_minimization
int64 num_minimization() const
Definition: clause.h:596
gtl::ContainsKey
bool ContainsKey(const Collection &collection, const Key &key)
Definition: map_util.h:170