Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/microsim/MSEdgeWeightsStorage.cpp
185785 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file MSEdgeWeightsStorage.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Laura Bieker
17
/// @author Michael Behrisch
18
/// @date 02.11.2009
19
///
20
// A storage for edge travel times and efforts
21
/****************************************************************************/
22
#include <config.h>
23
24
#include "MSEdgeWeightsStorage.h"
25
26
27
// ===========================================================================
28
// method definitions
29
// ===========================================================================
30
MSEdgeWeightsStorage::MSEdgeWeightsStorage() {
31
}
32
33
34
MSEdgeWeightsStorage::~MSEdgeWeightsStorage() {
35
}
36
37
38
bool
39
MSEdgeWeightsStorage::retrieveExistingTravelTime(const MSEdge* const e, const double t, double& value) const {
40
std::map<const MSEdge*, ValueTimeLine<double> >::const_iterator i = myTravelTimes.find(e);
41
if (i == myTravelTimes.end()) {
42
return false;
43
}
44
const ValueTimeLine<double>& tl = (*i).second;
45
if (!tl.describesTime(t)) {
46
return false;
47
}
48
value = tl.getValue(t);
49
return true;
50
}
51
52
53
bool
54
MSEdgeWeightsStorage::retrieveExistingEffort(const MSEdge* const e, const double t, double& value) const {
55
std::map<const MSEdge*, ValueTimeLine<double> >::const_iterator i = myEfforts.find(e);
56
if (i == myEfforts.end()) {
57
return false;
58
}
59
const ValueTimeLine<double>& tl = (*i).second;
60
if (!tl.describesTime(t)) {
61
return false;
62
}
63
value = tl.getValue(t);
64
return true;
65
}
66
67
68
void
69
MSEdgeWeightsStorage::addTravelTime(const MSEdge* const e,
70
double begin, double end,
71
double value) {
72
std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myTravelTimes.find(e);
73
if (i == myTravelTimes.end()) {
74
myTravelTimes[e] = ValueTimeLine<double>();
75
i = myTravelTimes.find(e);
76
}
77
(*i).second.add(begin, end, value);
78
}
79
80
81
void
82
MSEdgeWeightsStorage::addEffort(const MSEdge* const e,
83
double begin, double end,
84
double value) {
85
std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myEfforts.find(e);
86
if (i == myEfforts.end()) {
87
myEfforts[e] = ValueTimeLine<double>();
88
i = myEfforts.find(e);
89
}
90
(*i).second.add(begin, end, value);
91
}
92
93
94
void
95
MSEdgeWeightsStorage::removeTravelTime(const MSEdge* const e) {
96
std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myTravelTimes.find(e);
97
if (i != myTravelTimes.end()) {
98
myTravelTimes.erase(i);
99
}
100
}
101
102
103
void
104
MSEdgeWeightsStorage::removeEffort(const MSEdge* const e) {
105
std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myEfforts.find(e);
106
if (i != myEfforts.end()) {
107
myEfforts.erase(i);
108
}
109
}
110
111
112
bool
113
MSEdgeWeightsStorage::knowsTravelTime(const MSEdge* const e) const {
114
return myTravelTimes.find(e) != myTravelTimes.end();
115
}
116
117
118
bool
119
MSEdgeWeightsStorage::knowsEffort(const MSEdge* const e) const {
120
return myEfforts.find(e) != myEfforts.end();
121
}
122
123
124
/****************************************************************************/
125
126