![]() |
Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
|
Storage for a "mapped" constraint type whose only supported updates are constraint addition, and variable or constraint deletion.
The constraints are "atomic" in the sense that they can be added or deleted individually, but direct data updates (e.g., to coefficients) are not permitted. Note that they are not strictly immutable, though, as variable deletions may have side effects (e.g., a constraint considers a deleted variable as implicitly fixed to zero).
Implementers of new constraint families should provide a conforming ConstraintData definition, along with a template specialization of AtomicConstraintTraits (defined below). These should likely be placed in math_opt/constraints/$new_constraint_family/storage.h.
The ConstraintData parameter should refer to a class to represent a single constraint in memory. It must satisfy a duck-typed interface:
A member function to return all variables involved in the constraint: std::vector<VariableId> RelatedVariables() const;
The setter functions all accept a DiffIter, which must be an iterator over non-const references to AtomicConstraintStorage<ConstraintData>::Diff. These functions will modify the diff objects.
Definition at line 70 of file atomic_constraint_storage.h.
#include <atomic_constraint_storage.h>
Classes | |
struct | Diff |
Public Types | |
using | IdType = typename ConstraintData::IdType |
using | ProtoType = typename ConstraintData::ProtoType |
using | UpdatesProtoType = typename ConstraintData::UpdatesProtoType |
Public Member Functions | |
IdType | AddConstraint (ConstraintData constraint) |
Add a single constraint to the storage. | |
void | AddConstraints (const google::protobuf::Map< int64_t, ProtoType > &constraints) |
template<typename DiffIter> | |
void | Delete (IdType id, const iterator_range< DiffIter > &diffs) |
Delete a single constraint. | |
void | DeleteVariable (VariableId variable_id) |
Delete a single variable from each constraint in the storage. | |
int64_t | size () const |
IdType | next_id () const |
The smallest ID which is valid for a new constraint. | |
void | ensure_next_id_at_least (const IdType minimum) |
Sets the next variable id to be the maximum of next_id() and minimum. | |
bool | contains (const IdType id) const |
Returns true if this id has been created and not yet deleted. | |
const absl::flat_hash_set< IdType > & | RelatedConstraints (const VariableId variable_id) const |
std::vector< IdType > | Constraints () const |
The ids in use (not deleted). The order is not defined. | |
std::vector< IdType > | SortedConstraints () const |
google::protobuf::Map< int64_t, ProtoType > | Proto () const |
Returns a proto representation of the constraint class. | |
const ConstraintData & | data (const IdType id) const |
bool | diff_is_empty (const Diff &diff) const |
ConstraintData::UpdatesProtoType | Update (const Diff &diff) const |
Return a proto representation of the current update. | |
void | AdvanceCheckpointInDiff (Diff &diff) const |
Updates the checkpoint and clears all stored changes in diff. |
using operations_research::math_opt::AtomicConstraintStorage< ConstraintData >::IdType = typename ConstraintData::IdType |
Definition at line 72 of file atomic_constraint_storage.h.
using operations_research::math_opt::AtomicConstraintStorage< ConstraintData >::ProtoType = typename ConstraintData::ProtoType |
Definition at line 73 of file atomic_constraint_storage.h.
using operations_research::math_opt::AtomicConstraintStorage< ConstraintData >::UpdatesProtoType = typename ConstraintData::UpdatesProtoType |
Definition at line 74 of file atomic_constraint_storage.h.
AtomicConstraintStorage< ConstraintData >::IdType operations_research::math_opt::AtomicConstraintStorage< ConstraintData >::AddConstraint | ( | ConstraintData | constraint | ) |
Add a single constraint to the storage.
Inlined implementations
Definition at line 192 of file atomic_constraint_storage.h.
void operations_research::math_opt::AtomicConstraintStorage< ConstraintData >::AddConstraints | ( | const google::protobuf::Map< int64_t, ProtoType > & | constraints | ) |
Adds a collection of constraints to the storage, from an "id-to-proto" map. The keys for the input map will be used as the associated IDs in storage.
Will CHECK-fail if any ID is less than next_id().
Definition at line 205 of file atomic_constraint_storage.h.
void operations_research::math_opt::AtomicConstraintStorage< ConstraintData >::AdvanceCheckpointInDiff | ( | Diff & | diff | ) | const |
Updates the checkpoint and clears all stored changes in diff.
Definition at line 274 of file atomic_constraint_storage.h.
std::vector< typename AtomicConstraintStorage< ConstraintData >::IdType > operations_research::math_opt::AtomicConstraintStorage< ConstraintData >::Constraints | ( | ) | const |
The ids in use (not deleted). The order is not defined.
Definition at line 251 of file atomic_constraint_storage.h.
|
inline |
Returns true if this id has been created and not yet deleted.
Definition at line 119 of file atomic_constraint_storage.h.
|
inline |
Returns the underlying data for constraint id. Will crash if id is not present (i.e., if contains(id) returns false).
Definition at line 146 of file atomic_constraint_storage.h.
void operations_research::math_opt::AtomicConstraintStorage< ConstraintData >::Delete | ( | IdType | id, |
const iterator_range< DiffIter > & | diffs ) |
Delete a single constraint.
if the constraint >= checkpoint_, we don't store any info.
Definition at line 219 of file atomic_constraint_storage.h.
void operations_research::math_opt::AtomicConstraintStorage< ConstraintData >::DeleteVariable | ( | VariableId | variable_id | ) |
Delete a single variable from each constraint in the storage.
Definition at line 237 of file atomic_constraint_storage.h.
|
inline |
Functions for working with Diff Returns true if there are no changes (tracked changes before the checkpoint or new constraints after the checkpoint).
Definition at line 268 of file atomic_constraint_storage.h.
|
inline |
Sets the next variable id to be the maximum of next_id() and minimum.
Definition at line 114 of file atomic_constraint_storage.h.
|
inline |
The smallest ID which is valid for a new constraint.
Definition at line 111 of file atomic_constraint_storage.h.
|
inline |
Returns a proto representation of the constraint class.
Definition at line 136 of file atomic_constraint_storage.h.
|
inline |
Definition at line 121 of file atomic_constraint_storage.h.
|
inline |
The number of constraints stored (includes everything created and not yet deleted).
Definition at line 108 of file atomic_constraint_storage.h.
std::vector< typename AtomicConstraintStorage< ConstraintData >::IdType > operations_research::math_opt::AtomicConstraintStorage< ConstraintData >::SortedConstraints | ( | ) | const |
Returns a sorted vector of all existing (not deleted) constraints in the model.
Runs in O(n log(n)), where n is the number of constraints returned.
Definition at line 261 of file atomic_constraint_storage.h.
ConstraintData::UpdatesProtoType operations_research::math_opt::AtomicConstraintStorage< ConstraintData >::Update | ( | const Diff & | diff | ) | const |
Return a proto representation of the current update.
Definition at line 282 of file atomic_constraint_storage.h.