Eclipse SUMO - Simulation of Urban MObility
libsumo/MultiEntryExit.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2022 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/TraCIConstants.h>
29 #include "MultiEntryExit.h"
30 
31 
32 namespace libsumo {
33 // ===========================================================================
34 // static member initializations
35 // ===========================================================================
36 SubscriptionResults MultiEntryExit::mySubscriptionResults;
37 ContextSubscriptionResults MultiEntryExit::myContextSubscriptionResults;
38 
39 
40 // ===========================================================================
41 // static member definitions
42 // ===========================================================================
43 std::vector<std::string>
44 MultiEntryExit::getIDList() {
45  std::vector<std::string> ids;
47  return ids;
48 }
49 
50 
51 int
52 MultiEntryExit::getIDCount() {
53  std::vector<std::string> ids;
55 }
56 
57 
58 int
59 MultiEntryExit::getLastStepVehicleNumber(const std::string& detID) {
60  return getDetector(detID)->getVehiclesWithin();
61 }
62 
63 
64 double
65 MultiEntryExit::getLastStepMeanSpeed(const std::string& detID) {
66  return getDetector(detID)->getCurrentMeanSpeed();
67 }
68 
69 
70 std::vector<std::string>
71 MultiEntryExit::getLastStepVehicleIDs(const std::string& detID) {
72  return getDetector(detID)->getCurrentVehicleIDs();
73 }
74 
75 
76 int
77 MultiEntryExit::getLastStepHaltingNumber(const std::string& detID) {
78  return getDetector(detID)->getCurrentHaltingNumber();
79 }
80 
81 
82 double
83 MultiEntryExit::getLastIntervalMeanTravelTime(const std::string& detID) {
84  return getDetector(detID)->getLastIntervalMeanTravelTime();
85 }
86 
87 
88 double
89 MultiEntryExit::getLastIntervalMeanHaltsPerVehicle(const std::string& detID) {
90  return getDetector(detID)->getLastIntervalMeanHaltsPerVehicle();
91 }
92 
93 
94 double
95 MultiEntryExit::getLastIntervalMeanTimeLoss(const std::string& detID) {
96  return getDetector(detID)->getLastIntervalMeanTimeLoss();
97 }
98 
99 
100 int
101 MultiEntryExit::getLastIntervalVehicleSum(const std::string& detID) {
102  return getDetector(detID)->getLastIntervalVehicleSum();
103 }
104 
105 
106 std::string
107 MultiEntryExit::getParameter(const std::string& detID, const std::string& param) {
108  return getDetector(detID)->getParameter(param, "");
109 }
110 
111 
113 
114 
115 void
116 MultiEntryExit::setParameter(const std::string& detID, const std::string& name, const std::string& value) {
117  getDetector(detID)->setParameter(name, value);
118 }
119 
120 
122 
123 
125 MultiEntryExit::getDetector(const std::string& id) {
127  if (e3 == nullptr) {
128  throw TraCIException("Multi entry exit detector '" + id + "' is not known");
129  }
130  return e3;
131 }
132 
133 
134 std::shared_ptr<VariableWrapper>
135 MultiEntryExit::makeWrapper() {
136  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
137 }
138 
139 
140 bool
141 MultiEntryExit::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
142  switch (variable) {
143  case TRACI_ID_LIST:
144  return wrapper->wrapStringList(objID, variable, getIDList());
145  case ID_COUNT:
146  return wrapper->wrapInt(objID, variable, getIDCount());
148  return wrapper->wrapInt(objID, variable, getLastStepVehicleNumber(objID));
150  return wrapper->wrapDouble(objID, variable, getLastStepMeanSpeed(objID));
152  return wrapper->wrapStringList(objID, variable, getLastStepVehicleIDs(objID));
154  return wrapper->wrapInt(objID, variable, getLastStepHaltingNumber(objID));
156  return wrapper->wrapDouble(objID, variable, getLastIntervalMeanTravelTime(objID));
158  return wrapper->wrapDouble(objID, variable, getLastIntervalMeanHaltsPerVehicle(objID));
159  case VAR_TIMELOSS:
160  return wrapper->wrapDouble(objID, variable, getLastIntervalMeanTimeLoss(objID));
162  return wrapper->wrapInt(objID, variable, getLastIntervalVehicleSum(objID));
164  paramData->readUnsignedByte();
165  return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
167  paramData->readUnsignedByte();
168  return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
169  default:
170  return false;
171  }
172 }
173 
174 
175 }
176 
177 
178 /****************************************************************************/
@ SUMO_TAG_ENTRY_EXIT_DETECTOR
alternative tag for e3 detector
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:69
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition: TraCIDefs.h:115
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.
Definition: MSE3Collector.h:59
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:174
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:439
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 LAST_STEP_VEHICLE_NUMBER
TRACI_CONST int TRACI_ID_LIST
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:279
TRACI_CONST int VAR_TIMELOSS
TRACI_CONST int LAST_STEP_MEAN_SPEED
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:278
TRACI_CONST int LAST_STEP_VEHICLE_HALTING_NUMBER
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_LAST_INTERVAL_VEHICLE_NUMBER
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int VAR_LAST_INTERVAL_MEAN_HALTING_NUMBER