Eclipse SUMO - Simulation of Urban MObility
|
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. | |
CharacteristicMap (int domainDim, int imageDim, const std::vector< std::vector< double > > &ref_axes, const std::vector< double > &ref_flattenedMap) | |
Constructor. | |
std::vector< double > | eval (const std::vector< double > &ref_p, double eps=1e-6) const |
Evaluate a point in the map using linear interpolation. | |
int | getDomainDim () const |
Get the dimension of the map's domain. | |
int | getImageDim () const |
Get the image dimension of the map. | |
std::string | toString () const |
Encode the map as a string. | |
Private Member Functions | |
std::vector< double > | at (const std::vector< int > &ref_idxs) const |
Access a map entry using its indices. | |
int | calcFlatIdx (const std::vector< int > &ref_idxs) const |
Compute the index of a map entry in the flattened map. | |
void | determineStrides () |
Determine the stride for each map dimension in the flattened map. | |
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. | |
Private Attributes | |
std::vector< std::vector< double > > | axes |
Vector containing the values along each domain axis in ascending order. | |
int | domainDim |
Dimension of the map's domain. | |
std::vector< double > | flattenedMap |
Flattened map entries. | |
int | imageDim |
Image dimension of the map. | |
std::vector< int > | strides |
Stride for each domain dimension in the flattened map. | |
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.
CharacteristicMap::CharacteristicMap | ( | int | domainDim, |
int | imageDim, | ||
const std::vector< std::vector< double > > & | ref_axes, | ||
const std::vector< double > & | ref_flattenedMap | ||
) |
Constructor.
[in] | domainDim | The map's domain dimension |
[in] | imageDim | The map's image dimension |
[in] | ref_axes | A vector of vectors containing the entries of their respective axes in ascending order |
[in] | ref_flattenedMap | The row-major flattened entries of the map (i.e. the map is flattened along its first axis) |
std::runtime_error |
Definition at line 116 of file CharacteristicMap.cpp.
References axes, determineStrides(), domainDim, flattenedMap, and imageDim.
CharacteristicMap::CharacteristicMap | ( | const std::string & | ref_mapString | ) |
Constructor.
[in] | ref_mapString | A 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.
|
private |
Access a map entry using its indices.
[in] | ref_idxs | A vector containing indices |
std::runtime_error |
Definition at line 104 of file CharacteristicMap.cpp.
References calcFlatIdx(), domainDim, flattenedMap, and imageDim.
Referenced by eval().
|
private |
Compute the index of a map entry in the flattened map.
[in] | ref_idxs | Non-flattened map indices |
std::runtime_error |
Definition at line 46 of file CharacteristicMap.cpp.
References domainDim, and strides.
Referenced by at().
|
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(), and CharacteristicMap().
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.
[in] | ref_p | A point |
[in] | eps | An epsilon value |
std::runtime_error |
Definition at line 230 of file CharacteristicMap.cpp.
References at(), axes, domainDim, findNearestNeighborIdxs(), and imageDim.
Referenced by calcPowerConsumption().
|
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.
[in] | ref_p | A point |
[out] | ref_idxs | A vector into which the indices shall be written |
[in] | eps | An epsilon value |
std::runtime_error |
Definition at line 64 of file CharacteristicMap.cpp.
References axes, and domainDim.
Referenced by eval().
int CharacteristicMap::getDomainDim | ( | ) | const |
Get the dimension of the map's domain.
Definition at line 218 of file CharacteristicMap.cpp.
References domainDim.
int CharacteristicMap::getImageDim | ( | ) | const |
Get the image dimension of the map.
Definition at line 224 of file CharacteristicMap.cpp.
References imageDim.
std::string CharacteristicMap::toString | ( | ) | const |
Encode the map as a string.
Definition at line 193 of file CharacteristicMap.cpp.
References axes, domainDim, flattenedMap, and imageDim.
|
private |
Vector containing the values along each domain axis in ascending order.
Definition at line 118 of file CharacteristicMap.h.
Referenced by CharacteristicMap(), CharacteristicMap(), determineStrides(), eval(), findNearestNeighborIdxs(), and toString().
|
private |
Dimension of the map's domain.
Definition at line 112 of file CharacteristicMap.h.
Referenced by at(), calcFlatIdx(), CharacteristicMap(), CharacteristicMap(), determineStrides(), eval(), findNearestNeighborIdxs(), getDomainDim(), and toString().
|
private |
Flattened map entries.
Definition at line 121 of file CharacteristicMap.h.
Referenced by at(), CharacteristicMap(), CharacteristicMap(), and toString().
|
private |
Image dimension of the map.
Definition at line 115 of file CharacteristicMap.h.
Referenced by at(), CharacteristicMap(), CharacteristicMap(), determineStrides(), eval(), getImageDim(), and toString().
|
private |
Stride for each domain dimension in the flattened map.
Definition at line 124 of file CharacteristicMap.h.
Referenced by calcFlatIdx(), and determineStrides().