OR-Tools  9.1
sat_base.h
Go to the documentation of this file.
1// Copyright 2010-2021 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// Basic types and classes used by the sat solver.
15
16#ifndef OR_TOOLS_SAT_SAT_BASE_H_
17#define OR_TOOLS_SAT_SAT_BASE_H_
18
19#include <algorithm>
20#include <cstdint>
21#include <deque>
22#include <memory>
23#include <string>
24#include <vector>
25
26#include "absl/strings/str_format.h"
27#include "absl/types/span.h"
31#include "ortools/base/macros.h"
33#include "ortools/sat/model.h"
34#include "ortools/util/bitset.h"
35
36namespace operations_research {
37namespace sat {
38
39// Index of a variable (>= 0).
40DEFINE_INT_TYPE(BooleanVariable, int);
41const BooleanVariable kNoBooleanVariable(-1);
42
43// Index of a literal (>= 0), see Literal below.
44DEFINE_INT_TYPE(LiteralIndex, int);
45const LiteralIndex kNoLiteralIndex(-1);
46
47// Special values used in some API to indicate a literal that is always true
48// or always false.
49const LiteralIndex kTrueLiteralIndex(-2);
50const LiteralIndex kFalseLiteralIndex(-3);
51
52// A literal is used to represent a variable or its negation. If it represents
53// the variable it is said to be positive. If it represent its negation, it is
54// said to be negative. We support two representations as an integer.
55//
56// The "signed" encoding of a literal is convenient for input/output and is used
57// in the cnf file format. For a 0-based variable index x, (x + 1) represent the
58// variable x and -(x + 1) represent its negation. The signed value 0 is an
59// undefined literal and this class can never contain it.
60//
61// The "index" encoding of a literal is convenient as an index to an array
62// and is the one used internally for efficiency. It is always positive or zero,
63// and for a 0-based variable index x, (x << 1) encode the variable x and the
64// same number XOR 1 encode its negation.
65class Literal {
66 public:
67 // Not explicit for tests so we can write:
68 // vector<literal> literal = {+1, -3, +4, -9};
69 Literal(int signed_value) // NOLINT
70 : index_(signed_value > 0 ? ((signed_value - 1) << 1)
71 : ((-signed_value - 1) << 1) ^ 1) {
72 CHECK_NE(signed_value, 0);
73 }
74
76 explicit Literal(LiteralIndex index) : index_(index.value()) {}
77 Literal(BooleanVariable variable, bool is_positive)
78 : index_(is_positive ? (variable.value() << 1)
79 : (variable.value() << 1) ^ 1) {}
80
81 BooleanVariable Variable() const { return BooleanVariable(index_ >> 1); }
82 bool IsPositive() const { return !(index_ & 1); }
83 bool IsNegative() const { return (index_ & 1); }
84
85 LiteralIndex Index() const { return LiteralIndex(index_); }
86 LiteralIndex NegatedIndex() const { return LiteralIndex(index_ ^ 1); }
87
88 int SignedValue() const {
89 return (index_ & 1) ? -((index_ >> 1) + 1) : ((index_ >> 1) + 1);
90 }
91
92 Literal Negated() const { return Literal(NegatedIndex()); }
93
94 std::string DebugString() const {
95 return absl::StrFormat("%+d", SignedValue());
96 }
97 bool operator==(Literal other) const { return index_ == other.index_; }
98 bool operator!=(Literal other) const { return index_ != other.index_; }
99
100 bool operator<(const Literal& literal) const {
101 return Index() < literal.Index();
102 }
103
104 private:
105 int index_;
106};
107
108inline std::ostream& operator<<(std::ostream& os, Literal literal) {
109 os << literal.DebugString();
110 return os;
111}
112
113inline std::ostream& operator<<(std::ostream& os,
114 absl::Span<const Literal> literals) {
115 for (const Literal literal : literals) {
116 os << literal.DebugString() << ",";
117 }
118 return os;
119}
120
121// Holds the current variable assignment of the solver.
122// Each variable can be unassigned or be assigned to true or false.
124 public:
126 explicit VariablesAssignment(int num_variables) { Resize(num_variables); }
127 void Resize(int num_variables) {
128 assignment_.Resize(LiteralIndex(num_variables << 1));
129 }
130
131 // Makes the given literal true by assigning its underlying variable to either
132 // true or false depending on the literal sign. This can only be called on an
133 // unassigned variable.
135 DCHECK(!VariableIsAssigned(literal.Variable()));
136 assignment_.Set(literal.Index());
137 }
138
139 // Unassign the variable corresponding to the given literal.
140 // This can only be called on an assigned variable.
142 DCHECK(VariableIsAssigned(literal.Variable()));
143 assignment_.ClearTwoBits(literal.Index());
144 }
145
146 // Literal getters. Note that both can be false, in which case the
147 // corresponding variable is not assigned.
149 return assignment_.IsSet(literal.NegatedIndex());
150 }
152 return assignment_.IsSet(literal.Index());
153 }
155 return assignment_.AreOneOfTwoBitsSet(literal.Index());
156 }
157
158 // Returns true iff the given variable is assigned.
159 bool VariableIsAssigned(BooleanVariable var) const {
160 return assignment_.AreOneOfTwoBitsSet(LiteralIndex(var.value() << 1));
161 }
162
163 // Returns the literal of the given variable that is assigned to true.
164 // That is, depending on the variable, it can be the positive literal or the
165 // negative one. Only call this on an assigned variable.
168 return Literal(var, assignment_.IsSet(LiteralIndex(var.value() << 1)));
169 }
170
171 int NumberOfVariables() const { return assignment_.size().value() / 2; }
172
173 private:
174 // The encoding is as follows:
175 // - assignment_.IsSet(literal.Index()) means literal is true.
176 // - assignment_.IsSet(literal.Index() ^ 1]) means literal is false.
177 // - If both are false, then the variable (and the literal) is unassigned.
178 Bitset64<LiteralIndex> assignment_;
179
180 DISALLOW_COPY_AND_ASSIGN(VariablesAssignment);
181};
182
183// Forward declaration.
184class SatClause;
185class SatPropagator;
186
187// Information about a variable assignment.
189 // The decision level at which this assignment was made. This starts at 0 and
190 // increases each time the solver takes a search decision.
191 //
192 // TODO(user): We may be able to get rid of that for faster enqueues. Most of
193 // the code only need to know if this is 0 or the highest level, and for the
194 // LBD computation, the literal of the conflict are already ordered by level,
195 // so we could do it fairly efficiently.
196 //
197 // TODO(user): We currently don't support more than 2^28 decision levels. That
198 // should be enough for most practical problem, but we should fail properly if
199 // this limit is reached.
200 uint32_t level : 28;
201
202 // The type of assignment (see AssignmentType below).
203 //
204 // Note(user): We currently don't support more than 16 types of assignment.
205 // This is checked in RegisterPropagator().
206 mutable uint32_t type : 4;
207
208 // The index of this assignment in the trail.
209 int32_t trail_index;
210
211 std::string DebugString() const {
212 return absl::StrFormat("level:%d type:%d trail_index:%d", level, type,
214 }
215};
216static_assert(sizeof(AssignmentInfo) == 8,
217 "ERROR_AssignmentInfo_is_not_well_compacted");
218
219// Each literal on the trail will have an associated propagation "type" which is
220// either one of these special types or the id of a propagator.
222 static constexpr int kCachedReason = 0;
223 static constexpr int kUnitReason = 1;
224 static constexpr int kSearchDecision = 2;
225 static constexpr int kSameReasonAs = 3;
226
227 // Propagator ids starts from there and are created dynamically.
228 static constexpr int kFirstFreePropagationId = 4;
229};
230
231// The solver trail stores the assignment made by the solver in order.
232// This class is responsible for maintaining the assignment of each variable
233// and the information of each assignment.
234class Trail {
235 public:
236 explicit Trail(Model* model) : Trail() {}
237
239 current_info_.trail_index = 0;
240 current_info_.level = 0;
241 }
242
243 void Resize(int num_variables);
244
245 // Registers a propagator. This assigns a unique id to this propagator and
246 // calls SetPropagatorId() on it.
247 void RegisterPropagator(SatPropagator* propagator);
248
249 // Enqueues the assignment that make the given literal true on the trail. This
250 // should only be called on unassigned variables.
251 void Enqueue(Literal true_literal, int propagator_id) {
252 DCHECK(!assignment_.VariableIsAssigned(true_literal.Variable()));
253 trail_[current_info_.trail_index] = true_literal;
254 current_info_.type = propagator_id;
255 info_[true_literal.Variable()] = current_info_;
256 assignment_.AssignFromTrueLiteral(true_literal);
257 ++current_info_.trail_index;
258 }
259
260 // Specific Enqueue() version for the search decision.
261 void EnqueueSearchDecision(Literal true_literal) {
263 }
264
265 // Specific Enqueue() version for a fixed variable.
266 void EnqueueWithUnitReason(Literal true_literal) {
268 }
269
270 // Some constraints propagate a lot of literals at once. In these cases, it is
271 // more efficient to have all the propagated literals except the first one
272 // referring to the reason of the first of them.
274 BooleanVariable reference_var) {
275 reference_var_with_same_reason_as_[true_literal.Variable()] = reference_var;
277 }
278
279 // Enqueues the given literal using the current content of
280 // GetEmptyVectorToStoreReason() as the reason. This API is a bit more
281 // leanient and does not require the literal to be unassigned. If it is
282 // already assigned to false, then MutableConflict() will be set appropriately
283 // and this will return false otherwise this will enqueue the literal and
284 // returns true.
285 ABSL_MUST_USE_RESULT bool EnqueueWithStoredReason(Literal true_literal) {
286 if (assignment_.LiteralIsTrue(true_literal)) return true;
287 if (assignment_.LiteralIsFalse(true_literal)) {
288 *MutableConflict() = reasons_repository_[Index()];
289 MutableConflict()->push_back(true_literal);
290 return false;
291 }
292
294 const BooleanVariable var = true_literal.Variable();
295 reasons_[var] = reasons_repository_[info_[var].trail_index];
296 old_type_[var] = info_[var].type;
298 return true;
299 }
300
301 // Returns the reason why this variable was assigned.
302 //
303 // Note that this shouldn't be called on a variable at level zero, because we
304 // don't cleanup the reason data for these variables but the underlying
305 // clauses may have been deleted.
306 absl::Span<const Literal> Reason(BooleanVariable var) const;
307
308 // Returns the "type" of an assignment (see AssignmentType). Note that this
309 // function never returns kSameReasonAs or kCachedReason, it instead returns
310 // the initial type that caused this assignment. As such, it is different
311 // from Info(var).type and the latter should not be used outside this class.
312 int AssignmentType(BooleanVariable var) const;
313
314 // If a variable was propagated with EnqueueWithSameReasonAs(), returns its
315 // reference variable. Otherwise return the given variable.
316 BooleanVariable ReferenceVarWithSameReason(BooleanVariable var) const;
317
318 // This can be used to get a location at which the reason for the literal
319 // at trail_index on the trail can be stored. This clears the vector before
320 // returning it.
321 std::vector<Literal>* GetEmptyVectorToStoreReason(int trail_index) const {
322 if (trail_index >= reasons_repository_.size()) {
323 reasons_repository_.resize(trail_index + 1);
324 }
325 reasons_repository_[trail_index].clear();
326 return &reasons_repository_[trail_index];
327 }
328
329 // Shortcut for GetEmptyVectorToStoreReason(Index()).
330 std::vector<Literal>* GetEmptyVectorToStoreReason() const {
332 }
333
334 // Explicitly overwrite the reason so that the given propagator will be
335 // asked for it. This is currently only used by the BinaryImplicationGraph.
336 void ChangeReason(int trail_index, int propagator_id) {
337 const BooleanVariable var = trail_[trail_index].Variable();
338 info_[var].type = propagator_id;
339 old_type_[var] = propagator_id;
340 }
341
342 // Reverts the trail and underlying assignment to the given target trail
343 // index. Note that we do not touch the assignment info.
344 void Untrail(int target_trail_index) {
345 const int index = Index();
346 num_untrailed_enqueues_ += index - target_trail_index;
347 for (int i = target_trail_index; i < index; ++i) {
348 assignment_.UnassignLiteral(trail_[i]);
349 }
350 current_info_.trail_index = target_trail_index;
351 }
352 void Dequeue() { Untrail(Index() - 1); }
353
354 // Changes the decision level used by the next Enqueue().
355 void SetDecisionLevel(int level) { current_info_.level = level; }
356 int CurrentDecisionLevel() const { return current_info_.level; }
357
358 // Generic interface to set the current failing clause.
359 //
360 // Returns the address of a vector where a client can store the current
361 // conflict. This vector will be returned by the FailingClause() call.
362 std::vector<Literal>* MutableConflict() {
363 failing_sat_clause_ = nullptr;
364 return &conflict_;
365 }
366
367 // Returns the last conflict.
368 absl::Span<const Literal> FailingClause() const { return conflict_; }
369
370 // Specific SatClause interface so we can update the conflict clause activity.
371 // Note that MutableConflict() automatically sets this to nullptr, so we can
372 // know whether or not the last conflict was caused by a clause.
373 void SetFailingSatClause(SatClause* clause) { failing_sat_clause_ = clause; }
374 SatClause* FailingSatClause() const { return failing_sat_clause_; }
375
376 // Getters.
377 int NumVariables() const { return trail_.size(); }
378 int64_t NumberOfEnqueues() const { return num_untrailed_enqueues_ + Index(); }
379 int Index() const { return current_info_.trail_index; }
380 const Literal& operator[](int index) const { return trail_[index]; }
381 const VariablesAssignment& Assignment() const { return assignment_; }
382 const AssignmentInfo& Info(BooleanVariable var) const {
383 DCHECK_GE(var, 0);
384 DCHECK_LT(var, info_.size());
385 return info_[var];
386 }
387
388 // Print the current literals on the trail.
389 std::string DebugString() {
390 std::string result;
391 for (int i = 0; i < current_info_.trail_index; ++i) {
392 if (!result.empty()) result += " ";
393 result += trail_[i].DebugString();
394 }
395 return result;
396 }
397
398 private:
399 int64_t num_untrailed_enqueues_ = 0;
400 AssignmentInfo current_info_;
401 VariablesAssignment assignment_;
402 std::vector<Literal> trail_;
403 std::vector<Literal> conflict_;
405 SatClause* failing_sat_clause_;
406
407 // Data used by EnqueueWithSameReasonAs().
409 reference_var_with_same_reason_as_;
410
411 // Reason cache. Mutable since we want the API to be the same whether the
412 // reason are cached or not.
413 //
414 // When a reason is computed for the first time, we change the type of the
415 // variable assignment to kCachedReason so that we know that if it is needed
416 // again the reason can just be retrieved by a direct access to reasons_. The
417 // old type is saved in old_type_ and can be retrieved by
418 // AssignmentType().
419 //
420 // Note(user): Changing the type is not "clean" but it is efficient. The idea
421 // is that it is important to do as little as possible when pushing/popping
422 // literals on the trail. Computing the reason happens a lot less often, so it
423 // is okay to do slightly more work then. Note also, that we don't need to
424 // do anything on "untrail", the kCachedReason type will be overwritten when
425 // the same variable is assigned again.
426 //
427 // TODO(user): An alternative would be to change the sign of the type. This
428 // would remove the need for a separate old_type_ vector, but it requires
429 // more bits for the type filed in AssignmentInfo.
430 //
431 // Note that we use a deque for the reason repository so that if we add
432 // variables, the memory address of the vectors (kept in reasons_) are still
433 // valid.
434 mutable std::deque<std::vector<Literal>> reasons_repository_;
436 reasons_;
438
439 // This is used by RegisterPropagator() and Reason().
440 std::vector<SatPropagator*> propagators_;
441
442 DISALLOW_COPY_AND_ASSIGN(Trail);
443};
444
445// Base class for all the SAT constraints.
447 public:
448 explicit SatPropagator(const std::string& name)
450 virtual ~SatPropagator() {}
451
452 // Sets/Gets this propagator unique id.
453 void SetPropagatorId(int id) { propagator_id_ = id; }
454 int PropagatorId() const { return propagator_id_; }
455
456 // Inspects the trail from propagation_trail_index_ until at least one literal
457 // is propagated. Returns false iff a conflict is detected (in which case
458 // trail->SetFailingClause() must be called).
459 //
460 // This must update propagation_trail_index_ so that all the literals before
461 // it have been propagated. In particular, if nothing was propagated, then
462 // PropagationIsDone() must return true.
463 virtual bool Propagate(Trail* trail) = 0;
464
465 // Reverts the state so that all the literals with a trail index greater or
466 // equal to the given one are not processed for propagation. Note that the
467 // trail current decision level is already reverted before this is called.
468 //
469 // TODO(user): Currently this is called at each Backtrack(), but we could
470 // bundle the calls in case multiple conflict one after the other are detected
471 // even before the Propagate() call of a SatPropagator is called.
472 //
473 // TODO(user): It is not yet 100% the case, but this can be guaranteed to be
474 // called with a trail index that will always be the start of a new decision
475 // level.
476 virtual void Untrail(const Trail& trail, int trail_index) {
478 }
479
480 // Explains why the literal at given trail_index was propagated by returning a
481 // reason for this propagation. This will only be called for literals that are
482 // on the trail and were propagated by this class.
483 //
484 // The interpretation is that because all the literals of a reason were
485 // assigned to false, we could deduce the assignement of the given variable.
486 //
487 // The returned Span has to be valid until the literal is untrailed. A client
488 // can use trail_.GetEmptyVectorToStoreReason() if it doesn't have a memory
489 // location that already contains the reason.
490 virtual absl::Span<const Literal> Reason(const Trail& trail,
491 int trail_index) const {
492 LOG(FATAL) << "Not implemented.";
493 return {};
494 }
495
496 // Returns true if all the preconditions for Propagate() are satisfied.
497 // This is just meant to be used in a DCHECK.
498 bool PropagatePreconditionsAreSatisfied(const Trail& trail) const;
499
500 // Returns true iff all the trail was inspected by this propagator.
501 bool PropagationIsDone(const Trail& trail) const {
502 return propagation_trail_index_ == trail.Index();
503 }
504
505 protected:
506 const std::string name_;
509
510 private:
511 DISALLOW_COPY_AND_ASSIGN(SatPropagator);
512};
513
514// ######################## Implementations below ########################
515
516// TODO(user): A few of these method should be moved in a .cc
517
519 const Trail& trail) const {
520 if (propagation_trail_index_ > trail.Index()) {
521 LOG(INFO) << "Issue in '" << name_ << ":"
522 << " propagation_trail_index_=" << propagation_trail_index_
523 << " trail_.Index()=" << trail.Index();
524 return false;
525 }
526 if (propagation_trail_index_ < trail.Index() &&
527 trail.Info(trail[propagation_trail_index_].Variable()).level !=
528 trail.CurrentDecisionLevel()) {
529 LOG(INFO) << "Issue in '" << name_ << "':"
530 << " propagation_trail_index_=" << propagation_trail_index_
531 << " trail_.Index()=" << trail.Index()
532 << " level_at_propagation_index="
533 << trail.Info(trail[propagation_trail_index_].Variable()).level
534 << " current_decision_level=" << trail.CurrentDecisionLevel();
535 return false;
536 }
537 return true;
538}
539
540inline void Trail::Resize(int num_variables) {
541 assignment_.Resize(num_variables);
542 info_.resize(num_variables);
543 trail_.resize(num_variables);
544 reasons_.resize(num_variables);
545
546 // TODO(user): these vectors are not always used. Initialize them
547 // dynamically.
548 old_type_.resize(num_variables);
549 reference_var_with_same_reason_as_.resize(num_variables);
550}
551
552inline void Trail::RegisterPropagator(SatPropagator* propagator) {
553 if (propagators_.empty()) {
554 propagators_.resize(AssignmentType::kFirstFreePropagationId);
555 }
556 CHECK_LT(propagators_.size(), 16);
557 propagator->SetPropagatorId(propagators_.size());
558 propagators_.push_back(propagator);
559}
560
562 BooleanVariable var) const {
563 DCHECK(Assignment().VariableIsAssigned(var));
564 // Note that we don't use AssignmentType() here.
565 if (info_[var].type == AssignmentType::kSameReasonAs) {
566 var = reference_var_with_same_reason_as_[var];
567 DCHECK(Assignment().VariableIsAssigned(var));
569 }
570 return var;
571}
572
573inline int Trail::AssignmentType(BooleanVariable var) const {
574 if (info_[var].type == AssignmentType::kSameReasonAs) {
575 var = reference_var_with_same_reason_as_[var];
577 }
578 const int type = info_[var].type;
579 return type != AssignmentType::kCachedReason ? type : old_type_[var];
580}
581
582inline absl::Span<const Literal> Trail::Reason(BooleanVariable var) const {
583 // Special case for AssignmentType::kSameReasonAs to avoid a recursive call.
585
586 // Fast-track for cached reason.
587 if (info_[var].type == AssignmentType::kCachedReason) return reasons_[var];
588
589 const AssignmentInfo& info = info_[var];
590 if (info.type == AssignmentType::kUnitReason ||
592 reasons_[var] = {};
593 } else {
594 DCHECK_LT(info.type, propagators_.size());
595 DCHECK(propagators_[info.type] != nullptr) << info.type;
596 reasons_[var] = propagators_[info.type]->Reason(*this, info.trail_index);
597 }
598 old_type_[var] = info.type;
600 return reasons_[var];
601}
602
603} // namespace sat
604} // namespace operations_research
605
606#endif // OR_TOOLS_SAT_SAT_BASE_H_
int64_t min
Definition: alldiff_cst.cc:139
#define DCHECK_NE(val1, val2)
Definition: base/logging.h:887
#define CHECK_LT(val1, val2)
Definition: base/logging.h:701
#define DCHECK_GE(val1, val2)
Definition: base/logging.h:890
#define CHECK_NE(val1, val2)
Definition: base/logging.h:699
#define DCHECK_LT(val1, val2)
Definition: base/logging.h:889
#define LOG(severity)
Definition: base/logging.h:416
#define DCHECK(condition)
Definition: base/logging.h:885
Literal(int signed_value)
Definition: sat_base.h:69
LiteralIndex NegatedIndex() const
Definition: sat_base.h:86
LiteralIndex Index() const
Definition: sat_base.h:85
Literal(LiteralIndex index)
Definition: sat_base.h:76
Literal(BooleanVariable variable, bool is_positive)
Definition: sat_base.h:77
BooleanVariable Variable() const
Definition: sat_base.h:81
std::string DebugString() const
Definition: sat_base.h:94
bool operator==(Literal other) const
Definition: sat_base.h:97
bool operator!=(Literal other) const
Definition: sat_base.h:98
bool operator<(const Literal &literal) const
Definition: sat_base.h:100
Class that owns everything related to a particular optimization model.
Definition: sat/model.h:38
virtual bool Propagate(Trail *trail)=0
SatPropagator(const std::string &name)
Definition: sat_base.h:448
bool PropagatePreconditionsAreSatisfied(const Trail &trail) const
Definition: sat_base.h:518
virtual void Untrail(const Trail &trail, int trail_index)
Definition: sat_base.h:476
virtual absl::Span< const Literal > Reason(const Trail &trail, int trail_index) const
Definition: sat_base.h:490
bool PropagationIsDone(const Trail &trail) const
Definition: sat_base.h:501
void RegisterPropagator(SatPropagator *propagator)
Definition: sat_base.h:552
void Enqueue(Literal true_literal, int propagator_id)
Definition: sat_base.h:251
SatClause * FailingSatClause() const
Definition: sat_base.h:374
void ChangeReason(int trail_index, int propagator_id)
Definition: sat_base.h:336
int64_t NumberOfEnqueues() const
Definition: sat_base.h:378
std::vector< Literal > * GetEmptyVectorToStoreReason(int trail_index) const
Definition: sat_base.h:321
void EnqueueWithSameReasonAs(Literal true_literal, BooleanVariable reference_var)
Definition: sat_base.h:273
const VariablesAssignment & Assignment() const
Definition: sat_base.h:381
int AssignmentType(BooleanVariable var) const
Definition: sat_base.h:573
void SetFailingSatClause(SatClause *clause)
Definition: sat_base.h:373
absl::Span< const Literal > Reason(BooleanVariable var) const
Definition: sat_base.h:582
BooleanVariable ReferenceVarWithSameReason(BooleanVariable var) const
Definition: sat_base.h:561
ABSL_MUST_USE_RESULT bool EnqueueWithStoredReason(Literal true_literal)
Definition: sat_base.h:285
void Untrail(int target_trail_index)
Definition: sat_base.h:344
std::vector< Literal > * MutableConflict()
Definition: sat_base.h:362
const AssignmentInfo & Info(BooleanVariable var) const
Definition: sat_base.h:382
absl::Span< const Literal > FailingClause() const
Definition: sat_base.h:368
void SetDecisionLevel(int level)
Definition: sat_base.h:355
std::vector< Literal > * GetEmptyVectorToStoreReason() const
Definition: sat_base.h:330
const Literal & operator[](int index) const
Definition: sat_base.h:380
void Resize(int num_variables)
Definition: sat_base.h:540
void EnqueueWithUnitReason(Literal true_literal)
Definition: sat_base.h:266
void EnqueueSearchDecision(Literal true_literal)
Definition: sat_base.h:261
bool LiteralIsAssigned(Literal literal) const
Definition: sat_base.h:154
bool VariableIsAssigned(BooleanVariable var) const
Definition: sat_base.h:159
bool LiteralIsTrue(Literal literal) const
Definition: sat_base.h:151
void AssignFromTrueLiteral(Literal literal)
Definition: sat_base.h:134
Literal GetTrueLiteralForAssignedVariable(BooleanVariable var) const
Definition: sat_base.h:166
bool LiteralIsFalse(Literal literal) const
Definition: sat_base.h:148
const std::string name
int64_t value
IntVar * var
Definition: expr_array.cc:1874
GRBmodel * model
const int INFO
Definition: log_severity.h:31
const int FATAL
Definition: log_severity.h:32
std::ostream & operator<<(std::ostream &os, const BoolVar &var)
Definition: cp_model.cc:68
const LiteralIndex kNoLiteralIndex(-1)
const LiteralIndex kTrueLiteralIndex(-2)
DEFINE_INT_TYPE(ClauseIndex, int)
const LiteralIndex kFalseLiteralIndex(-3)
const BooleanVariable kNoBooleanVariable(-1)
Collection of objects used to extend the Constraint Solver library.
Literal literal
Definition: optimization.cc:85
int index
Definition: pack.cc:509
static constexpr int kSameReasonAs
Definition: sat_base.h:225
static constexpr int kFirstFreePropagationId
Definition: sat_base.h:228
static constexpr int kSearchDecision
Definition: sat_base.h:224
static constexpr int kCachedReason
Definition: sat_base.h:222