SUMO - Simulation of Urban MObility
MSEdgeWeightsStorage.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A storage for edge travel times and efforts
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include "MSEdgeWeightsStorage.h"
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
39 }
40 
41 
43 }
44 
45 
46 bool
47 MSEdgeWeightsStorage::retrieveExistingTravelTime(const MSEdge* const e, const double t, double& value) const {
48  std::map<const MSEdge*, ValueTimeLine<double> >::const_iterator i = myTravelTimes.find(e);
49  if (i == myTravelTimes.end()) {
50  return false;
51  }
52  const ValueTimeLine<double>& tl = (*i).second;
53  if (!tl.describesTime(t)) {
54  return false;
55  }
56  value = tl.getValue(t);
57  return true;
58 }
59 
60 
61 bool
62 MSEdgeWeightsStorage::retrieveExistingEffort(const MSEdge* const e, const double t, double& value) const {
63  std::map<const MSEdge*, ValueTimeLine<double> >::const_iterator i = myEfforts.find(e);
64  if (i == myEfforts.end()) {
65  return false;
66  }
67  const ValueTimeLine<double>& tl = (*i).second;
68  if (!tl.describesTime(t)) {
69  return false;
70  }
71  value = tl.getValue(t);
72  return true;
73 }
74 
75 
76 void
78  double begin, double end,
79  double value) {
80  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myTravelTimes.find(e);
81  if (i == myTravelTimes.end()) {
83  i = myTravelTimes.find(e);
84  }
85  (*i).second.add(begin, end, value);
86 }
87 
88 
89 void
91  double begin, double end,
92  double value) {
93  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myEfforts.find(e);
94  if (i == myEfforts.end()) {
96  i = myEfforts.find(e);
97  }
98  (*i).second.add(begin, end, value);
99 }
100 
101 
102 void
104  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myTravelTimes.find(e);
105  if (i != myTravelTimes.end()) {
106  myTravelTimes.erase(i);
107  }
108 }
109 
110 
111 void
113  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myEfforts.find(e);
114  if (i != myEfforts.end()) {
115  myEfforts.erase(i);
116  }
117 }
118 
119 
120 bool
122  return myTravelTimes.find(e) != myTravelTimes.end();
123 }
124 
125 
126 bool
128  return myEfforts.find(e) != myEfforts.end();
129 }
130 
131 
132 
133 /****************************************************************************/
134 
MSEdgeWeightsStorage()
Constructor.
bool knowsEffort(const MSEdge *const e) const
Returns the information whether any effort is known for the given edge.
bool describesTime(double time) const
Returns whether a value for the given time is known.
bool knowsTravelTime(const MSEdge *const e) const
Returns the information whether any travel time is known for the given edge.
bool retrieveExistingEffort(const MSEdge *const e, const double t, double &value) const
Returns an effort for an edge and time if stored.
A road/street connecting two junctions.
Definition: MSEdge.h:80
void removeEffort(const MSEdge *const e)
Removes the effort information for an edge.
T getValue(double time) const
Returns the value for the given time.
void addTravelTime(const MSEdge *const e, double begin, double end, double value)
Adds a travel time information for an edge and a time span.
void removeTravelTime(const MSEdge *const e)
Removes the travel time information for an edge.
std::map< const MSEdge *, ValueTimeLine< double > > myEfforts
A map of edge->time->effort.
bool retrieveExistingTravelTime(const MSEdge *const e, const double t, double &value) const
Returns a travel time for an edge and time if stored.
~MSEdgeWeightsStorage()
Destructor.
std::map< const MSEdge *, ValueTimeLine< double > > myTravelTimes
A map of edge->time->travel time.
void addEffort(const MSEdge *const e, double begin, double end, double value)
Adds an effort information for an edge and a time span.