Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <linear_constraint_storage.h>
Classes | |
struct | Diff |
struct | UpdateResult |
Public Member Functions | |
LinearConstraintId | Add (double lower_bound, double upper_bound, absl::string_view name) |
double | lower_bound (LinearConstraintId id) const |
double | upper_bound (LinearConstraintId id) const |
const std::string & | name (LinearConstraintId id) const |
template<typename DiffIter > | |
void | set_lower_bound (LinearConstraintId id, double lower_bound, const iterator_range< DiffIter > &diffs) |
template<typename DiffIter > | |
void | set_upper_bound (LinearConstraintId id, double upper_bound, const iterator_range< DiffIter > &diffs) |
template<typename DiffIter > | |
void | Delete (LinearConstraintId id, const iterator_range< DiffIter > &diffs) |
int64_t | size () const |
LinearConstraintId | next_id () const |
void | ensure_next_id_at_least (LinearConstraintId minimum) |
Sets the next variable id to be the maximum of next_id() and minimum . | |
bool | contains (LinearConstraintId id) const |
Returns true if this id has been created and not yet deleted. | |
std::vector< LinearConstraintId > | LinearConstraints () const |
The LinearConstraintsIds in use (not deleted), order not defined. | |
std::vector< LinearConstraintId > | SortedLinearConstraints () const |
template<typename DiffIter > | |
void | DeleteVariable (VariableId variable, const iterator_range< DiffIter > &diffs) |
Removes all occurrences of var from the constraint matrix. | |
template<typename DiffIter > | |
void | set_term (LinearConstraintId constraint, VariableId variable, double value, const iterator_range< DiffIter > &diffs) |
Setting value=0 deletes the key from the matrix. | |
const SparseMatrix< LinearConstraintId, VariableId > & | matrix () const |
The matrix of coefficients for the linear terms in the constraints. | |
std::pair< LinearConstraintsProto, SparseDoubleMatrixProto > | Proto () const |
Returns an equivalent proto of this . | |
bool | diff_is_empty (const Diff &diff) const |
UpdateResult | Update (const Diff &diff, const absl::flat_hash_set< VariableId > &deleted_variables, absl::Span< const VariableId > new_variables) const |
void | AdvanceCheckpointInDiff (VariableId variable_checkpoint, Diff &diff) const |
Updates the checkpoint and clears all stored changes in diff. | |
In memory representation of the linear constraints of an optimization model.
The setter functions all accept a DiffIter
, which must be an iterator over non-const references to LinearConstraintStorage::Diff. These functions will modify the LinearConstraintStorage::Diff objects.
Definition at line 45 of file linear_constraint_storage.h.
LinearConstraintId operations_research::math_opt::LinearConstraintStorage::Add | ( | double | lower_bound, |
double | upper_bound, | ||
absl::string_view | name ) |
Adds a linear constraint to the model and returns its id.
The returned ids begin at zero and strictly increase (in particular, if ensure_next_id_at_least() is not used, they will be consecutive). Deleted ids are NOT reused.
Definition at line 36 of file linear_constraint_storage.cc.
void operations_research::math_opt::LinearConstraintStorage::AdvanceCheckpointInDiff | ( | VariableId | variable_checkpoint, |
Diff & | diff ) const |
Updates the checkpoint and clears all stored changes in diff.
Definition at line 113 of file linear_constraint_storage.cc.
|
inline |
Returns true if this id has been created and not yet deleted.
Definition at line 293 of file linear_constraint_storage.h.
void operations_research::math_opt::LinearConstraintStorage::Delete | ( | LinearConstraintId | id, |
const iterator_range< DiffIter > & | diffs ) |
Removes a linear constraint from the model.
It is an error to use a deleted linear constraint id as input to any subsequent function calls on the model.
if the constraint >= checkpoint_, we don't store any info.
Definition at line 246 of file linear_constraint_storage.h.
void operations_research::math_opt::LinearConstraintStorage::DeleteVariable | ( | VariableId | variable, |
const iterator_range< DiffIter > & | diffs ) |
Removes all occurrences of var from the constraint matrix.
Definition at line 267 of file linear_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 313 of file linear_constraint_storage.h.
|
inline |
Sets the next variable id to be the maximum of next_id() and minimum
.
Definition at line 288 of file linear_constraint_storage.h.
std::vector< LinearConstraintId > operations_research::math_opt::LinearConstraintStorage::LinearConstraints | ( | ) | const |
The LinearConstraintsIds in use (not deleted), order not defined.
Definition at line 47 of file linear_constraint_storage.cc.
|
inline |
Inline function implementation
Definition at line 200 of file linear_constraint_storage.h.
|
inline |
The matrix of coefficients for the linear terms in the constraints.
Definition at line 139 of file linear_constraint_storage.h.
|
inline |
Definition at line 208 of file linear_constraint_storage.h.
|
inline |
The returned id of the next call to AddLinearConstraint.
Equal to the number of linear constraints created.
Definition at line 286 of file linear_constraint_storage.h.
std::pair< LinearConstraintsProto, SparseDoubleMatrixProto > operations_research::math_opt::LinearConstraintStorage::Proto | ( | ) | const |
Returns an equivalent proto of this
.
Definition at line 76 of file linear_constraint_storage.cc.
void operations_research::math_opt::LinearConstraintStorage::set_lower_bound | ( | LinearConstraintId | id, |
double | lower_bound, | ||
const iterator_range< DiffIter > & | diffs ) |
Definition at line 214 of file linear_constraint_storage.h.
void operations_research::math_opt::LinearConstraintStorage::set_term | ( | LinearConstraintId | constraint, |
VariableId | variable, | ||
double | value, | ||
const iterator_range< DiffIter > & | diffs ) |
Setting value=0 deletes the key from the matrix.
Definition at line 298 of file linear_constraint_storage.h.
void operations_research::math_opt::LinearConstraintStorage::set_upper_bound | ( | LinearConstraintId | id, |
double | upper_bound, | ||
const iterator_range< DiffIter > & | diffs ) |
Definition at line 230 of file linear_constraint_storage.h.
|
inline |
The number of linear constraints in the model.
Equal to the number of linear constraints created minus the number of linear constraints deleted.
Definition at line 282 of file linear_constraint_storage.h.
std::vector< LinearConstraintId > operations_research::math_opt::LinearConstraintStorage::SortedLinearConstraints | ( | ) | const |
Returns a sorted vector of all existing (not deleted) linear constraints in the model.
Runs in O(n log(n)), where n is the number of linear constraints returned.
Definition at line 57 of file linear_constraint_storage.cc.
LinearConstraintStorage::UpdateResult operations_research::math_opt::LinearConstraintStorage::Update | ( | const Diff & | diff, |
const absl::flat_hash_set< VariableId > & | deleted_variables, | ||
absl::Span< const VariableId > | new_variables ) const |
Definition at line 124 of file linear_constraint_storage.cc.
|
inline |
Definition at line 204 of file linear_constraint_storage.h.