Eclipse SUMO - Simulation of Urban MObility
libsumo/LaneArea.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 "LaneArea.h"
30 
31 
32 namespace libsumo {
33 // ===========================================================================
34 // static member initializations
35 // ===========================================================================
36 SubscriptionResults LaneArea::mySubscriptionResults;
37 ContextSubscriptionResults LaneArea::myContextSubscriptionResults;
38 
39 
40 // ===========================================================================
41 // static member definitions
42 // ===========================================================================
43 std::vector<std::string>
44 LaneArea::getIDList() {
45  std::vector<std::string> ids;
47  return ids;
48 }
49 
50 
51 int
52 LaneArea::getIDCount() {
53  std::vector<std::string> ids;
55 }
56 
57 
58 int
59 LaneArea::getJamLengthVehicle(const std::string& detID) {
60  return getDetector(detID)->getCurrentJamLengthInVehicles();
61 }
62 
63 
64 double
65 LaneArea::getJamLengthMeters(const std::string& detID) {
66  return getDetector(detID)->getCurrentJamLengthInMeters();
67 }
68 
69 
70 double
71 LaneArea::getLastStepMeanSpeed(const std::string& detID) {
72  return getDetector(detID)->getCurrentMeanSpeed();
73 }
74 
75 
76 std::vector<std::string>
77 LaneArea::getLastStepVehicleIDs(const std::string& detID) {
78  return getDetector(detID)->getCurrentVehicleIDs();
79 }
80 
81 
82 double
83 LaneArea::getLastStepOccupancy(const std::string& detID) {
84  return getDetector(detID)->getCurrentOccupancy();
85 }
86 
87 
88 double
89 LaneArea::getPosition(const std::string& detID) {
90  return getDetector(detID)->getStartPos();
91 }
92 
93 
94 std::string
95 LaneArea::getLaneID(const std::string& detID) {
96  return getDetector(detID)->getLane()->getID();
97 }
98 
99 
100 double
101 LaneArea::getLength(const std::string& detID) {
102  const MSE2Collector* const e2 = getDetector(detID);
103  return e2->getLength();
104 }
105 
106 
107 int
108 LaneArea::getLastStepVehicleNumber(const std::string& detID) {
109  return getDetector(detID)->getCurrentVehicleNumber();
110 }
111 
112 
113 int
114 LaneArea::getLastStepHaltingNumber(const std::string& detID) {
115  return getDetector(detID)->getCurrentHaltingNumber();
116 }
117 
118 
119 std::string
120 LaneArea::getParameter(const std::string& detID, const std::string& param) {
121  return getDetector(detID)->getParameter(param, "");
122 }
123 
124 
126 
127 
128 void
129 LaneArea::setParameter(const std::string& detID, const std::string& name, const std::string& value) {
130  getDetector(detID)->setParameter(name, value);
131 }
132 
133 
135 
136 
138 LaneArea::getDetector(const std::string& id) {
140  if (e2 == nullptr) {
141  throw TraCIException("Lane area detector '" + id + "' is not known");
142  }
143  return e2;
144 }
145 
146 
147 std::shared_ptr<VariableWrapper>
148 LaneArea::makeWrapper() {
149  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
150 }
151 
152 
153 bool
154 LaneArea::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
155  switch (variable) {
156  case TRACI_ID_LIST:
157  return wrapper->wrapStringList(objID, variable, getIDList());
158  case ID_COUNT:
159  return wrapper->wrapInt(objID, variable, getIDCount());
161  return wrapper->wrapInt(objID, variable, getLastStepVehicleNumber(objID));
163  return wrapper->wrapDouble(objID, variable, getLastStepMeanSpeed(objID));
165  return wrapper->wrapStringList(objID, variable, getLastStepVehicleIDs(objID));
167  return wrapper->wrapInt(objID, variable, getLastStepHaltingNumber(objID));
168  case JAM_LENGTH_VEHICLE:
169  return wrapper->wrapInt(objID, variable, getJamLengthVehicle(objID));
170  case JAM_LENGTH_METERS:
171  return wrapper->wrapDouble(objID, variable, getJamLengthMeters(objID));
172  case LAST_STEP_OCCUPANCY:
173  return wrapper->wrapDouble(objID, variable, getLastStepOccupancy(objID));
174  case VAR_POSITION:
175  return wrapper->wrapDouble(objID, variable, getPosition(objID));
176  case VAR_LANE_ID:
177  return wrapper->wrapString(objID, variable, getLaneID(objID));
178  case VAR_LENGTH:
179  return wrapper->wrapDouble(objID, variable, getLength(objID));
181  paramData->readUnsignedByte();
182  return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
184  paramData->readUnsignedByte();
185  return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
186  default:
187  return false;
188  }
189 }
190 
191 
192 }
193 
194 
195 /****************************************************************************/
@ SUMO_TAG_LANE_AREA_DETECTOR
alternative tag for e2 detector
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:69
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition: TraCIDefs.h:115
C++ TraCI client API implementation.
Definition: LaneArea.h:30
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
An areal detector corresponding to a sequence of consecutive lanes.
Definition: MSE2Collector.h:79
double getLength() const
Returns the length of the detector.
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
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 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_POSITION
TRACI_CONST int LAST_STEP_MEAN_SPEED
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:278
TRACI_CONST int JAM_LENGTH_METERS
TRACI_CONST int LAST_STEP_VEHICLE_HALTING_NUMBER
TRACI_CONST int VAR_LENGTH
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_LANE_ID
TRACI_CONST int LAST_STEP_OCCUPANCY
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int JAM_LENGTH_VEHICLE