Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::sat::ClauseManager Class Reference

#include <clause.h>

Inheritance diagram for operations_research::sat::ClauseManager:
operations_research::sat::SatPropagator

Classes

struct  Watcher
 

Public Member Functions

 ClauseManager (Model *model)
 --— ClauseManager --—
 
 ClauseManager (const ClauseManager &)=delete
 This type is neither copyable nor movable.
 
ClauseManageroperator= (const ClauseManager &)=delete
 
 ~ClauseManager () override
 
void Resize (int num_variables)
 Must be called before adding clauses referring to such variables.
 
bool Propagate (Trail *trail) final
 SatPropagator API.
 
absl::Span< const LiteralReason (const Trail &trail, int trail_index, int64_t conflict_id) const final
 
SatClauseReasonClause (int trail_index) const
 
bool AddClause (absl::Span< const Literal > literals, Trail *trail, int lbd)
 Adds a new clause and perform initial propagation for this clause only.
 
bool AddClause (absl::Span< const Literal > literals)
 
SatClauseAddRemovableClause (absl::Span< const Literal > literals, Trail *trail, int lbd)
 
void LazyDetach (SatClause *clause)
 
void CleanUpWatchers ()
 
void Detach (SatClause *clause)
 
void Attach (SatClause *clause, Trail *trail)
 
void DeleteRemovedClauses ()
 
int64_t num_clauses () const
 
const std::vector< SatClause * > & AllClausesInCreationOrder () const
 
bool IsRemovable (SatClause *const clause) const
 
int64_t num_removable_clauses () const
 
absl::flat_hash_map< SatClause *, ClauseInfo > * mutable_clauses_info ()
 
int64_t num_inspected_clauses () const
 Total number of clauses inspected during calls to PropagateOnFalse().
 
int64_t num_inspected_clause_literals () const
 
int64_t literal_size () const
 The number of different literals (always twice the number of variables).
 
int64_t num_watched_clauses () const
 Number of clauses currently watched.
 
void SetDratProofHandler (DratProofHandler *drat_proof_handler)
 
SatClauseNextClauseToMinimize ()
 
SatClauseNextClauseToProbe ()
 
void ResetToProbeIndex ()
 Restart the scans.
 
void ResetToMinimizeIndex ()
 
void DetachAllClauses ()
 
void AttachAllClauses ()
 
void InprocessingRemoveClause (SatClause *clause)
 These must only be called between [Detach/Attach]AllClauses() calls.
 
ABSL_MUST_USE_RESULT bool InprocessingFixLiteral (Literal true_literal)
 This one do not need the clause to be detached.
 
ABSL_MUST_USE_RESULT bool InprocessingRewriteClause (SatClause *clause, absl::Span< const Literal > new_clause)
 
SatClauseInprocessingAddClause (absl::Span< const Literal > new_clause)
 
const std::vector< Watcher > & WatcherListOnFalse (Literal false_literal) const
 
void SetAddClauseCallback (absl::AnyInvocable< void(int lbd, absl::Span< const Literal >)> add_clause_callback)
 
- Public Member Functions inherited from operations_research::sat::SatPropagator
 SatPropagator (const std::string &name)
 
 SatPropagator (const SatPropagator &)=delete
 This type is neither copyable nor movable.
 
SatPropagatoroperator= (const SatPropagator &)=delete
 
virtual ~SatPropagator ()=default
 
void SetPropagatorId (int id)
 Sets/Gets this propagator unique id.
 
int PropagatorId () const
 
virtual void Untrail (const Trail &, int trail_index)
 
bool PropagatePreconditionsAreSatisfied (const Trail &trail) const
 ######################## Implementations below ########################
 
bool PropagationIsDone (const Trail &trail) const
 Returns true iff all the trail was inspected by this propagator.
 
virtual bool IsEmpty () const
 

Additional Inherited Members

- Protected Attributes inherited from operations_research::sat::SatPropagator
const std::string name_
 
int propagator_id_
 
int propagation_trail_index_
 

Detailed Description

Stores the 2-watched literals data structure. See http://www.cs.berkeley.edu/~necula/autded/lecture24-sat.pdf for detail.

This class is also responsible for owning the clause memory and all related information.

Definition at line 159 of file clause.h.

Constructor & Destructor Documentation

◆ ClauseManager() [1/2]

operations_research::sat::ClauseManager::ClauseManager ( Model * model)
explicit

--— ClauseManager --—

Definition at line 72 of file clause.cc.

◆ ClauseManager() [2/2]

operations_research::sat::ClauseManager::ClauseManager ( const ClauseManager & )
delete

This type is neither copyable nor movable.

◆ ~ClauseManager()

operations_research::sat::ClauseManager::~ClauseManager ( )
override

Definition at line 83 of file clause.cc.

Member Function Documentation

◆ AddClause() [1/2]

bool operations_research::sat::ClauseManager::AddClause ( absl::Span< const Literal > literals)

Definition at line 220 of file clause.cc.

◆ AddClause() [2/2]

bool operations_research::sat::ClauseManager::AddClause ( absl::Span< const Literal > literals,
Trail * trail,
int lbd )

Adds a new clause and perform initial propagation for this clause only.

Definition at line 224 of file clause.cc.

◆ AddRemovableClause()

SatClause * operations_research::sat::ClauseManager::AddRemovableClause ( absl::Span< const Literal > literals,
Trail * trail,
int lbd )

Same as AddClause() for a removable clause. This is only called on learned conflict, so this should never have all its literal at false (CHECKED).

Definition at line 232 of file clause.cc.

◆ AllClausesInCreationOrder()

const std::vector< SatClause * > & operations_research::sat::ClauseManager::AllClausesInCreationOrder ( ) const
inline

Definition at line 215 of file clause.h.

◆ Attach()

void operations_research::sat::ClauseManager::Attach ( SatClause * clause,
Trail * trail )

Attaches the given clause. The first two literal of the clause must be unassigned and the clause must not be already attached.

Definition at line 295 of file clause.cc.

◆ AttachAllClauses()

void operations_research::sat::ClauseManager::AttachAllClauses ( )

Definition at line 343 of file clause.cc.

◆ CleanUpWatchers()

void operations_research::sat::ClauseManager::CleanUpWatchers ( )

Definition at line 462 of file clause.cc.

◆ DeleteRemovedClauses()

void operations_research::sat::ClauseManager::DeleteRemovedClauses ( )

Reclaims the memory of the lazily removed clauses (their size was set to zero) and remove them from AllClausesInCreationOrder() this work in O(num_clauses()).

We also update to_minimize_index_/to_probe_index_ correctly.

Todo
(user): If more indices are needed, generalize the code to a vector of indices.

Definition at line 479 of file clause.cc.

◆ Detach()

void operations_research::sat::ClauseManager::Detach ( SatClause * clause)

Detaches the given clause right away.

Todo
(user): It might be better to have a "slower" mode in PropagateOnFalse() that deal with detached clauses in the watcher list and is activated until the next CleanUpWatchers() calls.

Definition at line 322 of file clause.cc.

◆ DetachAllClauses()

void operations_research::sat::ClauseManager::DetachAllClauses ( )

During an inprocessing phase, it is easier to detach all clause first, then simplify and then reattach them. Note however that during these two calls, it is not possible to use the solver unit-progation.

Important: When reattach is called, we assume that none of their literal are fixed, so we don't do any special checks.

These functions can be called multiple-time and do the right things. This way before doing something, you can call the corresponding function and be sure to be in a good state. I.e. always AttachAllClauses() before propagation and DetachAllClauses() before going to do an inprocessing pass that might transform them.

This is easy, and this allows to reset memory if some watcher lists where really long at some point.

Definition at line 332 of file clause.cc.

◆ InprocessingAddClause()

SatClause * operations_research::sat::ClauseManager::InprocessingAddClause ( absl::Span< const Literal > new_clause)

This can return nullptr if new_clause was of size one or two as these are treated differently. Note that none of the variable should be fixed in the given new clause.

Todo
(user): We should return false...

Definition at line 436 of file clause.cc.

◆ InprocessingFixLiteral()

bool operations_research::sat::ClauseManager::InprocessingFixLiteral ( Literal true_literal)

This one do not need the clause to be detached.

Todo
(user): remove the test when the DRAT issue with fixed literal is resolved.

Even when all clauses are detached, we can propagate the implication graph and we do that right away.

Definition at line 360 of file clause.cc.

◆ InprocessingRemoveClause()

void operations_research::sat::ClauseManager::InprocessingRemoveClause ( SatClause * clause)

These must only be called between [Detach/Attach]AllClauses() calls.

Todo
(user): We could do something slower if the clauses are attached like we do for InprocessingRewriteClause().

Definition at line 379 of file clause.cc.

◆ InprocessingRewriteClause()

bool operations_research::sat::ClauseManager::InprocessingRewriteClause ( SatClause * clause,
absl::Span< const Literal > new_clause )

We must write the new clause before we delete the old one.

We can still rewrite the clause, but it is inefficient. We first detach it in a non-lazy way.

And we reattach it.

Definition at line 388 of file clause.cc.

◆ IsRemovable()

bool operations_research::sat::ClauseManager::IsRemovable ( SatClause *const clause) const
inline

True if removing this clause will not change the set of feasible solution. This is the case for clauses that were learned during search. Note however that some learned clause are kept forever (heuristics) and do not appear here.

Definition at line 223 of file clause.h.

◆ LazyDetach()

void operations_research::sat::ClauseManager::LazyDetach ( SatClause * clause)

Lazily detach the given clause. The deletion will actually occur when CleanUpWatchers() is called. The later needs to be called before any other function in this class can be called. This is DCHECKed.

Note
we remove the clause from clauses_info_ right away.

Definition at line 315 of file clause.cc.

◆ literal_size()

int64_t operations_research::sat::ClauseManager::literal_size ( ) const
inline

The number of different literals (always twice the number of variables).

Definition at line 238 of file clause.h.

◆ mutable_clauses_info()

absl::flat_hash_map< SatClause *, ClauseInfo > * operations_research::sat::ClauseManager::mutable_clauses_info ( )
inline

Definition at line 227 of file clause.h.

◆ NextClauseToMinimize()

SatClause * operations_research::sat::ClauseManager::NextClauseToMinimize ( )
inline

Round-robbing selection of the next clause to minimize/probe.

Note
for minimization we only look at clause kept forever.
Todo
(user): If more indices are needed, switch to a generic API.

Definition at line 251 of file clause.h.

◆ NextClauseToProbe()

SatClause * operations_research::sat::ClauseManager::NextClauseToProbe ( )
inline

Definition at line 260 of file clause.h.

◆ num_clauses()

int64_t operations_research::sat::ClauseManager::num_clauses ( ) const
inline

Definition at line 214 of file clause.h.

◆ num_inspected_clause_literals()

int64_t operations_research::sat::ClauseManager::num_inspected_clause_literals ( ) const
inline

Definition at line 233 of file clause.h.

◆ num_inspected_clauses()

int64_t operations_research::sat::ClauseManager::num_inspected_clauses ( ) const
inline

Total number of clauses inspected during calls to PropagateOnFalse().

Definition at line 232 of file clause.h.

◆ num_removable_clauses()

int64_t operations_research::sat::ClauseManager::num_removable_clauses ( ) const
inline

Definition at line 226 of file clause.h.

◆ num_watched_clauses()

int64_t operations_research::sat::ClauseManager::num_watched_clauses ( ) const
inline

Number of clauses currently watched.

Definition at line 241 of file clause.h.

◆ operator=()

ClauseManager & operations_research::sat::ClauseManager::operator= ( const ClauseManager & )
delete

◆ Propagate()

bool operations_research::sat::ClauseManager::Propagate ( Trail * trail)
finalvirtual

SatPropagator API.

Implements operations_research::sat::SatPropagator.

Definition at line 201 of file clause.cc.

◆ Reason()

absl::Span< const Literal > operations_research::sat::ClauseManager::Reason ( const Trail & ,
int ,
int64_t  ) const
finalvirtual

Explains why the literal at given trail_index was propagated by returning a reason for this propagation. This will only be called for literals that are on the trail and were propagated by this class.

The interpretation is that because all the literals of a reason were assigned to false, we could deduce the assignment of the given variable.

The returned Span has to be valid until the literal is untrailed. A client can use trail_.GetEmptyVectorToStoreReason() if it doesn't have a memory location that already contains the reason.

If conlict id is positive, then this is called during first UIP resolution and we will backtrack over this literal right away, so we don't need to have a span that survive more than once.

Reimplemented from operations_research::sat::SatPropagator.

Definition at line 210 of file clause.cc.

◆ ReasonClause()

SatClause * operations_research::sat::ClauseManager::ReasonClause ( int trail_index) const

Returns the reason of the variable at given trail_index. This only works for variable propagated by this class and is almost the same as Reason() with a different return format.

Definition at line 216 of file clause.cc.

◆ ResetToMinimizeIndex()

void operations_research::sat::ClauseManager::ResetToMinimizeIndex ( )
inline

Definition at line 270 of file clause.h.

◆ ResetToProbeIndex()

void operations_research::sat::ClauseManager::ResetToProbeIndex ( )
inline

Restart the scans.

Definition at line 269 of file clause.h.

◆ Resize()

void operations_research::sat::ClauseManager::Resize ( int num_variables)

Must be called before adding clauses referring to such variables.

Definition at line 88 of file clause.cc.

◆ SetAddClauseCallback()

void operations_research::sat::ClauseManager::SetAddClauseCallback ( absl::AnyInvocable< void(int lbd, absl::Span< const Literal >)> add_clause_callback)
inline

Definition at line 329 of file clause.h.

◆ SetDratProofHandler()

void operations_research::sat::ClauseManager::SetDratProofHandler ( DratProofHandler * drat_proof_handler)
inline

Definition at line 243 of file clause.h.

◆ WatcherListOnFalse()

const std::vector< Watcher > & operations_research::sat::ClauseManager::WatcherListOnFalse ( Literal false_literal) const
inline

This is exposed since some inprocessing code can heuristically exploit the currently watched literal and blocking literal to do some simplification.

Definition at line 325 of file clause.h.


The documentation for this class was generated from the following files: