Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::math_opt::AttrStorage< V, n, Symmetry > Class Template Reference

#include <attr_storage.h>

Public Types

using Key = AttrKey<n, Symmetry>

Public Member Functions

 AttrStorage ()
 Generally avoid, provided to make working with std::array easier.
 AttrStorage (const V default_value)
 AttrStorage (const AttrStorage &)=default
AttrStorageoperator= (const AttrStorage &)=default
 AttrStorage (AttrStorage &&)=default
AttrStorageoperator= (AttrStorage &&)=default
bool IsNonDefault (const Key key) const
std::optional< V > Set (const Key key, const V value)
Get (const Key key) const
std::optional< V > GetIfNonDefault (const Key key) const
 Returns the value of the attribute for key, or nullopt.
void Erase (const Key key)
 Sets the value of the attribute for key to the default value.
std::vector< KeyNonDefaults () const
template<int i>
std::vector< KeySlice (const int64_t key_elem) const
template<int i>
int64_t GetSliceSize (const int64_t key_elem) const
int64_t num_non_defaults () const
void Clear ()
 Restore all elements to their default value for this attribute.

Detailed Description

template<typename V, int n, typename Symmetry>
class operations_research::math_opt::AttrStorage< V, n, Symmetry >

Stores the value of an attribute keyed on n elements (e.g. linear_constraint_coefficient is a double valued attribute keyed first on LinearConstraint and then on Variable).

Memory usage: Storing k elements with non-default values in a AttrStorage<V, n> uses sizeof(V) * (n^2 + 1) * k / load_factor (where load_factor is the absl hash map load factor, typically 0.8), plus a small allocation overhead of O(k).

Definition at line 299 of file attr_storage.h.

Member Typedef Documentation

◆ Key

template<typename V, int n, typename Symmetry>
using operations_research::math_opt::AttrStorage< V, n, Symmetry >::Key = AttrKey<n, Symmetry>

Definition at line 301 of file attr_storage.h.

Constructor & Destructor Documentation

◆ AttrStorage() [1/4]

template<typename V, int n, typename Symmetry>
operations_research::math_opt::AttrStorage< V, n, Symmetry >::AttrStorage ( )
inlineexplicit

Generally avoid, provided to make working with std::array easier.

If this no longer holds, we should sprinkle the code with moves and return Vs by ref.

Definition at line 307 of file attr_storage.h.

◆ AttrStorage() [2/4]

template<typename V, int n, typename Symmetry>
operations_research::math_opt::AttrStorage< V, n, Symmetry >::AttrStorage ( const V default_value)
inlineexplicit

The default value of the attribute is its value when the model is created (e.g. for linear_constraint_coefficient, 0.0).

Definition at line 311 of file attr_storage.h.

◆ AttrStorage() [3/4]

template<typename V, int n, typename Symmetry>
operations_research::math_opt::AttrStorage< V, n, Symmetry >::AttrStorage ( const AttrStorage< V, n, Symmetry > & )
default

◆ AttrStorage() [4/4]

template<typename V, int n, typename Symmetry>
operations_research::math_opt::AttrStorage< V, n, Symmetry >::AttrStorage ( AttrStorage< V, n, Symmetry > && )
default

Member Function Documentation

◆ Clear()

template<typename V, int n, typename Symmetry>
void operations_research::math_opt::AttrStorage< V, n, Symmetry >::Clear ( )
inline

Restore all elements to their default value for this attribute.

Definition at line 416 of file attr_storage.h.

◆ Erase()

template<typename V, int n, typename Symmetry>
void operations_research::math_opt::AttrStorage< V, n, Symmetry >::Erase ( const Key key)
inline

Sets the value of the attribute for key to the default value.

Definition at line 366 of file attr_storage.h.

◆ Get()

template<typename V, int n, typename Symmetry>
V operations_research::math_opt::AttrStorage< V, n, Symmetry >::Get ( const Key key) const
inline

Returns the value of the attribute for key (return the default value if the attribute value for key is unset).

Definition at line 352 of file attr_storage.h.

◆ GetIfNonDefault()

template<typename V, int n, typename Symmetry>
std::optional< V > operations_research::math_opt::AttrStorage< V, n, Symmetry >::GetIfNonDefault ( const Key key) const
inline

Returns the value of the attribute for key, or nullopt.

Definition at line 357 of file attr_storage.h.

◆ GetSliceSize()

template<typename V, int n, typename Symmetry>
template<int i>
int64_t operations_research::math_opt::AttrStorage< V, n, Symmetry >::GetSliceSize ( const int64_t key_elem) const
inline

Returns the size of the given slice: This is equivalent to Slice(key_elem).size(), but O(1).

Definition at line 402 of file attr_storage.h.

◆ IsNonDefault()

template<typename V, int n, typename Symmetry>
bool operations_research::math_opt::AttrStorage< V, n, Symmetry >::IsNonDefault ( const Key key) const
inline

Returns true if the attribute for key has a value different from its default.

Definition at line 320 of file attr_storage.h.

◆ NonDefaults()

template<typename V, int n, typename Symmetry>
std::vector< Key > operations_research::math_opt::AttrStorage< V, n, Symmetry >::NonDefaults ( ) const
inline

Returns the keys (ids pairs) the of the elements with a non-default value for this attribute.

Definition at line 374 of file attr_storage.h.

◆ num_non_defaults()

template<typename V, int n, typename Symmetry>
int64_t operations_research::math_opt::AttrStorage< V, n, Symmetry >::num_non_defaults ( ) const
inline

Returns the number of keys (element pairs) with non-default values for this attribute.

Definition at line 413 of file attr_storage.h.

◆ operator=() [1/2]

template<typename V, int n, typename Symmetry>
AttrStorage & operations_research::math_opt::AttrStorage< V, n, Symmetry >::operator= ( AttrStorage< V, n, Symmetry > && )
default

◆ operator=() [2/2]

template<typename V, int n, typename Symmetry>
AttrStorage & operations_research::math_opt::AttrStorage< V, n, Symmetry >::operator= ( const AttrStorage< V, n, Symmetry > & )
default

◆ Set()

template<typename V, int n, typename Symmetry>
std::optional< V > operations_research::math_opt::AttrStorage< V, n, Symmetry >::Set ( const Key key,
const V value )
inline

Returns the previous value if value has changed, otherwise returns std::nullopt.

!is_default and !inserted

Definition at line 326 of file attr_storage.h.

◆ Slice()

template<typename V, int n, typename Symmetry>
template<int i>
std::vector< Key > operations_research::math_opt::AttrStorage< V, n, Symmetry >::Slice ( const int64_t key_elem) const
inline

Returns the set of all keys K such that:

  • There exists k_{0}..k_{n-1} such that K == AttrKey(k_{0}, ..., k_{i-1}, key_elem, k_{i+1}, ..., k_{n-1}), and
  • K has a non-default value for this attribute.

Definition at line 388 of file attr_storage.h.


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