#include <ValueTimeLine.h>
Definition at line 50 of file ValueTimeLine.h.
Public Types | |
| typedef std::map< SUMOReal, ValidValue > | TimedValueMap |
| Sorted map from start of intervals to values. | |
| typedef std::pair< bool, T > | ValidValue |
| Value of time line, indicating validity. | |
Public Member Functions | |
| void | add (SUMOReal begin, SUMOReal end, T value) |
| Adds a value for a time interval into the container. | |
| bool | describesTime (SUMOReal time) const |
| Returns whether a value for the given time is known. | |
| void | fillGaps (T value, bool extendOverBoundaries=false) |
| Sets a default value for all unset intervals. | |
| SUMOReal | getSplitTime (SUMOReal low, SUMOReal high) const |
| Returns the time point at which the value changes. | |
| T | getValue (SUMOReal time) const |
| Returns the value for the given time. | |
| ValueTimeLine () | |
| Constructor. | |
| ~ValueTimeLine () | |
| Destructor. | |
Private Attributes | |
| TimedValueMap | myValues |
| The list of time periods (with values). | |
| typedef std::map<SUMOReal, ValidValue> ValueTimeLine< T >::TimedValueMap |
| typedef std::pair<bool, T> ValueTimeLine< T >::ValidValue |
| ValueTimeLine< T >::ValueTimeLine | ( | ) | [inline] |
| ValueTimeLine< T >::~ValueTimeLine | ( | ) | [inline] |
| void ValueTimeLine< T >::add | ( | SUMOReal | begin, | |
| SUMOReal | end, | |||
| T | value | |||
| ) | [inline] |
Adds a value for a time interval into the container.
Make sure that begin >= 0 and begin < end.
| [in] | begin | the start time of the time range (inclusive) |
| [in] | end | the end time of the time range (exclusive) |
| [in] | value | the value to store |
Definition at line 73 of file ValueTimeLine.h.
Referenced by ROEdge::addEffort(), ROEdge::addTravelTime(), and TEST().
00073 { 00074 assert(begin>=0); 00075 assert(begin<end); 00076 // inserting strictly before the first or after the last interval (includes empty case) 00077 if (myValues.upper_bound(begin) == myValues.end() || 00078 myValues.upper_bound(end) == myValues.begin()) { 00079 myValues[begin] = std::make_pair(true, value); 00080 myValues[end] = std::make_pair(false, value); 00081 return; 00082 } 00083 // our end already has a value 00084 typename TimedValueMap::iterator endIt = myValues.find(end); 00085 if (endIt != myValues.end()) { 00086 myValues.erase(myValues.upper_bound(begin), endIt); 00087 myValues[begin] = std::make_pair(true, value); 00088 return; 00089 } 00090 // we have at least one entry strictly before our end 00091 endIt = myValues.lower_bound(end); 00092 --endIt; 00093 ValidValue oldEndValue = endIt->second; 00094 myValues.erase(myValues.upper_bound(begin), myValues.lower_bound(end)); 00095 myValues[begin] = std::make_pair(true, value); 00096 myValues[end] = oldEndValue; 00097 }
| bool ValueTimeLine< T >::describesTime | ( | SUMOReal | time | ) | const [inline] |
Returns whether a value for the given time is known.
This method implements the bounds checking. It returns true if and only if an explicit value was set for the given time using add. Default values stemming from fillGaps are not considered valid.
| [in] | the | time for which the value should be retrieved |
Definition at line 125 of file ValueTimeLine.h.
Referenced by ROEdge::getStoredEffort(), ROEdge::getTravelTime(), MSEdgeWeightsStorage::retrieveExistingEffort(), and MSEdgeWeightsStorage::retrieveExistingTravelTime().
00125 { 00126 typename TimedValueMap::const_iterator afterIt = myValues.upper_bound(time); 00127 if (afterIt == myValues.begin()) { 00128 return false; 00129 } 00130 --afterIt; 00131 return afterIt->second.first; 00132 }
| void ValueTimeLine< T >::fillGaps | ( | T | value, | |
| bool | extendOverBoundaries = false | |||
| ) | [inline] |
Sets a default value for all unset intervals.
| [in] | value | the value to store |
| [in] | extendOverBoundaries | whether the first/last value should be valid for later / earlier times as well |
Definition at line 159 of file ValueTimeLine.h.
Referenced by ROEdge::buildTimeLines(), and TEST().
00159 { 00160 for (typename TimedValueMap::iterator it = myValues.begin(); it != myValues.end(); ++it) { 00161 if (!it->second.first) { 00162 it->second.second = value; 00163 } 00164 } 00165 if (extendOverBoundaries && !myValues.empty()) { 00166 typename TimedValueMap::iterator it = --myValues.end(); 00167 if (!it->second.first) { 00168 myValues.erase(it, myValues.end()); 00169 } 00170 value = myValues.begin()->second.second; 00171 } 00172 myValues[-1] = std::make_pair(false, value); 00173 }
| SUMOReal ValueTimeLine< T >::getSplitTime | ( | SUMOReal | low, | |
| SUMOReal | high | |||
| ) | const [inline] |
Returns the time point at which the value changes.
If the two input parameters lie in two consecutive time intervals, this method returns the point at which the interval changes. In any other case -1 is returned.
| [in] | low | the time in the first interval |
| [in] | high | the time in the second interval |
Definition at line 144 of file ValueTimeLine.h.
Referenced by ROEdge::getStoredEffort(), and ROEdge::getTravelTime().
00144 { 00145 typename TimedValueMap::const_iterator afterLow = myValues.upper_bound(low); 00146 typename TimedValueMap::const_iterator afterHigh = myValues.upper_bound(high); 00147 --afterHigh; 00148 if (afterLow == afterHigh) { 00149 return afterLow->first; 00150 } 00151 return -1; 00152 }
| T ValueTimeLine< T >::getValue | ( | SUMOReal | time | ) | const [inline] |
Returns the value for the given time.
There is no bounds checking applied! If there was no value set, the return value is undefined, the method may even segfault.
| [in] | the | time for which the value should be retrieved |
Definition at line 107 of file ValueTimeLine.h.
Referenced by ROEdge::getStoredEffort(), ROEdge::getTravelTime(), MSEdgeWeightsStorage::retrieveExistingEffort(), MSEdgeWeightsStorage::retrieveExistingTravelTime(), and TEST().
00107 { 00108 assert(myValues.size()!=0); 00109 typename TimedValueMap::const_iterator it = myValues.upper_bound(time); 00110 assert(it != myValues.begin()); 00111 --it; 00112 return it->second.second; 00113 }
TimedValueMap ValueTimeLine< T >::myValues [private] |
The list of time periods (with values).
Definition at line 177 of file ValueTimeLine.h.
Referenced by ValueTimeLine< SUMOReal >::add(), ValueTimeLine< SUMOReal >::describesTime(), ValueTimeLine< SUMOReal >::fillGaps(), ValueTimeLine< SUMOReal >::getSplitTime(), and ValueTimeLine< SUMOReal >::getValue().
1.5.6