ValueTimeLine< T > Class Template Reference

#include <ValueTimeLine.h>


Detailed Description

template<typename T>
class ValueTimeLine< T >

A time line being a sorted container of non-overlapping time-ranges with assigned values. The container is sorted by the first value of the time-range while being filled. Every new inserted time range may overwrite or split one or mutliple earlier intervals.

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.
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).

Member Typedef Documentation

template<typename T>
typedef std::map<SUMOReal, ValidValue> ValueTimeLine< T >::TimedValueMap

Sorted map from start of intervals to values.

Definition at line 56 of file ValueTimeLine.h.

template<typename T>
typedef std::pair<bool, T> ValueTimeLine< T >::ValidValue

Value of time line, indicating validity.

Definition at line 53 of file ValueTimeLine.h.


Constructor & Destructor Documentation

template<typename T>
ValueTimeLine< T >::ValueTimeLine (  )  [inline]

Constructor.

Definition at line 60 of file ValueTimeLine.h.

00060 { }

template<typename T>
ValueTimeLine< T >::~ValueTimeLine (  )  [inline]

Destructor.

Definition at line 63 of file ValueTimeLine.h.

00063 { }


Member Function Documentation

template<typename T>
void ValueTimeLine< T >::add ( SUMOReal  begin,
SUMOReal  end,
value 
) [inline]

Adds a value for a time interval into the container.

Make sure that begin >= 0 and begin < end.

Parameters:
[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     }

template<typename T>
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.

Parameters:
[in] the time for which the value should be retrieved
Returns:
whether a valid value was set

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     }

template<typename T>
void ValueTimeLine< T >::fillGaps ( value,
bool  extendOverBoundaries = false 
) [inline]

Sets a default value for all unset intervals.

Parameters:
[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     }

template<typename T>
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.

Parameters:
[in] low the time in the first interval
[in] high the time in the second interval
Returns:
the split point

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     }

template<typename T>
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.

Parameters:
[in] the time for which the value should be retrieved
Returns:
the value for the time

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     }


Field Documentation

template<typename T>
TimedValueMap ValueTimeLine< T >::myValues [private]


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

Generated on Wed May 5 00:07:01 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6