Eclipse SUMO - Simulation of Urban MObility
CharacteristicMap Class Reference

The purpose of this class is to store a characteristic map (German: Kennfeld) of arbitrary dimensions and to provide functions in order to evaluate/interpolate points in it. More...

#include <CharacteristicMap.h>

Public Member Functions

 CharacteristicMap (const std::string &ref_mapString)
 Constructor. More...
 
 CharacteristicMap (int domainDim, int imageDim, const std::vector< std::vector< double >> &ref_axes, const std::vector< double > &ref_flattenedMap)
 Constructor. More...
 
std::vector< double > eval (const std::vector< double > &ref_p, double eps=1e-6) const
 Evaluate a point in the map using linear interpolation. More...
 
int getDomainDim () const
 Get the dimension of the map's domain. More...
 
int getImageDim () const
 Get the image dimension of the map. More...
 
std::string toString () const
 Encode the map as a string. More...
 

Private Member Functions

std::vector< double > at (const std::vector< int > &ref_idxs) const
 Access a map entry using its indices. More...
 
int calcFlatIdx (const std::vector< int > &ref_idxs) const
 Compute the index of a map entry in the flattened map. More...
 
void determineStrides ()
 Determine the stride for each map dimension in the flattened map. More...
 
int findNearestNeighborIdxs (const std::vector< double > &ref_p, std::vector< int > &ref_idxs, double eps=1e-6) const
 Determine the indices of the nearest neighbor of a point in the map. More...
 

Private Attributes

std::vector< std::vector< double > > axes
 Vector containing the values along each domain axis in ascending order. More...
 
int domainDim
 Dimension of the map's domain. More...
 
std::vector< double > flattenedMap
 Flattened map entries. More...
 
int imageDim
 Image dimension of the map. More...
 
std::vector< int > strides
 Stride for each domain dimension in the flattened map. More...
 

Detailed Description

The purpose of this class is to store a characteristic map (German: Kennfeld) of arbitrary dimensions and to provide functions in order to evaluate/interpolate points in it.

Definition at line 109 of file CharacteristicMap.h.

Constructor & Destructor Documentation

◆ CharacteristicMap() [1/2]

CharacteristicMap::CharacteristicMap ( int  domainDim,
int  imageDim,
const std::vector< std::vector< double >> &  ref_axes,
const std::vector< double > &  ref_flattenedMap 
)

Constructor.

Parameters
[in]domainDimThe map's domain dimension
[in]imageDimThe map's image dimension
[in]ref_axesA vector of vectors containing the entries of their respective axes in ascending order
[in]ref_flattenedMapThe row-major flattened entries of the map (i.e. the map is flattened along its first axis)
Exceptions
std::runtime_error

Definition at line 116 of file CharacteristicMap.cpp.

References axes, determineStrides(), domainDim, flattenedMap, and imageDim.

◆ CharacteristicMap() [2/2]

CharacteristicMap::CharacteristicMap ( const std::string &  ref_mapString)

Constructor.

Parameters
[in]ref_mapStringA string representation of a characteristic map (cf. example at the top of the file) throws std::runtime_error

Definition at line 141 of file CharacteristicMap.cpp.

References axes, determineStrides(), domainDim, flattenedMap, StringTokenizer::getVector(), and imageDim.

Member Function Documentation

◆ at()

std::vector< double > CharacteristicMap::at ( const std::vector< int > &  ref_idxs) const
private

Access a map entry using its indices.

Parameters
[in]ref_idxsA vector containing indices
Returns
A vector containing the image values of the map at the specified location
Exceptions
std::runtime_error

Definition at line 104 of file CharacteristicMap.cpp.

References calcFlatIdx(), domainDim, flattenedMap, and imageDim.

Referenced by eval().

Here is the caller graph for this function:

◆ calcFlatIdx()

int CharacteristicMap::calcFlatIdx ( const std::vector< int > &  ref_idxs) const
private

Compute the index of a map entry in the flattened map.

Parameters
[in]ref_idxsNon-flattened map indices
Returns
Flattened map index
Exceptions
std::runtime_error

Definition at line 46 of file CharacteristicMap.cpp.

References domainDim, and strides.

Referenced by at().

Here is the caller graph for this function:

◆ determineStrides()

void CharacteristicMap::determineStrides ( )
private

Determine the stride for each map dimension in the flattened map.

Definition at line 35 of file CharacteristicMap.cpp.

References axes, domainDim, imageDim, and strides.

Referenced by CharacteristicMap().

Here is the caller graph for this function:

◆ eval()

std::vector< double > CharacteristicMap::eval ( const std::vector< double > &  ref_p,
double  eps = 1e-6 
) const

Evaluate a point in the map using linear interpolation.

Please note that the result may contain NaNs. That happens when... a) ... the point in question has no nearest neighbor (that is, it lies outside of the domain). In that case, all entries of the vector are set to NaN. b) ... an image value of the nearest neighbor is NaN. Then, the result is also NaN in that image dimension. c) ... evaluation would require interpolating with a support point which is NaN in an image dimension. The corresponding result entry is set to NaN in that case.

Parameters
[in]ref_pA point
[in]epsAn epsilon value
Returns
The (interpolated) image values of the map at the specified point
Exceptions
std::runtime_error

Definition at line 230 of file CharacteristicMap.cpp.

References at(), axes, domainDim, findNearestNeighborIdxs(), and imageDim.

Referenced by calcPowerConsumption().

Here is the caller graph for this function:

◆ findNearestNeighborIdxs()

int CharacteristicMap::findNearestNeighborIdxs ( const std::vector< double > &  ref_p,
std::vector< int > &  ref_idxs,
double  eps = 1e-6 
) const
private

Determine the indices of the nearest neighbor of a point in the map.

A point has no such neighbor if it lies outside of the range of an axis with respect to some epsilon.

Parameters
[in]ref_pA point
[out]ref_idxsA vector into which the indices shall be written
[in]epsAn epsilon value
Returns
0 if a nearest neighbor could be found, else -1
Exceptions
std::runtime_error

Definition at line 64 of file CharacteristicMap.cpp.

References axes, and domainDim.

Referenced by eval().

Here is the caller graph for this function:

◆ getDomainDim()

int CharacteristicMap::getDomainDim ( ) const

Get the dimension of the map's domain.

Returns
The domain's dimension

Definition at line 218 of file CharacteristicMap.cpp.

References domainDim.

◆ getImageDim()

int CharacteristicMap::getImageDim ( ) const

Get the image dimension of the map.

Returns
The image dimension of the characteristic map

Definition at line 224 of file CharacteristicMap.cpp.

References imageDim.

◆ toString()

std::string CharacteristicMap::toString ( ) const

Encode the map as a string.

Returns
A string representation of the characteristic map (cf. example at the top of the file)

Definition at line 193 of file CharacteristicMap.cpp.

References axes, domainDim, flattenedMap, imageDim, and nlohmann::to_string().

Field Documentation

◆ axes

std::vector<std::vector<double> > CharacteristicMap::axes
private

Vector containing the values along each domain axis in ascending order.

Definition at line 118 of file CharacteristicMap.h.

Referenced by CharacteristicMap(), determineStrides(), eval(), findNearestNeighborIdxs(), and toString().

◆ domainDim

int CharacteristicMap::domainDim
private

Dimension of the map's domain.

Definition at line 112 of file CharacteristicMap.h.

Referenced by at(), calcFlatIdx(), CharacteristicMap(), determineStrides(), eval(), findNearestNeighborIdxs(), getDomainDim(), and toString().

◆ flattenedMap

std::vector<double> CharacteristicMap::flattenedMap
private

Flattened map entries.

Definition at line 121 of file CharacteristicMap.h.

Referenced by at(), CharacteristicMap(), and toString().

◆ imageDim

int CharacteristicMap::imageDim
private

Image dimension of the map.

Definition at line 115 of file CharacteristicMap.h.

Referenced by at(), CharacteristicMap(), determineStrides(), eval(), getImageDim(), and toString().

◆ strides

std::vector<int> CharacteristicMap::strides
private

Stride for each domain dimension in the flattened map.

Definition at line 124 of file CharacteristicMap.h.

Referenced by calcFlatIdx(), and determineStrides().


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