Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
sat_solver.h
Go to the documentation of this file.
1// Copyright 2010-2024 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 implements a SAT solver.
15// see http://en.wikipedia.org/wiki/Boolean_satisfiability_problem
16// for more detail.
17// TODO(user): Expand.
18
19#ifndef OR_TOOLS_SAT_SAT_SOLVER_H_
20#define OR_TOOLS_SAT_SAT_SOLVER_H_
21
22#include <cstdint>
23#include <functional>
24#include <limits>
25#include <memory>
26#include <ostream>
27#include <string>
28#include <utility>
29#include <vector>
30
31#include "absl/base/attributes.h"
32#include "absl/container/flat_hash_map.h"
33#include "absl/log/check.h"
34#include "absl/strings/string_view.h"
35#include "absl/types/span.h"
36#include "ortools/base/hash.h"
38#include "ortools/base/timer.h"
39#include "ortools/base/types.h"
40#include "ortools/sat/clause.h"
42#include "ortools/sat/model.h"
44#include "ortools/sat/restart.h"
47#include "ortools/sat/sat_parameters.pb.h"
48#include "ortools/util/bitset.h"
50#include "ortools/util/stats.h"
53
54namespace operations_research {
55namespace sat {
56
57// A constant used by the EnqueueDecision*() API.
58const int kUnsatTrailIndex = -1;
59
60// The main SAT solver.
61// It currently implements the CDCL algorithm. See
62// http://en.wikipedia.org/wiki/Conflict_Driven_Clause_Learning
63class SatSolver {
64 public:
65 SatSolver();
66 explicit SatSolver(Model* model);
67
68 // This type is neither copyable nor movable.
69 SatSolver(const SatSolver&) = delete;
70 SatSolver& operator=(const SatSolver&) = delete;
71
72 ~SatSolver();
73
74 // TODO(user): Remove. This is temporary for accessing the model deep within
75 // some old code that didn't use the Model object.
76 Model* model() { return model_; }
77
78 // Parameters management. Note that calling SetParameters() will reset the
79 // value of many heuristics. For instance:
80 // - The restart strategy will be reinitialized.
81 // - The random seed and random generator will be reset to the value given in
82 // parameters.
83 // - The global TimeLimit singleton will be reset and time will be
84 // counted from this call.
85 void SetParameters(const SatParameters& parameters);
86 const SatParameters& parameters() const;
87
88 // Increases the number of variables of the current problem.
89 //
90 // TODO(user): Rename to IncreaseNumVariablesTo() until we support removing
91 // variables...
92 void SetNumVariables(int num_variables);
93 int NumVariables() const { return num_variables_.value(); }
94 BooleanVariable NewBooleanVariable() {
95 const int num_vars = NumVariables();
96
97 // We need to be able to encode the variable as a literal.
98 CHECK_LT(2 * num_vars, std::numeric_limits<int32_t>::max());
99 SetNumVariables(num_vars + 1);
100 return BooleanVariable(num_vars);
101 }
102
103 // Fixes a variable so that the given literal is true. This can be used to
104 // solve a subproblem where some variables are fixed. Note that it is more
105 // efficient to add such unit clause before all the others.
106 // Returns false if the problem is detected to be UNSAT.
107 ABSL_MUST_USE_RESULT bool AddUnitClause(Literal true_literal);
108
109 // Same as AddProblemClause() below, but for small clauses.
112
113 // Adds a clause to the problem. Returns false if the problem is detected to
114 // be UNSAT.
115 // If is_safe is false, we will do some basic presolving like removing
116 // duplicate literals.
117 //
118 // TODO(user): Rename this to AddClause(), also get rid of the specialized
119 // AddUnitClause(), AddBinaryClause() and AddTernaryClause() since they
120 // just end up calling this?
121 bool AddProblemClause(absl::Span<const Literal> literals,
122 bool is_safe = true);
123
124 // Adds a pseudo-Boolean constraint to the problem. Returns false if the
125 // problem is detected to be UNSAT. If the constraint is always true, this
126 // detects it and does nothing.
127 //
128 // Note(user): There is an optimization if the same constraint is added
129 // consecutively (even if the bounds are different). This is particularly
130 // useful for an optimization problem when we want to constrain the objective
131 // of the problem more and more. Just re-adding such constraint is relatively
132 // efficient.
133 //
134 // OVERFLOW: The sum of the absolute value of all the coefficients
135 // in the constraint must not overflow. This is currently CHECKed().
136 // TODO(user): Instead of failing, implement an error handling code.
137 bool AddLinearConstraint(bool use_lower_bound, Coefficient lower_bound,
138 bool use_upper_bound, Coefficient upper_bound,
139 std::vector<LiteralWithCoeff>* cst);
140
141 // Returns true if the model is UNSAT. Note that currently the status is
142 // "sticky" and once this happen, nothing else can be done with the solver.
143 //
144 // Thanks to this function, a client can safely ignore the return value of any
145 // Add*() functions. If one of them return false, then ModelIsUnsat() will
146 // return true.
147 bool ModelIsUnsat() const { return model_is_unsat_; }
148
149 // TODO(user): remove this function.
150 bool IsModelUnsat() const { return model_is_unsat_; } // DEPRECATED
151
152 // Adds and registers the given propagator with the sat solver. Note that
153 // during propagation, they will be called in the order they were added.
154 void AddPropagator(SatPropagator* propagator);
155 void AddLastPropagator(SatPropagator* propagator);
156 void TakePropagatorOwnership(std::unique_ptr<SatPropagator> propagator) {
157 owned_propagators_.push_back(std::move(propagator));
158 }
159
160 // Wrapper around the same functions in SatDecisionPolicy.
161 //
162 // TODO(user): Clean this up by making clients directly talk to
163 // SatDecisionPolicy.
167 std::vector<std::pair<Literal, float>> AllPreferences() const {
168 return decision_policy_->AllPreferences();
169 }
171 return decision_policy_->ResetDecisionHeuristic();
172 }
173
174 // Solves the problem and returns its status.
175 // An empty problem is considered to be SAT.
176 //
177 // Note that the conflict limit applies only to this function and starts
178 // counting from the time it is called.
179 //
180 // This will restart from the current solver configuration. If a previous call
181 // to Solve() was interrupted by a conflict or time limit, calling this again
182 // will resume the search exactly as it would have continued.
183 //
184 // Note that this will use the TimeLimit singleton, so the time limit
185 // will be counted since the last time TimeLimit was reset, not from
186 // the start of this function.
193 Status Solve();
194
195 // Same as Solve(), but with a given time limit. Note that this will not
196 // update the TimeLimit singleton, but only the passed object instead.
198
199 // Simple interface to solve a problem under the given assumptions. This
200 // simply ask the solver to solve a problem given a set of variables fixed to
201 // a given value (the assumptions). Compared to simply calling AddUnitClause()
202 // and fixing the variables once and for all, this allow to backtrack over the
203 // assumptions and thus exploit the incrementally between subsequent solves.
204 //
205 // This function backtrack over all the current decision, tries to enqueue the
206 // given assumptions, sets the assumption level accordingly and finally calls
207 // Solve().
208 //
209 // If, given these assumptions, the model is UNSAT, this returns the
210 // ASSUMPTIONS_UNSAT status. INFEASIBLE is reserved for the case where the
211 // model is proven to be unsat without any assumptions.
212 //
213 // If ASSUMPTIONS_UNSAT is returned, it is possible to get a "core" of unsat
214 // assumptions by calling GetLastIncompatibleDecisions().
216 const std::vector<Literal>& assumptions,
217 int64_t max_number_of_conflicts = -1);
218
219 // Changes the assumption level. All the decisions below this level will be
220 // treated as assumptions by the next Solve(). Note that this may impact some
221 // heuristics, like the LBD value of a clause.
222 void SetAssumptionLevel(int assumption_level);
223
224 // Returns the current assumption level. Note that if a solve was done since
225 // the last SetAssumptionLevel(), then the returned level may be lower than
226 // the one that was set. This is because some assumptions may now be
227 // consequences of others before them due to the newly learned clauses.
228 int AssumptionLevel() const { return assumption_level_; }
229
230 // This can be called just after SolveWithAssumptions() returned
231 // ASSUMPTION_UNSAT or after EnqueueDecisionAndBacktrackOnConflict() leaded
232 // to a conflict. It returns a subsequence (in the correct order) of the
233 // previously enqueued decisions that cannot be taken together without making
234 // the problem UNSAT.
235 std::vector<Literal> GetLastIncompatibleDecisions();
236
237 // Advanced usage. The next 3 functions allow to drive the search from outside
238 // the solver.
239
240 // Takes a new decision (the given true_literal must be unassigned) and
241 // propagates it. Returns the trail index of the first newly propagated
242 // literal. If there is a conflict and the problem is detected to be UNSAT,
243 // returns kUnsatTrailIndex.
244 //
245 // Important: In the presence of assumptions, this also returns
246 // kUnsatTrailIndex on ASSUMPTION_UNSAT. One can know the difference with
247 // IsModelUnsat().
248 //
249 // A client can determine if there is a conflict by checking if the
250 // CurrentDecisionLevel() was increased by 1 or not.
251 //
252 // If there is a conflict, the given decision is not applied and:
253 // - The conflict is learned.
254 // - The decisions are potentially backtracked to the first decision that
255 // propagates more variables because of the newly learned conflict.
256 // - The returned value is equal to trail_->Index() after this backtracking
257 // and just before the new propagation (due to the conflict) which is also
258 // performed by this function.
260
261 // This function starts by calling EnqueueDecisionAndBackjumpOnConflict(). If
262 // there is no conflict, it stops there. Otherwise, it tries to reapply all
263 // the decisions that were backjumped over until the first one that can't be
264 // taken because it is incompatible. Note that during this process, more
265 // conflicts may happen and the trail may be backtracked even further.
266 //
267 // In any case, the new decisions stack will be the largest valid "prefix"
268 // of the old stack. Note that decisions that are now consequence of the ones
269 // before them will no longer be decisions.
270 //
271 // Returns INFEASIBLE if the model was proven infeasible, ASSUMPTION_UNSAT if
272 // the current decision and the one we are trying to take are not compatible
273 // together and FEASIBLE if all decisions are taken.
274 //
275 // Note(user): This function can be called with an already assigned literal.
277 Literal true_literal, int* first_propagation_index = nullptr);
278
279 // Tries to enqueue the given decision and performs the propagation.
280 // Returns true if no conflict occurred. Otherwise, returns false and restores
281 // the solver to the state just before this was called.
282 //
283 // Note(user): With this function, the solver doesn't learn anything.
284 bool EnqueueDecisionIfNotConflicting(Literal true_literal);
285
286 // Restores the state to the given target decision level. The decision at that
287 // level and all its propagation will not be undone. But all the trail after
288 // this will be cleared. Calling this with 0 will revert all the decisions and
289 // only the fixed variables will be left on the trail.
290 void Backtrack(int target_level);
291
292 // Advanced usage. This is meant to restore the solver to a "proper" state
293 // after a solve was interrupted due to a limit reached.
294 //
295 // Without assumption (i.e. if AssumptionLevel() is 0), this will revert all
296 // decisions and make sure that all the fixed literals are propagated. In
297 // presence of assumptions, this will either backtrack to the assumption level
298 // or re-enqueue any assumptions that may have been backtracked over due to
299 // conflits resolution. In both cases, the propagation is finished.
300 //
301 // Note that this may prove the model to be UNSAT or ASSUMPTION_UNSAT in which
302 // case it will return false.
304
305 // Advanced usage. Finish the progation if it was interrupted. Note that this
306 // might run into conflict and will propagate again until a fixed point is
307 // reached or the model was proven UNSAT. Returns IsModelUnsat().
308 ABSL_MUST_USE_RESULT bool FinishPropagation();
309
310 // Like Backtrack(0) but make sure the propagation is finished and return
311 // false if unsat was detected. This also removes any assumptions level.
312 ABSL_MUST_USE_RESULT bool ResetToLevelZero();
313
314 // Changes the assumptions level and the current solver assumptions. Returns
315 // false if the model is UNSAT or ASSUMPTION_UNSAT, true otherwise.
316 //
317 // This uses the "new" assumptions handling, where all assumptions are
318 // enqueued at once at decision level 1 before we start to propagate. This has
319 // many advantages. In particular, because we propagate with the binary
320 // implications first, if we ever have assumption => not(other_assumptions) we
321 // are guaranteed to find it and returns a core of size 2.
322 //
323 // Paper: "Speeding Up Assumption-Based SAT", Randy Hickey and Fahiem Bacchus
324 // http://www.maxhs.org/docs/Hickey-Bacchus2019_Chapter_SpeedingUpAssumption-BasedSAT.pdf
325 bool ResetWithGivenAssumptions(const std::vector<Literal>& assumptions);
326
327 // Advanced usage. If the decision level is smaller than the assumption level,
328 // this will try to reapply all assumptions. Returns true if this was doable,
329 // otherwise returns false in which case the model is either UNSAT or
330 // ASSUMPTION_UNSAT.
332
333 // Helper functions to get the correct status when one of the functions above
334 // returns false.
337 }
338
339 // Extract the current problem clauses. The Output type must support the two
340 // functions:
341 // - void AddBinaryClause(Literal a, Literal b);
342 // - void AddClause(absl::Span<const Literal> clause);
343 //
344 // TODO(user): also copy the removable clauses?
345 template <typename Output>
346 void ExtractClauses(Output* out) {
347 CHECK(!IsModelUnsat());
348 Backtrack(0);
349 if (!FinishPropagation()) return;
350
351 // It is important to process the newly fixed variables, so they are not
352 // present in the clauses we export.
353 if (num_processed_fixed_variables_ < trail_->Index()) {
355 }
356 clauses_propagator_->DeleteRemovedClauses();
357
358 // Note(user): Putting the binary clauses first help because the presolver
359 // currently process the clauses in order.
360 out->SetNumVariables(NumVariables());
361 binary_implication_graph_->ExtractAllBinaryClauses(out);
362 for (SatClause* clause : clauses_propagator_->AllClausesInCreationOrder()) {
363 if (!clauses_propagator_->IsRemovable(clause)) {
364 out->AddClause(clause->AsSpan());
365 }
366 }
367 }
368
369 // Functions to manage the set of learned binary clauses.
370 // Only clauses added/learned when TrackBinaryClause() is true are managed.
371 void TrackBinaryClauses(bool value) { track_binary_clauses_ = value; }
372 bool AddBinaryClauses(const std::vector<BinaryClause>& clauses);
373 const std::vector<BinaryClause>& NewlyAddedBinaryClauses();
375
376 struct Decision {
377 Decision() = default;
379 int trail_index = 0;
381 };
382
383 // Note that the Decisions() vector is always of size NumVariables(), and that
384 // only the first CurrentDecisionLevel() entries have a meaning.
385 const std::vector<Decision>& Decisions() const { return decisions_; }
386 int CurrentDecisionLevel() const { return current_decision_level_; }
387 const Trail& LiteralTrail() const { return *trail_; }
388 const VariablesAssignment& Assignment() const { return trail_->Assignment(); }
389
390 // Some statistics since the creation of the solver.
391 int64_t num_branches() const;
392 int64_t num_failures() const;
393 int64_t num_propagations() const;
394 int64_t num_backtracks() const;
395
396 // Note that we count the number of backtrack to level zero from a positive
397 // level. Those can corresponds to actual restarts, or conflicts that learn
398 // unit clauses or any other reason that trigger such backtrack.
399 int64_t num_restarts() const;
400
401 // Access to all counters.
402 // Tracks various information about the solver progress.
403 struct Counters {
404 int64_t num_branches = 0;
405 int64_t num_failures = 0;
406 int64_t num_restarts = 0;
407 int64_t num_backtracks = 0;
408
409 // Minimization stats.
410 int64_t num_minimizations = 0;
412
413 // PB constraints.
415
416 // Clause learning /deletion stats.
420
421 // TryToMinimizeClause() stats.
428 };
429 Counters counters() const { return counters_; }
430
431 // A deterministic number that should be correlated with the time spent in
432 // the Solve() function. The order of magnitude should be close to the time
433 // in seconds.
434 double deterministic_time() const;
435
436 // Only used for debugging. Save the current assignment in debug_assignment_.
437 // The idea is that if we know that a given assignment is satisfiable, then
438 // all the learned clauses or PB constraints must be satisfiable by it. In
439 // debug mode, and after this is called, all the learned clauses are tested to
440 // satisfy this saved assignment.
441 void SaveDebugAssignment();
442 void LoadDebugSolution(const std::vector<Literal>& solution);
443
444 void SetDratProofHandler(DratProofHandler* drat_proof_handler) {
445 drat_proof_handler_ = drat_proof_handler;
446 clauses_propagator_->SetDratProofHandler(drat_proof_handler_);
447 binary_implication_graph_->SetDratProofHandler(drat_proof_handler_);
448 }
449
450 // This function is here to deal with the case where a SAT/CP model is found
451 // to be trivially UNSAT while the user is constructing the model. Instead of
452 // having to test the status of all the lines adding a constraint, one can
453 // just check if the solver is not UNSAT once the model is constructed. Note
454 // that we usually log a warning on the first constraint that caused a
455 // "trival" unsatisfiability.
456 void NotifyThatModelIsUnsat() { model_is_unsat_ = true; }
457
458 // Adds a clause at any level of the tree and propagate any new deductions.
459 // Returns false if the model becomes UNSAT. Important: We currently do not
460 // support adding a clause that is already falsified at a positive decision
461 // level. Doing that will cause a check fail.
462 //
463 // TODO(user): Backjump and propagate on a falsified clause? this is currently
464 // not needed.
465 bool AddClauseDuringSearch(absl::Span<const Literal> literals);
466
467 // Performs propagation of the recently enqueued elements.
468 // Mainly visible for testing.
469 ABSL_MUST_USE_RESULT bool Propagate();
470
471 bool MinimizeByPropagation(double dtime);
472
473 // Advance the given time limit with all the deterministic time that was
474 // elapsed since last call.
476 const double current = deterministic_time();
478 current - deterministic_time_at_last_advanced_time_limit_);
479 deterministic_time_at_last_advanced_time_limit_ = current;
480 }
481
482 // Simplifies the problem when new variables are assigned at level 0.
484
485 int64_t NumFixedVariables() const {
486 if (!decisions_.empty()) return decisions_[0].trail_index;
487 CHECK_EQ(CurrentDecisionLevel(), 0);
488 return trail_->Index();
489 }
490
491 // Hack to allow to temporarily disable logging if it is enabled.
492 SolverLogger* mutable_logger() { return logger_; }
493
494 // Processes the current conflict from trail->FailingClause().
495 //
496 // This learns the conflict, backtracks, enqueues the consequence of the
497 // learned conflict and return. When handling assumptions, this might return
498 // false without backtracking in case of ASSUMPTIONS_UNSAT. This is only
499 // exposed to allow processing a conflict detected outside normal propagation.
501
502 private:
503 // All Solve() functions end up calling this one.
504 Status SolveInternal(TimeLimit* time_limit, int64_t max_number_of_conflicts);
505
506 // Adds a binary clause to the BinaryImplicationGraph and to the
507 // BinaryClauseManager when track_binary_clauses_ is true.
508 void AddBinaryClauseInternal(Literal a, Literal b);
509
510 // See SaveDebugAssignment(). Note that these functions only consider the
511 // variables at the time the debug_assignment_ was saved. If new variables
512 // were added since that time, they will be considered unassigned.
513 bool ClauseIsValidUnderDebugAssignment(
514 absl::Span<const Literal> clause) const;
515 bool PBConstraintIsValidUnderDebugAssignment(
516 const std::vector<LiteralWithCoeff>& cst, Coefficient rhs) const;
517
518 // Logs the given status if parameters_.log_search_progress() is true.
519 // Also returns it.
520 Status StatusWithLog(Status status);
521
522 // Main function called from SolveWithAssumptions() or from Solve() with an
523 // assumption_level of 0 (meaning no assumptions).
524 Status SolveInternal(int assumption_level);
525
526 // Applies the previous decisions (which are still on decisions_), in order,
527 // starting from the one at the current decision level. Stops at the one at
528 // decisions_[level] or on the first decision already propagated to "false"
529 // and thus incompatible.
530 //
531 // Note that during this process, conflicts may arise which will lead to
532 // backjumps. In this case, we will simply keep reapplying decisions from the
533 // last one backtracked over and so on.
534 //
535 // Returns FEASIBLE if no conflict occurred, INFEASIBLE if the model was
536 // proven unsat and ASSUMPTION_UNSAT otherwise. In the last case the first non
537 // taken old decision will be propagated to false by the ones before.
538 //
539 // first_propagation_index will be filled with the trail index of the first
540 // newly propagated literal, or with -1 if INFEASIBLE is returned.
541 Status ReapplyDecisionsUpTo(int level,
542 int* first_propagation_index = nullptr);
543
544 // Returns false if the thread memory is over the limit.
545 bool IsMemoryLimitReached() const;
546
547 // Sets model_is_unsat_ to true and return false.
548 bool SetModelUnsat();
549
550 // Returns the decision level of a given variable.
551 int DecisionLevel(BooleanVariable var) const {
552 return trail_->Info(var).level;
553 }
554
555 // Returns the relevant pointer if the given variable was propagated by the
556 // constraint in question. This is used to bump the activity of the learned
557 // clauses or pb constraints.
558 SatClause* ReasonClauseOrNull(BooleanVariable var) const;
559 UpperBoundedLinearConstraint* ReasonPbConstraintOrNull(
560 BooleanVariable var) const;
561
562 // This does one step of a pseudo-Boolean resolution:
563 // - The variable var has been assigned to l at a given trail_index.
564 // - The reason for var propagates it to l.
565 // - The conflict propagates it to not(l)
566 // The goal of the operation is to combine the two constraints in order to
567 // have a new conflict at a lower trail_index.
568 //
569 // Returns true if the reason for var was a normal clause. In this case,
570 // the *slack is updated to its new value.
571 bool ResolvePBConflict(BooleanVariable var,
572 MutableUpperBoundedLinearConstraint* conflict,
573 Coefficient* slack);
574
575 // Returns true iff the clause is the reason for an assigned variable.
576 //
577 // TODO(user): With our current data structures, we could also return true
578 // for clauses that were just used as a reason (like just before an untrail).
579 // This may be beneficial, but should properly be defined so that we can
580 // have the same behavior if we change the implementation.
581 bool ClauseIsUsedAsReason(SatClause* clause) const {
582 const BooleanVariable var = clause->PropagatedLiteral().Variable();
583 return trail_->Info(var).trail_index < trail_->Index() &&
584 (*trail_)[trail_->Info(var).trail_index].Variable() == var &&
585 ReasonClauseOrNull(var) == clause;
586 }
587
588 // Add a problem clause. The clause is assumed to be "cleaned", that is no
589 // duplicate variables (not strictly required) and not empty.
590 bool AddProblemClauseInternal(absl::Span<const Literal> literals);
591
592 // This is used by all the Add*LinearConstraint() functions. It detects
593 // infeasible/trivial constraints or clause constraints and takes the proper
594 // action.
595 bool AddLinearConstraintInternal(const std::vector<LiteralWithCoeff>& cst,
596 Coefficient rhs, Coefficient max_value);
597
598 // Makes sure a pseudo boolean constraint is in canonical form.
599 void CanonicalizeLinear(std::vector<LiteralWithCoeff>* cst,
600 Coefficient* bound_shift, Coefficient* max_value);
601
602 // Adds a learned clause to the problem. This should be called after
603 // Backtrack(). The backtrack is such that after it is applied, all the
604 // literals of the learned close except one will be false. Thus the last one
605 // will be implied True. This function also Enqueue() the implied literal.
606 //
607 // Returns the LBD of the clause.
608 int AddLearnedClauseAndEnqueueUnitPropagation(
609 const std::vector<Literal>& literals, bool is_redundant);
610
611 // Creates a new decision which corresponds to setting the given literal to
612 // True and Enqueue() this change.
613 void EnqueueNewDecision(Literal literal);
614
615 // Returns true if everything has been propagated.
616 //
617 // TODO(user): This test is fast but not exhaustive, especially regarding the
618 // integer propagators. Fix.
619 bool PropagationIsDone() const;
620
621 // Update the propagators_ list with the relevant propagators.
622 void InitializePropagators();
623
624 // Output to the DRAT proof handler any newly fixed variables.
625 void ProcessNewlyFixedVariablesForDratProof();
626
627 // Returns the maximum trail_index of the literals in the given clause.
628 // All the literals must be assigned. Returns -1 if the clause is empty.
629 int ComputeMaxTrailIndex(absl::Span<const Literal> clause) const;
630
631 // Computes what is known as the first UIP (Unique implication point) conflict
632 // clause starting from the failing clause. For a definition of UIP and a
633 // comparison of the different possible conflict clause computation, see the
634 // reference below.
635 //
636 // The conflict will have only one literal at the highest decision level, and
637 // this literal will always be the first in the conflict vector.
638 //
639 // L Zhang, CF Madigan, MH Moskewicz, S Malik, "Efficient conflict driven
640 // learning in a boolean satisfiability solver" Proceedings of the 2001
641 // IEEE/ACM international conference on Computer-aided design, Pages 279-285.
642 // http://www.cs.tau.ac.il/~msagiv/courses/ATP/iccad2001_final.pdf
643 void ComputeFirstUIPConflict(
644 int max_trail_index, std::vector<Literal>* conflict,
645 std::vector<Literal>* reason_used_to_infer_the_conflict,
646 std::vector<SatClause*>* subsumed_clauses);
647
648 // Fills literals with all the literals in the reasons of the literals in the
649 // given input. The output vector will have no duplicates and will not contain
650 // the literals already present in the input.
651 void ComputeUnionOfReasons(const std::vector<Literal>& input,
652 std::vector<Literal>* literals);
653
654 // Do the full pseudo-Boolean constraint analysis. This calls multiple
655 // time ResolvePBConflict() on the current conflict until we have a conflict
656 // that allow us to propagate more at a lower decision level. This level
657 // is the one returned in backjump_level.
658 void ComputePBConflict(int max_trail_index, Coefficient initial_slack,
659 MutableUpperBoundedLinearConstraint* conflict,
660 int* backjump_level);
661
662 // Applies some heuristics to a conflict in order to minimize its size and/or
663 // replace literals by other literals from lower decision levels. The first
664 // function choose which one of the other functions to call depending on the
665 // parameters.
666 //
667 // Precondition: is_marked_ should be set to true for all the variables of
668 // the conflict. It can also contains false non-conflict variables that
669 // are implied by the negation of the 1-UIP conflict literal.
670 void MinimizeConflict(std::vector<Literal>* conflict);
671 void MinimizeConflictExperimental(std::vector<Literal>* conflict);
672 void MinimizeConflictSimple(std::vector<Literal>* conflict);
673 void MinimizeConflictRecursively(std::vector<Literal>* conflict);
674
675 // Utility function used by MinimizeConflictRecursively().
676 bool CanBeInferedFromConflictVariables(BooleanVariable variable);
677
678 // To be used in DCHECK(). Verifies some property of the conflict clause:
679 // - There is an unique literal with the highest decision level.
680 // - This literal appears in the first position.
681 // - All the other literals are of smaller decision level.
682 // - There is no literal with a decision level of zero.
683 bool IsConflictValid(const std::vector<Literal>& literals);
684
685 // Given the learned clause after a conflict, this computes the correct
686 // backtrack level to call Backtrack() with.
687 int ComputeBacktrackLevel(const std::vector<Literal>& literals);
688
689 // The LBD (Literal Blocks Distance) is the number of different decision
690 // levels at which the literals of the clause were assigned. Note that we
691 // ignore the decision level 0 whereas the definition in the paper below
692 // doesn't:
693 //
694 // G. Audemard, L. Simon, "Predicting Learnt Clauses Quality in Modern SAT
695 // Solver" in Twenty-first International Joint Conference on Artificial
696 // Intelligence (IJCAI'09), july 2009.
697 // http://www.ijcai.org/papers09/Papers/IJCAI09-074.pdf
698 //
699 // IMPORTANT: All the literals of the clause must be assigned, and the first
700 // literal must be of the highest decision level. This will be the case for
701 // all the reason clauses.
702 template <typename LiteralList>
703 int ComputeLbd(const LiteralList& literals);
704
705 // Checks if we need to reduce the number of learned clauses and do
706 // it if needed. Also updates the learned clause limit for the next cleanup.
707 void CleanClauseDatabaseIfNeeded();
708
709 // Activity management for clauses. This work the same way at the ones for
710 // variables, but with different parameters.
711 void BumpReasonActivities(const std::vector<Literal>& literals);
712 void BumpClauseActivity(SatClause* clause);
713 void RescaleClauseActivities(double scaling_factor);
714 void UpdateClauseActivityIncrement();
715
716 std::string DebugString(const SatClause& clause) const;
717 std::string StatusString(Status status) const;
718 std::string RunningStatisticsString() const;
719
720 // Marks as "non-deletable" all clauses that were used to infer the given
721 // variable. The variable must be currently assigned.
722 void KeepAllClauseUsedToInfer(BooleanVariable variable);
723 bool SubsumptionIsInteresting(BooleanVariable variable);
724
725 // Use propagation to try to minimize the given clause. This is really similar
726 // to MinimizeCoreWithPropagation(). It must be called when the current
727 // decision level is zero. Note that because this do a small tree search, it
728 // will impact the variable/clauses activities and may add new conflicts.
729 void TryToMinimizeClause(SatClause* clause);
730
731 // This is used by the old non-model constructor.
732 Model* model_;
733 std::unique_ptr<Model> owned_model_;
734
735 BooleanVariable num_variables_ = BooleanVariable(0);
736
737 // Internal propagators. We keep them here because we need more than the
738 // SatPropagator interface for them.
739 BinaryImplicationGraph* binary_implication_graph_;
740 ClauseManager* clauses_propagator_;
741 PbConstraints* pb_constraints_;
742
743 // Ordered list of propagators used by Propagate()/Untrail().
744 std::vector<SatPropagator*> propagators_;
745 std::vector<SatPropagator*> non_empty_propagators_;
746
747 // Ordered list of propagators added with AddPropagator().
748 std::vector<SatPropagator*> external_propagators_;
749 SatPropagator* last_propagator_ = nullptr;
750
751 // For the old, non-model interface.
752 std::vector<std::unique_ptr<SatPropagator>> owned_propagators_;
753
754 // Keep track of all binary clauses so they can be exported.
755 bool track_binary_clauses_;
756 BinaryClauseManager binary_clauses_;
757
758 // Pointers to singleton Model objects.
759 Trail* trail_;
760 TimeLimit* time_limit_;
761 SatParameters* parameters_;
762 RestartPolicy* restart_;
763 SatDecisionPolicy* decision_policy_;
764 SolverLogger* logger_;
765
766 // Used for debugging only. See SaveDebugAssignment().
767 VariablesAssignment debug_assignment_;
768
769 // The stack of decisions taken by the solver. They are stored in [0,
770 // current_decision_level_). The vector is of size num_variables_ so it can
771 // store all the decisions. This is done this way because in some situation we
772 // need to remember the previously taken decisions after a backtrack.
773 int current_decision_level_ = 0;
774 std::vector<Decision> decisions_;
775
776 // The trail index after the last Backtrack() call or before the last
777 // EnqueueNewDecision() call.
778 int last_decision_or_backtrack_trail_index_ = 0;
779
780 // The assumption level. See SolveWithAssumptions().
781 int assumption_level_ = 0;
782 std::vector<Literal> assumptions_;
783
784 // The size of the trail when ProcessNewlyFixedVariables() was last called.
785 // Note that the trail contains only fixed literals (that is literals of
786 // decision levels 0) before this point.
787 int num_processed_fixed_variables_ = 0;
788 double deterministic_time_of_last_fixed_variables_cleanup_ = 0.0;
789
790 // Used in ProcessNewlyFixedVariablesForDratProof().
791 int drat_num_processed_fixed_variables_ = 0;
792
793 Counters counters_;
794
795 // Solver information.
796 WallTimer timer_;
797
798 // This is set to true if the model is found to be UNSAT when adding new
799 // constraints.
800 bool model_is_unsat_ = false;
801
802 // Increment used to bump the variable activities.
803 double clause_activity_increment_;
804
805 // This counter is decremented each time we learn a clause that can be
806 // deleted. When it reaches zero, a clause cleanup is triggered.
807 int num_learned_clause_before_cleanup_ = 0;
808
809 int64_t minimization_by_propagation_threshold_ = 0;
810
811 // Temporary members used during conflict analysis.
812 SparseBitset<BooleanVariable> is_marked_;
813 SparseBitset<BooleanVariable> is_independent_;
814 SparseBitset<BooleanVariable> tmp_mark_;
815 std::vector<int> min_trail_index_per_level_;
816
817 // Temporary members used by CanBeInferedFromConflictVariables().
818 std::vector<BooleanVariable> dfs_stack_;
819 std::vector<BooleanVariable> variable_to_process_;
820
821 // Temporary member used when adding clauses.
822 std::vector<Literal> literals_scratchpad_;
823
824 // A boolean vector used to temporarily mark decision levels.
825 DEFINE_STRONG_INDEX_TYPE(SatDecisionLevel);
826 SparseBitset<SatDecisionLevel> is_level_marked_;
827
828 // Temporary vectors used by EnqueueDecisionAndBackjumpOnConflict().
829 std::vector<Literal> learned_conflict_;
830 std::vector<Literal> reason_used_to_infer_the_conflict_;
831 std::vector<Literal> extra_reason_literals_;
832 std::vector<SatClause*> subsumed_clauses_;
833
834 // When true, temporarily disable the deletion of clauses that are not needed
835 // anymore. This is a hack for TryToMinimizeClause() because we use
836 // propagation in this function which might trigger a clause database
837 // deletion, but we still want the pointer to the clause we wants to minimize
838 // to be valid until the end of that function.
839 bool block_clause_deletion_ = false;
840
841 // "cache" to avoid inspecting many times the same reason during conflict
842 // analysis.
843 VariableWithSameReasonIdentifier same_reason_identifier_;
844
845 // Boolean used to include/exclude constraints from the core computation.
846 bool is_relevant_for_core_computation_;
847
848 // The current pseudo-Boolean conflict used in PB conflict analysis.
849 MutableUpperBoundedLinearConstraint pb_conflict_;
850
851 // The deterministic time when the time limit was updated.
852 // As the deterministic time in the time limit has to be advanced manually,
853 // it is necessary to keep track of the last time the time was advanced.
854 double deterministic_time_at_last_advanced_time_limit_ = 0;
855
856 DratProofHandler* drat_proof_handler_;
857
858 mutable StatsGroup stats_;
859};
860
861// Tries to minimize the given UNSAT core with a really simple heuristic.
862// The idea is to remove literals that are consequences of others in the core.
863// We already know that in the initial order, no literal is propagated by the
864// one before it, so we just look for propagation in the reverse order.
865//
866// Important: The given SatSolver must be the one that just produced the given
867// core.
868//
869// TODO(user): One should use MinimizeCoreWithPropagation() instead.
870void MinimizeCore(SatSolver* solver, std::vector<Literal>* core);
871
872// ============================================================================
873// Model based functions.
874//
875// TODO(user): move them in another file, and unit-test them.
876// ============================================================================
877
878inline std::function<void(Model*)> BooleanLinearConstraint(
879 int64_t lower_bound, int64_t upper_bound,
880 std::vector<LiteralWithCoeff>* cst) {
881 return [=](Model* model) {
882 model->GetOrCreate<SatSolver>()->AddLinearConstraint(
883 /*use_lower_bound=*/true, Coefficient(lower_bound),
884 /*use_upper_bound=*/true, Coefficient(upper_bound), cst);
885 };
886}
887
888inline std::function<void(Model*)> CardinalityConstraint(
889 int64_t lower_bound, int64_t upper_bound,
890 const std::vector<Literal>& literals) {
891 return [=](Model* model) {
892 std::vector<LiteralWithCoeff> cst;
893 cst.reserve(literals.size());
894 for (int i = 0; i < literals.size(); ++i) {
895 cst.emplace_back(literals[i], 1);
896 }
897 model->GetOrCreate<SatSolver>()->AddLinearConstraint(
898 /*use_lower_bound=*/true, Coefficient(lower_bound),
899 /*use_upper_bound=*/true, Coefficient(upper_bound), &cst);
900 };
901}
902
903inline std::function<void(Model*)> ExactlyOneConstraint(
904 const std::vector<Literal>& literals) {
905 return [=](Model* model) {
906 std::vector<LiteralWithCoeff> cst;
907 cst.reserve(literals.size());
908 for (const Literal l : literals) {
909 cst.emplace_back(l, Coefficient(1));
910 }
911 model->GetOrCreate<SatSolver>()->AddLinearConstraint(
912 /*use_lower_bound=*/true, Coefficient(1),
913 /*use_upper_bound=*/true, Coefficient(1), &cst);
914 };
915}
916
917inline std::function<void(Model*)> AtMostOneConstraint(
918 const std::vector<Literal>& literals) {
919 return [=](Model* model) {
920 std::vector<LiteralWithCoeff> cst;
921 cst.reserve(literals.size());
922 for (const Literal l : literals) {
923 cst.emplace_back(l, Coefficient(1));
924 }
925 model->GetOrCreate<SatSolver>()->AddLinearConstraint(
926 /*use_lower_bound=*/false, Coefficient(0),
927 /*use_upper_bound=*/true, Coefficient(1), &cst);
928 };
929}
930
931inline std::function<void(Model*)> ClauseConstraint(
932 absl::Span<const Literal> literals) {
933 return [=](Model* model) {
934 model->GetOrCreate<SatSolver>()->AddProblemClause(literals,
935 /*is_safe=*/false);
936 };
937}
938
939// a => b.
940inline std::function<void(Model*)> Implication(Literal a, Literal b) {
941 return [=](Model* model) {
942 model->GetOrCreate<SatSolver>()->AddBinaryClause(a.Negated(), b);
943 };
944}
945
946// a == b.
947inline std::function<void(Model*)> Equality(Literal a, Literal b) {
948 return [=](Model* model) {
949 model->GetOrCreate<SatSolver>()->AddBinaryClause(a.Negated(), b);
950 model->GetOrCreate<SatSolver>()->AddBinaryClause(a, b.Negated());
951 };
952}
953
954// r <=> (at least one literal is true). This is a reified clause.
955inline std::function<void(Model*)> ReifiedBoolOr(
956 const std::vector<Literal>& literals, Literal r) {
957 return [=](Model* model) {
958 std::vector<Literal> clause;
959 for (const Literal l : literals) {
960 model->Add(Implication(l, r)); // l => r.
961 clause.push_back(l);
962 }
963
964 // All false => r false.
965 clause.push_back(r.Negated());
966 model->Add(ClauseConstraint(clause));
967 };
968}
969
970// enforcement_literals => clause.
971inline std::function<void(Model*)> EnforcedClause(
972 absl::Span<const Literal> enforcement_literals,
973 absl::Span<const Literal> clause) {
974 return [=](Model* model) {
975 std::vector<Literal> tmp;
976 for (const Literal l : enforcement_literals) {
977 tmp.push_back(l.Negated());
978 }
979 for (const Literal l : clause) {
980 tmp.push_back(l);
981 }
982 model->Add(ClauseConstraint(tmp));
983 };
984}
985
986// r <=> (all literals are true).
987//
988// Note(user): we could have called ReifiedBoolOr() with everything negated.
989inline std::function<void(Model*)> ReifiedBoolAnd(
990 const std::vector<Literal>& literals, Literal r) {
991 return [=](Model* model) {
992 std::vector<Literal> clause;
993 for (const Literal l : literals) {
994 model->Add(Implication(r, l)); // r => l.
995 clause.push_back(l.Negated());
996 }
997
998 // All true => r true.
999 clause.push_back(r);
1000 model->Add(ClauseConstraint(clause));
1001 };
1002}
1003
1004// r <=> (a <= b).
1005inline std::function<void(Model*)> ReifiedBoolLe(Literal a, Literal b,
1006 Literal r) {
1007 return [=](Model* model) {
1008 // r <=> (a <= b) is the same as r <=> not(a=1 and b=0).
1009 // So r <=> a=0 OR b=1.
1010 model->Add(ReifiedBoolOr({a.Negated(), b}, r));
1011 };
1012}
1013
1014// This checks that the variable is fixed.
1015inline std::function<int64_t(const Model&)> Value(Literal l) {
1016 return [=](const Model& model) {
1017 const Trail* trail = model.Get<Trail>();
1018 CHECK(trail->Assignment().VariableIsAssigned(l.Variable()));
1019 return trail->Assignment().LiteralIsTrue(l);
1020 };
1021}
1022
1023// This checks that the variable is fixed.
1024inline std::function<int64_t(const Model&)> Value(BooleanVariable b) {
1025 return [=](const Model& model) {
1026 const Trail* trail = model.Get<Trail>();
1027 CHECK(trail->Assignment().VariableIsAssigned(b));
1028 return trail->Assignment().LiteralIsTrue(Literal(b, true));
1029 };
1030}
1031
1032// This can be used to enumerate all the solutions. After each SAT call to
1033// Solve(), calling this will reset the solver and exclude the current solution
1034// so that the next call to Solve() will give a new solution or UNSAT is there
1035// is no more new solutions.
1036inline std::function<void(Model*)> ExcludeCurrentSolutionAndBacktrack() {
1037 return [=](Model* model) {
1038 SatSolver* sat_solver = model->GetOrCreate<SatSolver>();
1039
1040 // Note that we only exclude the current decisions, which is an efficient
1041 // way to not get the same SAT assignment.
1042 const int current_level = sat_solver->CurrentDecisionLevel();
1043 std::vector<Literal> clause_to_exclude_solution;
1044 clause_to_exclude_solution.reserve(current_level);
1045 for (int i = 0; i < current_level; ++i) {
1046 clause_to_exclude_solution.push_back(
1047 sat_solver->Decisions()[i].literal.Negated());
1048 }
1049 sat_solver->Backtrack(0);
1050 model->Add(ClauseConstraint(clause_to_exclude_solution));
1051 };
1052}
1053
1054// Returns a string representation of a SatSolver::Status.
1056inline std::ostream& operator<<(std::ostream& os, SatSolver::Status status) {
1057 os << SatStatusString(status);
1058 return os;
1059}
1060
1061} // namespace sat
1062} // namespace operations_research
1063
1064#endif // OR_TOOLS_SAT_SAT_SOLVER_H_
void AdvanceDeterministicTime(double deterministic_duration)
Definition time_limit.h:183
void ExtractAllBinaryClauses(Output *out) const
Definition clause.h:707
void SetDratProofHandler(DratProofHandler *drat_proof_handler)
Definition clause.h:727
bool IsRemovable(SatClause *const clause) const
Definition clause.h:223
void SetDratProofHandler(DratProofHandler *drat_proof_handler)
Definition clause.h:243
const std::vector< SatClause * > & AllClausesInCreationOrder() const
Definition clause.h:215
std::vector< std::pair< Literal, float > > AllPreferences() const
Returns the vector of the current assignment preferences.
void SetAssignmentPreference(Literal literal, float weight)
Base class for all the SAT constraints.
Definition sat_base.h:533
Status EnqueueDecisionAndBacktrackOnConflict(Literal true_literal, int *first_propagation_index=nullptr)
bool AddLinearConstraint(bool use_lower_bound, Coefficient lower_bound, bool use_upper_bound, Coefficient upper_bound, std::vector< LiteralWithCoeff > *cst)
Status SolveWithTimeLimit(TimeLimit *time_limit)
void SetDratProofHandler(DratProofHandler *drat_proof_handler)
Definition sat_solver.h:444
bool AddBinaryClauses(const std::vector< BinaryClause > &clauses)
bool AddProblemClause(absl::Span< const Literal > literals, bool is_safe=true)
bool MinimizeByPropagation(double dtime)
const std::vector< BinaryClause > & NewlyAddedBinaryClauses()
SatSolver(const SatSolver &)=delete
This type is neither copyable nor movable.
SolverLogger * mutable_logger()
Hack to allow to temporarily disable logging if it is enabled.
Definition sat_solver.h:492
void SetAssignmentPreference(Literal literal, float weight)
Definition sat_solver.h:164
BooleanVariable NewBooleanVariable()
Definition sat_solver.h:94
void ProcessNewlyFixedVariables()
Simplifies the problem when new variables are assigned at level 0.
bool ResetWithGivenAssumptions(const std::vector< Literal > &assumptions)
int64_t num_branches() const
Some statistics since the creation of the solver.
void LoadDebugSolution(const std::vector< Literal > &solution)
std::vector< Literal > GetLastIncompatibleDecisions()
bool AddBinaryClause(Literal a, Literal b)
Same as AddProblemClause() below, but for small clauses.
int EnqueueDecisionAndBackjumpOnConflict(Literal true_literal)
void Backtrack(int target_level)
const SatParameters & parameters() const
bool EnqueueDecisionIfNotConflicting(Literal true_literal)
bool AddClauseDuringSearch(absl::Span< const Literal > literals)
ABSL_MUST_USE_RESULT bool Propagate()
void SetAssumptionLevel(int assumption_level)
std::vector< std::pair< Literal, float > > AllPreferences() const
Definition sat_solver.h:167
ABSL_MUST_USE_RESULT bool AddUnitClause(Literal true_literal)
bool AddTernaryClause(Literal a, Literal b, Literal c)
void TakePropagatorOwnership(std::unique_ptr< SatPropagator > propagator)
Definition sat_solver.h:156
SatSolver & operator=(const SatSolver &)=delete
void AdvanceDeterministicTime(TimeLimit *limit)
Definition sat_solver.h:475
Status ResetAndSolveWithGivenAssumptions(const std::vector< Literal > &assumptions, int64_t max_number_of_conflicts=-1)
const VariablesAssignment & Assignment() const
Definition sat_solver.h:388
ABSL_MUST_USE_RESULT bool ResetToLevelZero()
void AddLastPropagator(SatPropagator *propagator)
const std::vector< Decision > & Decisions() const
Definition sat_solver.h:385
ABSL_MUST_USE_RESULT bool FinishPropagation()
const Trail & LiteralTrail() const
Definition sat_solver.h:387
void SetNumVariables(int num_variables)
Definition sat_solver.cc:85
void AddPropagator(SatPropagator *propagator)
void SetParameters(const SatParameters &parameters)
const AssignmentInfo & Info(BooleanVariable var) const
Definition sat_base.h:463
const VariablesAssignment & Assignment() const
Definition sat_base.h:462
bool VariableIsAssigned(BooleanVariable var) const
Returns true iff the given variable is assigned.
Definition sat_base.h:196
bool LiteralIsTrue(Literal literal) const
Definition sat_base.h:188
int64_t a
Definition table.cc:44
int64_t value
IntVar * var
absl::Status status
Definition g_gurobi.cc:44
double upper_bound
double lower_bound
GRBmodel * model
int literal
time_limit
Definition solve.cc:22
double solution
std::function< void(Model *)> Equality(IntegerVariable v, int64_t value)
Fix v to a given value.
Definition integer.h:2012
std::function< void(Model *)> ReifiedBoolOr(const std::vector< Literal > &literals, Literal r)
r <=> (at least one literal is true). This is a reified clause.
Definition sat_solver.h:957
std::string SatStatusString(SatSolver::Status status)
Returns a string representation of a SatSolver::Status.
std::function< void(Model *)> ClauseConstraint(absl::Span< const Literal > literals)
Definition sat_solver.h:933
std::function< void(Model *)> EnforcedClause(absl::Span< const Literal > enforcement_literals, absl::Span< const Literal > clause)
enforcement_literals => clause.
Definition sat_solver.h:973
std::function< void(Model *)> ReifiedBoolLe(Literal a, Literal b, Literal r)
r <=> (a <= b).
std::function< void(Model *)> Implication(absl::Span< const Literal > enforcement_literals, IntegerLiteral i)
Definition integer.h:2025
std::ostream & operator<<(std::ostream &os, const BoolVar &var)
Definition cp_model.cc:89
std::function< void(Model *)> AtMostOneConstraint(const std::vector< Literal > &literals)
Definition sat_solver.h:919
std::function< int64_t(const Model &)> Value(IntegerVariable v)
This checks that the variable is fixed.
Definition integer.h:1975
std::function< void(Model *)> ReifiedBoolAnd(const std::vector< Literal > &literals, Literal r)
Definition sat_solver.h:991
std::function< void(Model *)> CardinalityConstraint(int64_t lower_bound, int64_t upper_bound, const std::vector< Literal > &literals)
Definition sat_solver.h:890
std::function< void(Model *)> BooleanLinearConstraint(int64_t lower_bound, int64_t upper_bound, std::vector< LiteralWithCoeff > *cst)
Definition sat_solver.h:880
const int kUnsatTrailIndex
A constant used by the EnqueueDecision*() API.
Definition sat_solver.h:58
std::function< void(Model *)> ExactlyOneConstraint(const std::vector< Literal > &literals)
Definition sat_solver.h:905
std::function< void(Model *)> ExcludeCurrentSolutionAndBacktrack()
void MinimizeCore(SatSolver *solver, std::vector< Literal > *core)
In SWIG mode, we don't want anything besides these top-level includes.
int64_t weight
Definition pack.cc:510
static int input(yyscan_t yyscanner)
#define DEFINE_STRONG_INDEX_TYPE(index_type_name)
int32_t trail_index
The index of this assignment in the trail.
Definition sat_base.h:263
int64_t minimization_num_clauses
TryToMinimizeClause() stats.
Definition sat_solver.h:422
int64_t num_minimizations
Minimization stats.
Definition sat_solver.h:410
int64_t num_literals_learned
Clause learning /deletion stats.
Definition sat_solver.h:417