SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2015 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 #ifdef CHECK_MEMORY_LEAKS
35 #include <foreign/nvwa/debug_new.h>
36 #endif // CHECK_MEMORY_LEAKS
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
43 }
44 
45 
47 }
48 
49 
50 bool
52  std::map<const MSEdge*, ValueTimeLine<SUMOReal> >::const_iterator i = myTravelTimes.find(e);
53  if (i == myTravelTimes.end()) {
54  return false;
55  }
56  const ValueTimeLine<SUMOReal>& tl = (*i).second;
57  if (!tl.describesTime(t)) {
58  return false;
59  }
60  value = tl.getValue(t);
61  return true;
62 }
63 
64 
65 bool
66 MSEdgeWeightsStorage::retrieveExistingEffort(const MSEdge* const e, const SUMOReal t, SUMOReal& value) const {
67  std::map<const MSEdge*, ValueTimeLine<SUMOReal> >::const_iterator i = myEfforts.find(e);
68  if (i == myEfforts.end()) {
69  return false;
70  }
71  const ValueTimeLine<SUMOReal>& tl = (*i).second;
72  if (!tl.describesTime(t)) {
73  return false;
74  }
75  value = tl.getValue(t);
76  return true;
77 }
78 
79 
80 void
82  SUMOReal begin, SUMOReal end,
83  SUMOReal value) {
84  std::map<const MSEdge*, ValueTimeLine<SUMOReal> >::iterator i = myTravelTimes.find(e);
85  if (i == myTravelTimes.end()) {
87  i = myTravelTimes.find(e);
88  }
89  (*i).second.add(begin, end, value);
90 }
91 
92 
93 void
95  SUMOReal begin, SUMOReal end,
96  SUMOReal value) {
97  std::map<const MSEdge*, ValueTimeLine<SUMOReal> >::iterator i = myEfforts.find(e);
98  if (i == myEfforts.end()) {
100  i = myEfforts.find(e);
101  }
102  (*i).second.add(begin, end, value);
103 }
104 
105 
106 void
108  std::map<const MSEdge*, ValueTimeLine<SUMOReal> >::iterator i = myTravelTimes.find(e);
109  if (i != myTravelTimes.end()) {
110  myTravelTimes.erase(i);
111  }
112 }
113 
114 
115 void
117  std::map<const MSEdge*, ValueTimeLine<SUMOReal> >::iterator i = myEfforts.find(e);
118  if (i != myEfforts.end()) {
119  myEfforts.erase(i);
120  }
121 }
122 
123 
124 bool
126  return myTravelTimes.find(e) != myTravelTimes.end();
127 }
128 
129 
130 bool
132  return myEfforts.find(e) != myEfforts.end();
133 }
134 
135 
136 
137 /****************************************************************************/
138 
MSEdgeWeightsStorage()
Constructor.
void addEffort(const MSEdge *const e, SUMOReal begin, SUMOReal end, SUMOReal value)
Adds an effort information for an edge and a time span.
void addTravelTime(const MSEdge *const e, SUMOReal begin, SUMOReal end, SUMOReal value)
Adds a travel time information for an edge and a time span.
A road/street connecting two junctions.
Definition: MSEdge.h:81
void removeEffort(const MSEdge *const e)
Removes the effort information for an edge.
bool describesTime(SUMOReal time) const
Returns whether a value for the given time is known.
T getValue(SUMOReal time) const
Returns the value for the given time.
std::map< const MSEdge *, ValueTimeLine< SUMOReal > > myEfforts
A map of edge->time->effort.
void removeTravelTime(const MSEdge *const e)
Removes the travel time information for an edge.
~MSEdgeWeightsStorage()
Destructor.
bool knowsEffort(const MSEdge *const e) const
Returns the information whether any effort is known for the given edge.
#define SUMOReal
Definition: config.h:218
bool retrieveExistingEffort(const MSEdge *const e, const SUMOReal t, SUMOReal &value) const
Returns an effort for an edge and time if stored.
bool knowsTravelTime(const MSEdge *const e) const
Returns the information whether any travel time is known for the given edge.
bool retrieveExistingTravelTime(const MSEdge *const e, const SUMOReal t, SUMOReal &value) const
Returns a travel time for an edge and time if stored.
std::map< const MSEdge *, ValueTimeLine< SUMOReal > > myTravelTimes
A map of edge->time->travel time.