Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libsumo/MultiEntryExit.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2012-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 MultiEntryExit.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Mario Krumnow
17
/// @author Jakob Erdmann
18
/// @author Michael Behrisch
19
/// @date 30.05.2012
20
///
21
// C++ TraCI client API implementation
22
/****************************************************************************/
23
#include <config.h>
24
25
#include <microsim/output/MSDetectorControl.h>
26
#include <microsim/output/MSE2Collector.h>
27
#include <microsim/MSNet.h>
28
#include <libsumo/Helper.h>
29
#include <libsumo/TraCIConstants.h>
30
#include "MultiEntryExit.h"
31
32
33
namespace libsumo {
34
// ===========================================================================
35
// static member initializations
36
// ===========================================================================
37
SubscriptionResults MultiEntryExit::mySubscriptionResults;
38
ContextSubscriptionResults MultiEntryExit::myContextSubscriptionResults;
39
40
41
// ===========================================================================
42
// static member definitions
43
// ===========================================================================
44
std::vector<std::string>
45
MultiEntryExit::getIDList() {
46
std::vector<std::string> ids;
47
MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).insertIDs(ids);
48
return ids;
49
}
50
51
52
int
53
MultiEntryExit::getIDCount() {
54
return (int)MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).size();
55
}
56
57
58
std::vector<std::string>
59
MultiEntryExit::getEntryLanes(const std::string& detID) {
60
std::vector<std::string> ids;
61
for (const MSCrossSection& cs : getDetector(detID)->getEntries()) {
62
ids.push_back(cs.myLane->getID());
63
}
64
return ids;
65
}
66
67
68
std::vector<std::string>
69
MultiEntryExit::getExitLanes(const std::string& detID) {
70
std::vector<std::string> ids;
71
for (const MSCrossSection& cs : getDetector(detID)->getExits()) {
72
ids.push_back(cs.myLane->getID());
73
}
74
return ids;
75
}
76
77
78
std::vector<double>
79
MultiEntryExit::getEntryPositions(const std::string& detID) {
80
std::vector<double> pos;
81
for (const MSCrossSection& cs : getDetector(detID)->getEntries()) {
82
pos.push_back(cs.myPosition);
83
}
84
return pos;
85
}
86
87
88
std::vector<double>
89
MultiEntryExit::getExitPositions(const std::string& detID) {
90
std::vector<double> pos;
91
for (const MSCrossSection& cs : getDetector(detID)->getExits()) {
92
pos.push_back(cs.myPosition);
93
}
94
return pos;
95
}
96
97
98
int
99
MultiEntryExit::getLastStepVehicleNumber(const std::string& detID) {
100
return getDetector(detID)->getVehiclesWithin();
101
}
102
103
104
double
105
MultiEntryExit::getLastStepMeanSpeed(const std::string& detID) {
106
return getDetector(detID)->getCurrentMeanSpeed();
107
}
108
109
110
std::vector<std::string>
111
MultiEntryExit::getLastStepVehicleIDs(const std::string& detID) {
112
return getDetector(detID)->getCurrentVehicleIDs();
113
}
114
115
116
int
117
MultiEntryExit::getLastStepHaltingNumber(const std::string& detID) {
118
return getDetector(detID)->getCurrentHaltingNumber();
119
}
120
121
122
double
123
MultiEntryExit::getLastIntervalMeanTravelTime(const std::string& detID) {
124
return getDetector(detID)->getLastIntervalMeanTravelTime();
125
}
126
127
128
double
129
MultiEntryExit::getLastIntervalMeanHaltsPerVehicle(const std::string& detID) {
130
return getDetector(detID)->getLastIntervalMeanHaltsPerVehicle();
131
}
132
133
134
double
135
MultiEntryExit::getLastIntervalMeanTimeLoss(const std::string& detID) {
136
return getDetector(detID)->getLastIntervalMeanTimeLoss();
137
}
138
139
140
int
141
MultiEntryExit::getLastIntervalVehicleSum(const std::string& detID) {
142
return getDetector(detID)->getLastIntervalVehicleSum();
143
}
144
145
146
std::string
147
MultiEntryExit::getParameter(const std::string& detID, const std::string& param) {
148
return getDetector(detID)->getParameter(param, "");
149
}
150
151
152
LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(MultiEntryExit)
153
154
155
void
156
MultiEntryExit::setParameter(const std::string& detID, const std::string& name, const std::string& value) {
157
getDetector(detID)->setParameter(name, value);
158
}
159
160
161
LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(MultiEntryExit, MULTIENTRYEXIT)
162
163
164
MSE3Collector*
165
MultiEntryExit::getDetector(const std::string& id) {
166
MSE3Collector* e3 = dynamic_cast<MSE3Collector*>(MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).get(id));
167
if (e3 == nullptr) {
168
throw TraCIException("Multi entry exit detector '" + id + "' is not known");
169
}
170
return e3;
171
}
172
173
174
std::shared_ptr<VariableWrapper>
175
MultiEntryExit::makeWrapper() {
176
return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
177
}
178
179
180
bool
181
MultiEntryExit::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
182
switch (variable) {
183
case TRACI_ID_LIST:
184
return wrapper->wrapStringList(objID, variable, getIDList());
185
case ID_COUNT:
186
return wrapper->wrapInt(objID, variable, getIDCount());
187
case LAST_STEP_VEHICLE_NUMBER:
188
return wrapper->wrapInt(objID, variable, getLastStepVehicleNumber(objID));
189
case LAST_STEP_MEAN_SPEED:
190
return wrapper->wrapDouble(objID, variable, getLastStepMeanSpeed(objID));
191
case LAST_STEP_VEHICLE_ID_LIST:
192
return wrapper->wrapStringList(objID, variable, getLastStepVehicleIDs(objID));
193
case LAST_STEP_VEHICLE_HALTING_NUMBER:
194
return wrapper->wrapInt(objID, variable, getLastStepHaltingNumber(objID));
195
case VAR_LAST_INTERVAL_TRAVELTIME:
196
return wrapper->wrapDouble(objID, variable, getLastIntervalMeanTravelTime(objID));
197
case VAR_LAST_INTERVAL_MEAN_HALTING_NUMBER:
198
return wrapper->wrapDouble(objID, variable, getLastIntervalMeanHaltsPerVehicle(objID));
199
case VAR_TIMELOSS:
200
return wrapper->wrapDouble(objID, variable, getLastIntervalMeanTimeLoss(objID));
201
case VAR_LAST_INTERVAL_VEHICLE_NUMBER:
202
return wrapper->wrapInt(objID, variable, getLastIntervalVehicleSum(objID));
203
case VAR_LANES:
204
return wrapper->wrapStringList(objID, variable, getEntryLanes(objID));
205
case VAR_EXIT_LANES:
206
return wrapper->wrapStringList(objID, variable, getExitLanes(objID));
207
case VAR_POSITION:
208
return wrapper->wrapDoubleList(objID, variable, getEntryPositions(objID));
209
case VAR_EXIT_POSITIONS:
210
return wrapper->wrapDoubleList(objID, variable, getExitPositions(objID));
211
case libsumo::VAR_PARAMETER:
212
paramData->readUnsignedByte();
213
return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
214
case libsumo::VAR_PARAMETER_WITH_KEY:
215
paramData->readUnsignedByte();
216
return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
217
default:
218
return false;
219
}
220
}
221
222
223
}
224
225
226
/****************************************************************************/
227
228