SUMO - Simulation of Urban MObility
MSEdgeWeightsStorage.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A storage for edge travel times and efforts
20 /****************************************************************************/
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include "MSEdgeWeightsStorage.h"
32 
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
38 }
39 
40 
42 }
43 
44 
45 bool
46 MSEdgeWeightsStorage::retrieveExistingTravelTime(const MSEdge* const e, const double t, double& value) const {
47  std::map<const MSEdge*, ValueTimeLine<double> >::const_iterator i = myTravelTimes.find(e);
48  if (i == myTravelTimes.end()) {
49  return false;
50  }
51  const ValueTimeLine<double>& tl = (*i).second;
52  if (!tl.describesTime(t)) {
53  return false;
54  }
55  value = tl.getValue(t);
56  return true;
57 }
58 
59 
60 bool
61 MSEdgeWeightsStorage::retrieveExistingEffort(const MSEdge* const e, const double t, double& value) const {
62  std::map<const MSEdge*, ValueTimeLine<double> >::const_iterator i = myEfforts.find(e);
63  if (i == myEfforts.end()) {
64  return false;
65  }
66  const ValueTimeLine<double>& tl = (*i).second;
67  if (!tl.describesTime(t)) {
68  return false;
69  }
70  value = tl.getValue(t);
71  return true;
72 }
73 
74 
75 void
77  double begin, double end,
78  double value) {
79  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myTravelTimes.find(e);
80  if (i == myTravelTimes.end()) {
82  i = myTravelTimes.find(e);
83  }
84  (*i).second.add(begin, end, value);
85 }
86 
87 
88 void
90  double begin, double end,
91  double value) {
92  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myEfforts.find(e);
93  if (i == myEfforts.end()) {
95  i = myEfforts.find(e);
96  }
97  (*i).second.add(begin, end, value);
98 }
99 
100 
101 void
103  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myTravelTimes.find(e);
104  if (i != myTravelTimes.end()) {
105  myTravelTimes.erase(i);
106  }
107 }
108 
109 
110 void
112  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myEfforts.find(e);
113  if (i != myEfforts.end()) {
114  myEfforts.erase(i);
115  }
116 }
117 
118 
119 bool
121  return myTravelTimes.find(e) != myTravelTimes.end();
122 }
123 
124 
125 bool
127  return myEfforts.find(e) != myEfforts.end();
128 }
129 
130 
131 
132 /****************************************************************************/
133 
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.