1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file MSEdgeWeightsStorage.cpp
11 /// @author Daniel Krajzewicz
12 /// @author Laura Bieker
13 /// @author Michael Behrisch
14 /// @date 02.11.2009
15 /// @version $Id$
16 ///
17 // A storage for edge travel times and efforts
18 /****************************************************************************/
19
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24
25 #include "MSEdgeWeightsStorage.h"
26
27
28 // ===========================================================================
29 // method definitions
30 // ===========================================================================
MSEdgeWeightsStorage()31 MSEdgeWeightsStorage::MSEdgeWeightsStorage() {
32 }
33
34
~MSEdgeWeightsStorage()35 MSEdgeWeightsStorage::~MSEdgeWeightsStorage() {
36 }
37
38
39 bool
retrieveExistingTravelTime(const MSEdge * const e,const double t,double & value) const40 MSEdgeWeightsStorage::retrieveExistingTravelTime(const MSEdge* const e, const double t, double& value) const {
41 std::map<const MSEdge*, ValueTimeLine<double> >::const_iterator i = myTravelTimes.find(e);
42 if (i == myTravelTimes.end()) {
43 return false;
44 }
45 const ValueTimeLine<double>& tl = (*i).second;
46 if (!tl.describesTime(t)) {
47 return false;
48 }
49 value = tl.getValue(t);
50 return true;
51 }
52
53
54 bool
retrieveExistingEffort(const MSEdge * const e,const double t,double & value) const55 MSEdgeWeightsStorage::retrieveExistingEffort(const MSEdge* const e, const double t, double& value) const {
56 std::map<const MSEdge*, ValueTimeLine<double> >::const_iterator i = myEfforts.find(e);
57 if (i == myEfforts.end()) {
58 return false;
59 }
60 const ValueTimeLine<double>& tl = (*i).second;
61 if (!tl.describesTime(t)) {
62 return false;
63 }
64 value = tl.getValue(t);
65 return true;
66 }
67
68
69 void
addTravelTime(const MSEdge * const e,double begin,double end,double value)70 MSEdgeWeightsStorage::addTravelTime(const MSEdge* const e,
71 double begin, double end,
72 double value) {
73 std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myTravelTimes.find(e);
74 if (i == myTravelTimes.end()) {
75 myTravelTimes[e] = ValueTimeLine<double>();
76 i = myTravelTimes.find(e);
77 }
78 (*i).second.add(begin, end, value);
79 }
80
81
82 void
addEffort(const MSEdge * const e,double begin,double end,double value)83 MSEdgeWeightsStorage::addEffort(const MSEdge* const e,
84 double begin, double end,
85 double value) {
86 std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myEfforts.find(e);
87 if (i == myEfforts.end()) {
88 myEfforts[e] = ValueTimeLine<double>();
89 i = myEfforts.find(e);
90 }
91 (*i).second.add(begin, end, value);
92 }
93
94
95 void
removeTravelTime(const MSEdge * const e)96 MSEdgeWeightsStorage::removeTravelTime(const MSEdge* const e) {
97 std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myTravelTimes.find(e);
98 if (i != myTravelTimes.end()) {
99 myTravelTimes.erase(i);
100 }
101 }
102
103
104 void
removeEffort(const MSEdge * const e)105 MSEdgeWeightsStorage::removeEffort(const MSEdge* const e) {
106 std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myEfforts.find(e);
107 if (i != myEfforts.end()) {
108 myEfforts.erase(i);
109 }
110 }
111
112
113 bool
knowsTravelTime(const MSEdge * const e) const114 MSEdgeWeightsStorage::knowsTravelTime(const MSEdge* const e) const {
115 return myTravelTimes.find(e) != myTravelTimes.end();
116 }
117
118
119 bool
knowsEffort(const MSEdge * const e) const120 MSEdgeWeightsStorage::knowsEffort(const MSEdge* const e) const {
121 return myEfforts.find(e) != myEfforts.end();
122 }
123
124
125
126 /****************************************************************************/
127
128