Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::math_opt::VariableStorage Class Reference

#include <variable_storage.h>

Classes

struct  Diff
 
struct  UpdateResult
 

Public Member Functions

VariableId Add (double lower_bound, double upper_bound, bool is_integer, absl::string_view name)
 
double lower_bound (VariableId id) const
 
double upper_bound (VariableId id) const
 
bool is_integer (VariableId id) const
 
const std::string & name (VariableId id) const
 
template<typename DiffIter >
void set_lower_bound (VariableId id, double lower_bound, const iterator_range< DiffIter > &diffs)
 
template<typename DiffIter >
void set_upper_bound (VariableId id, double upper_bound, const iterator_range< DiffIter > &diffs)
 
template<typename DiffIter >
void set_integer (VariableId id, bool is_integer, const iterator_range< DiffIter > &diffs)
 
template<typename DiffIter >
void Delete (VariableId id, const iterator_range< DiffIter > &diffs)
 
int64_t size () const
 
VariableId next_id () const
 
void ensure_next_id_at_least (VariableId minimum)
 Sets the next variable id to be the maximum of next_id() and minimum.
 
bool contains (VariableId id) const
 Returns true if this id has been created and not yet deleted.
 
std::vector< VariableId > Variables () const
 The VariableIds in use (not deleted), order not defined.
 
std::vector< VariableId > SortedVariables () const
 
VariablesProto Proto () const
 An equivalent proto of this.
 
bool diff_is_empty (const Diff &diff) const
 
UpdateResult Update (const Diff &diff) const
 
void AdvanceCheckpointInDiff (Diff &diff) const
 Updates the checkpoint and clears all stored changes in diff.
 
std::vector< VariableId > VariablesFrom (VariableId start) const
 

Detailed Description

The in memory representation of the variables of an optimization model.

The setter functions all accept a DiffIter, which must be an iterator over non-const references to VariableStorage::Diff. These functions will modify the VariableStorage::Diff objects.

Definition at line 39 of file variable_storage.h.

Member Function Documentation

◆ Add()

VariableId operations_research::math_opt::VariableStorage::Add ( double lower_bound,
double upper_bound,
bool is_integer,
absl::string_view name )

Adds a variable 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 32 of file variable_storage.cc.

◆ AdvanceCheckpointInDiff()

void operations_research::math_opt::VariableStorage::AdvanceCheckpointInDiff ( Diff & diff) const

Updates the checkpoint and clears all stored changes in diff.

Definition at line 90 of file variable_storage.cc.

◆ contains()

bool operations_research::math_opt::VariableStorage::contains ( VariableId id) const
inline

Returns true if this id has been created and not yet deleted.

Definition at line 251 of file variable_storage.h.

◆ Delete()

template<typename DiffIter >
void operations_research::math_opt::VariableStorage::Delete ( VariableId id,
const iterator_range< DiffIter > & diffs )

Removes a variable from the model.

It is an error to use a deleted variable id as input to any subsequent function calls on this.

Definition at line 229 of file variable_storage.h.

◆ diff_is_empty()

bool operations_research::math_opt::VariableStorage::diff_is_empty ( const Diff & diff) const
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 255 of file variable_storage.h.

◆ ensure_next_id_at_least()

void operations_research::math_opt::VariableStorage::ensure_next_id_at_least ( VariableId minimum)
inline

Sets the next variable id to be the maximum of next_id() and minimum.

Definition at line 247 of file variable_storage.h.

◆ is_integer()

bool operations_research::math_opt::VariableStorage::is_integer ( VariableId id) const
inline

Definition at line 175 of file variable_storage.h.

◆ lower_bound()

double operations_research::math_opt::VariableStorage::lower_bound ( VariableId id) const
inline

Inline functions

Definition at line 167 of file variable_storage.h.

◆ name()

const std::string & operations_research::math_opt::VariableStorage::name ( VariableId id) const
inline

Definition at line 179 of file variable_storage.h.

◆ next_id()

VariableId operations_research::math_opt::VariableStorage::next_id ( ) const
inline

The returned id of the next call to AddVariable.

Equal to the number of variables created.

Definition at line 245 of file variable_storage.h.

◆ Proto()

VariablesProto operations_research::math_opt::VariableStorage::Proto ( ) const

An equivalent proto of this.

Definition at line 82 of file variable_storage.cc.

◆ set_integer()

template<typename DiffIter >
void operations_research::math_opt::VariableStorage::set_integer ( VariableId id,
bool is_integer,
const iterator_range< DiffIter > & diffs )

Definition at line 214 of file variable_storage.h.

◆ set_lower_bound()

template<typename DiffIter >
void operations_research::math_opt::VariableStorage::set_lower_bound ( VariableId id,
double lower_bound,
const iterator_range< DiffIter > & diffs )

Definition at line 184 of file variable_storage.h.

◆ set_upper_bound()

template<typename DiffIter >
void operations_research::math_opt::VariableStorage::set_upper_bound ( VariableId id,
double upper_bound,
const iterator_range< DiffIter > & diffs )

Definition at line 199 of file variable_storage.h.

◆ size()

int64_t operations_research::math_opt::VariableStorage::size ( ) const
inline

The number of variables in the model.

Equal to the number of variables created minus the number of variables deleted.

Definition at line 243 of file variable_storage.h.

◆ SortedVariables()

std::vector< VariableId > operations_research::math_opt::VariableStorage::SortedVariables ( ) const

Returns a sorted vector of all existing (not deleted) variables in the model.

Runs in O(n log(n)), where n is the number of variables returned.

Definition at line 54 of file variable_storage.cc.

◆ Update()

VariableStorage::UpdateResult operations_research::math_opt::VariableStorage::Update ( const Diff & diff) const

Definition at line 98 of file variable_storage.cc.

◆ upper_bound()

double operations_research::math_opt::VariableStorage::upper_bound ( VariableId id) const
inline

Definition at line 171 of file variable_storage.h.

◆ Variables()

std::vector< VariableId > operations_research::math_opt::VariableStorage::Variables ( ) const

The VariableIds in use (not deleted), order not defined.

Definition at line 45 of file variable_storage.cc.

◆ VariablesFrom()

std::vector< VariableId > operations_research::math_opt::VariableStorage::VariablesFrom ( VariableId start) const

Returns the variables in the model starting with start (inclusive) and larger in order. Runs in O(next_id() - start).

Definition at line 60 of file variable_storage.cc.


The documentation for this class was generated from the following files: