Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <integer.h>
Public Member Functions | |
GenericLiteralWatcher (Model *model) | |
GenericLiteralWatcher (const GenericLiteralWatcher &)=delete | |
This type is neither copyable nor movable. | |
GenericLiteralWatcher & | operator= (const GenericLiteralWatcher &)=delete |
~GenericLiteralWatcher () final=default | |
void | ReserveSpaceForNumVariables (int num_vars) |
Memory optimization: you can call this before registering watchers. | |
bool | Propagate (Trail *trail) final |
void | Untrail (const Trail &trail, int literal_trail_index) final |
int | Register (PropagatorInterface *propagator) |
Registers a propagator and returns its unique ids. | |
void | SetPropagatorPriority (int id, int priority) |
void | NotifyThatPropagatorMayNotReachFixedPointInOnePass (int id) |
void | AlwaysCallAtLevelZero (int id) |
void | WatchLiteral (Literal l, int id, int watch_index=-1) |
void | WatchLowerBound (IntegerVariable var, int id, int watch_index=-1) |
void | WatchUpperBound (IntegerVariable var, int id, int watch_index=-1) |
void | WatchIntegerVariable (IntegerVariable i, int id, int watch_index=-1) |
void | WatchLowerBound (AffineExpression e, int id) |
void | WatchUpperBound (AffineExpression e, int id) |
void | WatchAffineExpression (AffineExpression e, int id) |
void | WatchLowerBound (IntegerValue, int) |
void | WatchUpperBound (IntegerValue, int) |
void | WatchIntegerVariable (IntegerValue, int) |
void | RegisterReversibleClass (int id, ReversibleInterface *rev) |
void | RegisterReversibleInt (int id, int *rev) |
void | SetUntilNextBacktrack (bool *is_in_dive) |
int | NumPropagators () const |
Returns the number of registered propagators. | |
void | RegisterLevelZeroModifiedVariablesCallback (const std::function< void(const std::vector< IntegerVariable > &)> cb) |
void | SetStopPropagationCallback (std::function< bool()> callback) |
int | GetCurrentId () const |
void | CallOnNextPropagate (int id) |
Add the given propagator to its queue. | |
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. | |
SatPropagator & | operator= (const SatPropagator &)=delete |
virtual | ~SatPropagator ()=default |
void | SetPropagatorId (int id) |
Sets/Gets this propagator unique id. | |
int | PropagatorId () const |
virtual absl::Span< const Literal > | Reason (const Trail &, int, int64_t) const |
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_ |
This class allows registering Propagator that will be called if a watched Literal or LbVar changes.
|
explicit |
Definition at line 2087 of file integer.cc.
|
delete |
This type is neither copyable nor movable.
|
finaldefault |
void operations_research::sat::GenericLiteralWatcher::AlwaysCallAtLevelZero | ( | int | id | ) |
Whether we call a propagator even if its watched variables didn't change. This is only used when we are back to level zero. This was introduced for the LP propagator where we might need to continue an interrupted solve or add extra cuts at level zero.
Definition at line 2370 of file integer.cc.
void operations_research::sat::GenericLiteralWatcher::CallOnNextPropagate | ( | int | id | ) |
Add the given propagator to its queue.
Definition at line 2108 of file integer.cc.
|
inline |
Returns the id of the propagator we are currently calling. This is meant to be used from inside Propagate() in case a propagator was registered more than once at different priority for instance.
void operations_research::sat::GenericLiteralWatcher::NotifyThatPropagatorMayNotReachFixedPointInOnePass | ( | int | id | ) |
The default behavior is to assume that a propagator does not need to be called twice in a row. However, propagators on which this is called will be called again if they change one of their own watched variables.
Definition at line 2365 of file integer.cc.
|
inline |
|
delete |
|
finalvirtual |
On propagate, the registered propagators will be called if they need to until a fixed point is reached. Propagators with low ids will tend to be called first, but it ultimately depends on their "waking" order.
Only once per call to Propagate(), if we are at level zero, we might want to call propagators even if the bounds didn't change.
Increase the deterministic time depending on some basic fact about our propagation.
We test the time limit from time to time. This is in order to return in case of slow propagation.
Before we propagate, make sure any reversible structure are up to date.
This is needed to detect if the propagator propagated anything or not.
Update the propagation queue. At this point, the propagator has been removed from the queue but in_queue_ is still true.
If the propagator is assumed to be idempotent, then we set in_queue_ to false after UpdateCallingNeeds() so this later function will never add it back.
Otherwise, we set in_queue_ to false first so that UpdateCallingNeeds() may add it back if the propagator modified any of its watched variables.
If the propagator pushed a literal, we exit in order to rerun all SAT only propagators first. Note that since a literal was pushed we are guaranteed to be called again, and we will resume from priority 0.
Important: for now we need to re-run the clauses propagator each time we push a new literal because some propagator like the arc consistent all diff relies on this.
If the propagator pushed an integer bound, we revert to priority = 0.
We wait until we reach the fix point before calling the callback.
Implements operations_research::sat::SatPropagator.
Definition at line 2155 of file integer.cc.
int operations_research::sat::GenericLiteralWatcher::Register | ( | PropagatorInterface * | propagator | ) |
Registers a propagator and returns its unique ids.
Call this propagator at least once the next time Propagate() is called.
Definition at line 2332 of file integer.cc.
|
inline |
Set a callback for new variable bounds at level 0.
This will be called (only at level zero) with the list of IntegerVariable with changed lower bounds. Note that it might be called more than once during the same propagation cycle if we fix variables in "stages".
Also note that this will be called if some BooleanVariable where fixed even if no IntegerVariable are changed, so the passed vector to the function might be empty.
void operations_research::sat::GenericLiteralWatcher::RegisterReversibleClass | ( | int | id, |
ReversibleInterface * | rev ) |
Registers a reversible class with a given propagator. This class will be changed to the correct state just before the propagator is called.
Doing it just before should minimize cache-misses and bundle as much as possible the "backtracking" together. Many propagators only watches a few variables and will not be called at each decision levels.
Definition at line 2374 of file integer.cc.
void operations_research::sat::GenericLiteralWatcher::RegisterReversibleInt | ( | int | id, |
int * | rev ) |
Registers a reversible int with a given propagator. The int will be changed to its correct value just before Propagate() is called.
Alternatively, one can directly get the underlying RevRepository<int> with a call to model.Get<>(), and use SaveWithStamp() before each modification to have just a slight overhead per int updates. This later option is what is usually done in a CP solver at the cost of a slightly more complex API.
Definition at line 2380 of file integer.cc.
void operations_research::sat::GenericLiteralWatcher::ReserveSpaceForNumVariables | ( | int | num_vars | ) |
Memory optimization: you can call this before registering watchers.
Definition at line 2104 of file integer.cc.
void operations_research::sat::GenericLiteralWatcher::SetPropagatorPriority | ( | int | id, |
int | priority ) |
Changes the priority of the propagator with given id. The priority is a non-negative integer. Propagators with a lower priority will always be run before the ones with a higher one. The default priority is one.
Definition at line 2358 of file integer.cc.
|
inline |
This will be called not too often during propagation (when we finish propagating one priority). If it returns true, we will stop propagation there. It is used by LbTreeSearch as we can stop as soon as the objective lower bound crossed a threshold and do not need to call expensive propagator when this is the case.
|
inline |
A simple form of incremental update is to maintain state as we dive into the search tree but forget everything on every backtrack. A propagator can be called many times by decision, so this can make a large proportion of the calls incremental.
This allows to achieve this with a really low overhead.
The propagator can define a bool rev_is_in_dive_ = false; and at the beginning of each propagate do: const bool no_backtrack_since_last_call = rev_is_in_dive_; watcher_->SetUntilNextBacktrack(&rev_is_in_dive_);
|
finalvirtual |
Reverts the state so that all the literals with a trail index greater or equal to the given one are not processed for propagation. Note that the trail current decision level is already reverted before this is called.
Nothing to do since we found a conflict before Propagate() was called.
The assumption is not always true if we are currently aborting.
We need to clear the watch indices on untrail.
This means that we already propagated all there is to propagate at the level trail_index, so we can safely clear modified_vars_ in case it wasn't already done.
Reimplemented from operations_research::sat::SatPropagator.
Definition at line 2297 of file integer.cc.
|
inline |
|
inline |
|
inline |
|
inline |
Watches the corresponding quantity. The propagator with given id will be called if it changes. Note that WatchLiteral() only trigger when the literal becomes true.
If watch_index is specified, it is associated with the watched literal. Doing this will cause IncrementalPropagate() to be called (see the documentation of this interface for more detail).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |