Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <integer_expr.h>
Public Member Functions | |
LinearConstraintPropagator (absl::Span< const Literal > enforcement_literals, absl::Span< const IntegerVariable > vars, absl::Span< const IntegerValue > coeffs, IntegerValue upper_bound, Model *model) | |
LinearConstraintPropagator (LinearConstraint ct, Model *model) | |
bool | Propagate () final |
void | RegisterWith (GenericLiteralWatcher *watcher) |
bool | PropagateAtLevelZero () |
std::pair< IntegerValue, IntegerValue > | ConditionalLb (IntegerLiteral integer_literal, IntegerVariable target_var) const |
NOTE(user): This is only used with int128, so we code only a single version. | |
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 > &) |
A really basic implementation of an upper-bounded sum of integer variables. The complexity is in O(num_variables) at each propagation.
Definition at line 67 of file integer_expr.h.
operations_research::sat::LinearConstraintPropagator< use_int128 >::LinearConstraintPropagator | ( | absl::Span< const Literal > | enforcement_literals, |
absl::Span< const IntegerVariable > | vars, | ||
absl::Span< const IntegerValue > | coeffs, | ||
IntegerValue | upper_bound, | ||
Model * | model ) |
If refied_literal is kNoLiteralIndex then this is a normal constraint, otherwise we enforce the implication refied_literal => constraint is true.
Copy data.
Handle negative coefficients.
Literal reason will only be used with the negation of enforcement_literals. It will stay constant. We also do not store enforcement_literals, but retrieve them from there.
Initialize the reversible numbers.
Definition at line 46 of file integer_expr.cc.
operations_research::sat::LinearConstraintPropagator< use_int128 >::LinearConstraintPropagator | ( | LinearConstraint | ct, |
Model * | model ) |
This version allow to std::move the memory from the LinearConstraint directly. It Only uses the upper bound. Id does not support enforcement_literals.
Handle negative coefficients.
Initialize the reversible numbers.
Definition at line 87 of file integer_expr.cc.
std::pair< IntegerValue, IntegerValue > operations_research::sat::LinearConstraintPropagator< use_int128 >::ConditionalLb | ( | IntegerLiteral | integer_literal, |
IntegerVariable | target_var ) const |
NOTE(user): This is only used with int128, so we code only a single version.
This is a pretty usage specific function. Returns the implied lower bound on target_var if the given integer literal is false (resp. true). If the variables do not appear both in the linear inequality, this returns two kMinIntegerValue.
The code below is wrong if integer_literal and target_var are the same. In this case we return the trivial bounds.
Recall that all our coefficient are positive.
The upper bound on NegationOf(target_var) are lb(-target) + slack / coeff. So the lower bound on target_var is ub - slack / coeff.
A literal means var >= bound.
We have var_coeff * var in the expression, the literal is var >= bound. When it is false, it is not relevant as implied_lb used var >= lb. When it is true, the diff is bound - lb.
We have var_coeff * -var in the expression, the literal is var >= bound. When it is true, it is not relevant as implied_lb used -var >= -ub. And when it is false it means var < bound, so -var >= -bound + 1
Definition at line 139 of file integer_expr.cc.
|
finalvirtual |
For LazyReasonInterface.
Implements operations_research::sat::LazyReasonInterface.
Definition at line 231 of file integer_expr.cc.
|
finalvirtual |
We propagate:
Reified case: If any of the enforcement_literals are false, we ignore the constraint.
Unfortunately, we can't propagate anything if we have more than one unassigned enforcement literal.
Compute the new lower bound and update the reversible structures.
Update the set of fixed variables.
Save the current sum of fixed variables.
If use_int128 is true, the slack or propagation slack can be larger than this. To detect overflow with capped arithmetic, it is important the slack used in our algo never exceed this value.
Conflict?
It is fine if we don't relax as much as possible.
Propagate the only non-true literal to false.
We can only propagate more if all the enforcement literals are true.
The lower bound of all the variables except one can be used to update the upper bound of the last one.
Implements operations_research::sat::PropagatorInterface.
Definition at line 259 of file integer_expr.cc.
bool operations_research::sat::LinearConstraintPropagator< use_int128 >::PropagateAtLevelZero | ( | ) |
Same as Propagate() but only consider current root level bounds. This is mainly useful for the LP propagator since it can find relevant optimal really late in the search tree.
Compute the new lower bound and update the reversible structures.
Conflict?
The lower bound of all the variables except one can be used to update the upper bound of the last one.
Definition at line 398 of file integer_expr.cc.
void operations_research::sat::LinearConstraintPropagator< use_int128 >::RegisterWith | ( | GenericLiteralWatcher * | watcher | ) |
We only watch the true direction.
Definition at line 467 of file integer_expr.cc.