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

#include <sparse_coefficient_map.h>

Public Member Functions

 SparseCoefficientMap ()=default
 
 SparseCoefficientMap (absl::flat_hash_map< VariableId, double > terms)
 
double get (VariableId id) const
 Returns 0.0 by default if no value is set.
 
bool set (VariableId id, double coeff)
 Returns true if the stored value changes.
 
const absl::flat_hash_map< VariableId, double > & terms () const
 
void clear ()
 
void erase (VariableId id)
 Has no effect if id is not set.
 
SparseDoubleVectorProto Proto () const
 

Detailed Description

Represents a sparse collection of linear terms: {double_i x VariableId_i}_i. All VariableIds not represented in the collection are implicitly treated as having zero coefficient.

Internally it is a lightweight wrapper around absl::flat_hash_map that only explicitly stores nonzero elements.

Definition at line 33 of file sparse_coefficient_map.h.

Constructor & Destructor Documentation

◆ SparseCoefficientMap() [1/2]

operations_research::math_opt::SparseCoefficientMap::SparseCoefficientMap ( )
default

◆ SparseCoefficientMap() [2/2]

operations_research::math_opt::SparseCoefficientMap::SparseCoefficientMap ( absl::flat_hash_map< VariableId, double > terms)
inlineexplicit

Inline implementations

Definition at line 67 of file sparse_coefficient_map.h.

Member Function Documentation

◆ clear()

void operations_research::math_opt::SparseCoefficientMap::clear ( )
inline

Definition at line 96 of file sparse_coefficient_map.h.

◆ erase()

void operations_research::math_opt::SparseCoefficientMap::erase ( VariableId id)
inline

Has no effect if id is not set.

Definition at line 98 of file sparse_coefficient_map.h.

◆ get()

double operations_research::math_opt::SparseCoefficientMap::get ( VariableId id) const
inline

Returns 0.0 by default if no value is set.

Definition at line 73 of file sparse_coefficient_map.h.

◆ Proto()

SparseDoubleVectorProto operations_research::math_opt::SparseCoefficientMap::Proto ( ) const

Definition at line 24 of file sparse_coefficient_map.cc.

◆ set()

bool operations_research::math_opt::SparseCoefficientMap::set ( VariableId id,
double coeff )
inline

Returns true if the stored value changes.

Definition at line 81 of file sparse_coefficient_map.h.

◆ terms()

const absl::flat_hash_map< VariableId, double > & operations_research::math_opt::SparseCoefficientMap::terms ( ) const
inline

Definition at line 46 of file sparse_coefficient_map.h.


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