Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <linear_propagation.h>
Public Member Functions | |
LinearPropagator (Model *model) | |
~LinearPropagator () override | |
bool | Propagate () final |
void | SetLevel (int level) final |
bool | AddConstraint (absl::Span< const Literal > enforcement_literals, absl::Span< const IntegerVariable > vars, absl::Span< const IntegerValue > coeffs, IntegerValue upper_bound) |
Adds a new constraint to the propagator. | |
void | Explain (int id, IntegerValue propagation_slack, IntegerVariable var_to_explain, int trail_index, std::vector< Literal > *literals_reason, std::vector< int > *trail_indices_reason) final |
For LazyReasonInterface. | |
Public Member Functions inherited from operations_research::sat::PropagatorInterface | |
PropagatorInterface ()=default | |
virtual | ~PropagatorInterface ()=default |
virtual bool | IncrementalPropagate (const std::vector< int > &) |
This is meant to supersede both IntegerSumLE and the PrecedencePropagator.
Definition at line 300 of file linear_propagation.h.
|
explicit |
Definition at line 358 of file linear_propagation.cc.
|
override |
Definition at line 382 of file linear_propagation.cc.
bool operations_research::sat::LinearPropagator::AddConstraint | ( | absl::Span< const Literal > | enforcement_literals, |
absl::Span< const IntegerVariable > | vars, | ||
absl::Span< const IntegerValue > | coeffs, | ||
IntegerValue | upper_bound ) |
Adds a new constraint to the propagator.
Adds a new constraint to the propagator. We support adding constraint at a positive level:
Make sure max_variations_ is of correct size.
Initialize constraint data.
Initialize watchers. Initialy we want everything to be propagated at least once.
When a conditional precedence becomes enforced, add it.
Transposed graph to know which constraint to wake up.
We need both the var entry and its negation to be allocated.
We need to be registered to the watcher so Propagate() is called at the proper priority. But then we rely on modified_vars_.
Propagate this new constraint.
Definition at line 576 of file linear_propagation.cc.
|
finalvirtual |
For LazyReasonInterface.
Implements operations_research::sat::LazyReasonInterface.
Definition at line 888 of file linear_propagation.cc.
|
finalvirtual |
This will be called after one or more literals that are watched by this propagator changed. It will also always be called on the first propagation cycle after registration.
Initial addition.
We will clear modified_vars_ on exit since everything we propagate here is handled by PropagateOneConstraint().
Cleanup.
We abort this propagator as soon as a Boolean is propagated, so that we always finish the Boolean propagation first. This can happen when we push a bound that has associated Booleans or push enforcement to false. The idea is to resume from our current state when we are called again. Note however that we have to clear the propagated_by_ info has other propagator might have pushed the same variable further.
We always process the whole queue in FIFO order.
This is either a conflict or an enforcement propagation. We do it right away.
We abort after the first pushed boolean. We could abort later too, it is unclear what works best.
We can probably save the AnalyzeConstraint() cost, but then we only do that when the constraint propagate, and the context might have change since we computed it above.
Implements operations_research::sat::PropagatorInterface.
Definition at line 472 of file linear_propagation.cc.
|
finalvirtual |
Initially a reversible class starts at level zero. Increasing the level saves the state of the current old level. Decreasing the level restores the state to what it was at this level and all higher levels are forgotten. Everything done at level zero cannot be backtracked over.
The level is assumed to be non-negative.
If the solver backtracked at any point, we invalidate all our queue and propagated_by information.
Tricky: if we aborted the current propagation because we pushed a Boolean, by default, the GenericLiteralWatcher will only call Propagate() again if one of the watched variable changed. With this, it is guaranteed to call it again if it wasn't in the queue already.
Implements operations_research::ReversibleInterface.
Definition at line 406 of file linear_propagation.cc.