Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <pb_constraint.h>
Public Member Functions | |
PbConstraints (Model *model) | |
PbConstraints (const PbConstraints &)=delete | |
This type is neither copyable nor movable. | |
PbConstraints & | operator= (const PbConstraints &)=delete |
~PbConstraints () override | |
bool | Propagate (Trail *trail) final |
void | Untrail (const Trail &trail, int trail_index) final |
absl::Span< const Literal > | Reason (const Trail &trail, int trail_index, int64_t conflict_id) const final |
void | Resize (int num_variables) |
Changes the number of variables. | |
bool | AddConstraint (const std::vector< LiteralWithCoeff > &cst, Coefficient rhs, Trail *trail) |
bool | AddLearnedConstraint (const std::vector< LiteralWithCoeff > &cst, Coefficient rhs, Trail *trail) |
int | NumberOfConstraints () const |
Returns the number of constraints managed by this class. | |
bool | IsEmpty () const final |
void | ClearConflictingConstraint () |
UpperBoundedLinearConstraint * | ConflictingConstraint () |
UpperBoundedLinearConstraint * | ReasonPbConstraint (int trail_index) const |
void | BumpActivity (UpperBoundedLinearConstraint *constraint) |
void | RescaleActivities (double scaling_factor) |
void | UpdateActivityIncrement () |
void | DeleteConstraint (int index) |
Only used for testing. | |
int64_t | num_constraint_lookups () const |
Some statistics. | |
int64_t | num_inspected_constraint_literals () const |
int64_t | num_threshold_updates () const |
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 |
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. | |
Additional Inherited Members | |
Protected Attributes inherited from operations_research::sat::SatPropagator | |
const std::string | name_ |
int | propagator_id_ |
int | propagation_trail_index_ |
Class responsible for managing a set of pseudo-Boolean constraints and their propagation.
Definition at line 528 of file pb_constraint.h.
|
inlineexplicit |
Definition at line 530 of file pb_constraint.h.
|
delete |
This type is neither copyable nor movable.
|
inlineoverride |
Definition at line 546 of file pb_constraint.h.
bool operations_research::sat::PbConstraints::AddConstraint | ( | const std::vector< LiteralWithCoeff > & | cst, |
Coefficient | rhs, | ||
Trail * | trail ) |
Adds a constraint in canonical form to the set of managed constraints. Note that this detects constraints with exactly the same terms. In this case, the constraint rhs is updated if the new one is lower or nothing is done otherwise.
There are some preconditions, and the function will return false if they are not met. The constraint can be added when the trail is not empty, however given the current propagated assignment:
The constraint cannot have propagated at an earlier decision level.
Special case if this is the first constraint.
Optimization if the constraint terms are duplicates.
The constraint is redundant, so there is nothing to do.
Definition at line 837 of file pb_constraint.cc.
bool operations_research::sat::PbConstraints::AddLearnedConstraint | ( | const std::vector< LiteralWithCoeff > & | cst, |
Coefficient | rhs, | ||
Trail * | trail ) |
Same as AddConstraint(), but also marks the added constraint as learned so that it can be deleted during the constraint cleanup phase.
The second test is to avoid marking a problem constraint as learned because of the "reuse last constraint" optimization.
Definition at line 898 of file pb_constraint.cc.
void operations_research::sat::PbConstraints::BumpActivity | ( | UpperBoundedLinearConstraint * | constraint | ) |
Activity update functions.
Definition at line 1081 of file pb_constraint.cc.
|
inline |
ConflictingConstraint() returns the last PB constraint that caused a conflict. Calling ClearConflictingConstraint() reset this to nullptr.
Definition at line 597 of file pb_constraint.h.
|
inline |
Definition at line 598 of file pb_constraint.h.
|
inline |
Only used for testing.
Definition at line 614 of file pb_constraint.h.
|
inlinefinalvirtual |
Small optimization: If a propagator does not contain any "constraints" there is no point calling propagate on it. Before each propagation, the solver will checks for emptiness, and construct an optimized list of propagator before looping many time over the list.
Reimplemented from operations_research::sat::SatPropagator.
Definition at line 590 of file pb_constraint.h.
|
inline |
Some statistics.
Definition at line 620 of file pb_constraint.h.
|
inline |
Definition at line 621 of file pb_constraint.h.
|
inline |
Definition at line 624 of file pb_constraint.h.
|
inline |
Returns the number of constraints managed by this class.
Definition at line 589 of file pb_constraint.h.
|
delete |
|
finalvirtual |
Inspects the trail from propagation_trail_index_ until at least one literal is propagated. Returns false iff a conflict is detected (in which case trail->SetFailingClause() must be called).
This must update propagation_trail_index_ so that all the literals before it have been propagated. In particular, if nothing was propagated, then PropagationIsDone() must return true.
Implements operations_research::sat::SatPropagator.
Definition at line 948 of file pb_constraint.cc.
|
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 979 of file pb_constraint.cc.
UpperBoundedLinearConstraint * operations_research::sat::PbConstraints::ReasonPbConstraint | ( | int | trail_index | ) | const |
Returns the underlying UpperBoundedLinearConstraint responsible for assigning the literal at given trail index.
Definition at line 991 of file pb_constraint.cc.
void operations_research::sat::PbConstraints::RescaleActivities | ( | double | scaling_factor | ) |
Definition at line 1091 of file pb_constraint.cc.
|
inline |
Changes the number of variables.
Definition at line 560 of file pb_constraint.h.
|
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.
Only the constraints which were inspected during Propagate() need inspection during Untrail().
Reimplemented from operations_research::sat::SatPropagator.
Definition at line 956 of file pb_constraint.cc.
void operations_research::sat::PbConstraints::UpdateActivityIncrement | ( | ) |
Definition at line 1098 of file pb_constraint.cc.