C++ Reference: class GenericLiteralWatcher

Note: This documentation is automatically generated.

This class allows registering Propagator that will be called if a watched Literal or LbVar changes.

TODO(user): Move this to its own file. Add unit tests!
Method
AlwaysCallAtLevelZero

Return type: void

Arguments: 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.

GenericLiteralWatcher

Return type: explicit

Arguments: Model* model

~GenericLiteralWatcher

GetCurrentId

Return type: int

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.

NotifyThatPropagatorMayNotReachFixedPointInOnePass

Return type: void

Arguments: 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.

NumPropagators

Return type: int

Returns the number of registered propagators.

Propagate

Return type: bool

Arguments: Trail* trail

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.

Register

Return type: int

Arguments: PropagatorInterface* propagator

Registers a propagator and returns its unique ids.

RegisterLevelZeroModifiedVariablesCallback

Return type: void

Arguments: const std::function<void(const std::vector<IntegerVariable>&)> cb

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.

RegisterReversibleClass

Return type: void

Arguments: 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.

RegisterReversibleInt

Return type: void

Arguments: 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. Note that this will work in O(num_rev_int_of_propagator_id) per call to Propagate() and happens at most once per decision level. As such this is meant for classes that have just a few reversible ints or that will have a similar complexity anyway. Alternatively, one can directly get the underlying RevRepository 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 sligthly more complex API.

SetPropagatorPriority

Return type: void

Arguments: 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.

SetStopPropagationCallback

Return type: void

Arguments: std::function<bool()> callback

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.

Untrail

Return type: void

Arguments: const Trail& trail, int literal_trail_index

WatchAffineExpression

Return type: void

Arguments: AffineExpression e, int id

WatchIntegerVariable

Return type: void

Arguments: IntegerVariable i, int id, int watch_index = -1

WatchIntegerVariable

Return type: void

Arguments: IntegerValue v, int id

WatchLiteral

Return type: void

Arguments: Literal l, int id, int watch_index = -1

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).

WatchLowerBound

Return type: void

Arguments: IntegerVariable var, int id, int watch_index = -1

WatchLowerBound

Return type: void

Arguments: AffineExpression e, int id

Because the coeff is always positive, whatching an affine expression is the same as watching its var.

WatchLowerBound

Return type: void

Arguments: IntegerValue i, int id

No-op overload for "constant" IntegerVariable that are sometimes templated as an IntegerValue.

WatchUpperBound

Return type: void

Arguments: IntegerVariable var, int id, int watch_index = -1

WatchUpperBound

Return type: void

Arguments: AffineExpression e, int id

WatchUpperBound

Return type: void

Arguments: IntegerValue i, int id