Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/MultiEntryExit.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-2024 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/****************************************************************************/
21// C++ TraCI client API implementation
22/****************************************************************************/
23#include <config.h>
24
27#include <microsim/MSNet.h>
28#include <libsumo/Helper.h>
30#include "MultiEntryExit.h"
31
32
33namespace libsumo {
34// ===========================================================================
35// static member initializations
36// ===========================================================================
37SubscriptionResults MultiEntryExit::mySubscriptionResults;
38ContextSubscriptionResults MultiEntryExit::myContextSubscriptionResults;
39
40
41// ===========================================================================
42// static member definitions
43// ===========================================================================
44std::vector<std::string>
45MultiEntryExit::getIDList() {
46 std::vector<std::string> ids;
48 return ids;
49}
50
51
52int
53MultiEntryExit::getIDCount() {
55}
56
57
58std::vector<std::string>
59MultiEntryExit::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
68std::vector<std::string>
69MultiEntryExit::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
78std::vector<double>
79MultiEntryExit::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
88std::vector<double>
89MultiEntryExit::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
98int
99MultiEntryExit::getLastStepVehicleNumber(const std::string& detID) {
100 return getDetector(detID)->getVehiclesWithin();
101}
102
103
104double
105MultiEntryExit::getLastStepMeanSpeed(const std::string& detID) {
106 return getDetector(detID)->getCurrentMeanSpeed();
107}
108
109
110std::vector<std::string>
111MultiEntryExit::getLastStepVehicleIDs(const std::string& detID) {
112 return getDetector(detID)->getCurrentVehicleIDs();
113}
114
115
116int
117MultiEntryExit::getLastStepHaltingNumber(const std::string& detID) {
118 return getDetector(detID)->getCurrentHaltingNumber();
119}
120
121
122double
123MultiEntryExit::getLastIntervalMeanTravelTime(const std::string& detID) {
124 return getDetector(detID)->getLastIntervalMeanTravelTime();
125}
126
127
128double
129MultiEntryExit::getLastIntervalMeanHaltsPerVehicle(const std::string& detID) {
130 return getDetector(detID)->getLastIntervalMeanHaltsPerVehicle();
131}
132
133
134double
135MultiEntryExit::getLastIntervalMeanTimeLoss(const std::string& detID) {
136 return getDetector(detID)->getLastIntervalMeanTimeLoss();
137}
138
139
140int
141MultiEntryExit::getLastIntervalVehicleSum(const std::string& detID) {
142 return getDetector(detID)->getLastIntervalVehicleSum();
143}
144
145
146std::string
147MultiEntryExit::getParameter(const std::string& detID, const std::string& param) {
148 return getDetector(detID)->getParameter(param, "");
149}
150
151
153
154
155void
156MultiEntryExit::setParameter(const std::string& detID, const std::string& name, const std::string& value) {
157 getDetector(detID)->setParameter(name, value);
158}
159
160
162
163
165MultiEntryExit::getDetector(const std::string& id) {
167 if (e3 == nullptr) {
168 throw TraCIException("Multi entry exit detector '" + id + "' is not known");
169 }
170 return e3;
171}
172
173
174std::shared_ptr<VariableWrapper>
175MultiEntryExit::makeWrapper() {
176 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
177}
178
179
180bool
181MultiEntryExit::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());
188 return wrapper->wrapInt(objID, variable, getLastStepVehicleNumber(objID));
190 return wrapper->wrapDouble(objID, variable, getLastStepMeanSpeed(objID));
192 return wrapper->wrapStringList(objID, variable, getLastStepVehicleIDs(objID));
194 return wrapper->wrapInt(objID, variable, getLastStepHaltingNumber(objID));
196 return wrapper->wrapDouble(objID, variable, getLastIntervalMeanTravelTime(objID));
198 return wrapper->wrapDouble(objID, variable, getLastIntervalMeanHaltsPerVehicle(objID));
199 case VAR_TIMELOSS:
200 return wrapper->wrapDouble(objID, variable, getLastIntervalMeanTimeLoss(objID));
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));
210 return wrapper->wrapDoubleList(objID, variable, getExitPositions(objID));
212 paramData->readUnsignedByte();
213 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
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/****************************************************************************/
@ SUMO_TAG_ENTRY_EXIT_DETECTOR
alternative tag for e3 detector
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:123
A simple description of a position on a lane (crossing of a lane)
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
A detector of vehicles passing an area between entry/exit points.
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition MSNet.h:441
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
C++ TraCI client API implementation.
T get(const std::string &id) const
Retrieves an item.
void insertIDs(std::vector< std::string > &into) const
int size() const
Returns the number of stored items within the container.
virtual std::string readString()
Definition storage.cpp:180
virtual int readUnsignedByte()
Definition storage.cpp:155
TRACI_CONST int VAR_LAST_INTERVAL_TRAVELTIME
TRACI_CONST int LAST_STEP_VEHICLE_ID_LIST
TRACI_CONST int VAR_EXIT_POSITIONS
TRACI_CONST int LAST_STEP_VEHICLE_NUMBER
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_LANES
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition TraCIDefs.h:338
TRACI_CONST int VAR_TIMELOSS
TRACI_CONST int VAR_POSITION
TRACI_CONST int LAST_STEP_MEAN_SPEED
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition TraCIDefs.h:337
TRACI_CONST int LAST_STEP_VEHICLE_HALTING_NUMBER
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_EXIT_LANES
TRACI_CONST int VAR_LAST_INTERVAL_VEHICLE_NUMBER
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int VAR_LAST_INTERVAL_MEAN_HALTING_NUMBER