Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/LaneArea.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 "LaneArea.h"
31
32
33namespace libsumo {
34// ===========================================================================
35// static member initializations
36// ===========================================================================
37SubscriptionResults LaneArea::mySubscriptionResults;
38ContextSubscriptionResults LaneArea::myContextSubscriptionResults;
39NamedRTree* LaneArea::myTree(nullptr);
40
41
42// ===========================================================================
43// static member definitions
44// ===========================================================================
45std::vector<std::string>
46LaneArea::getIDList() {
47 std::vector<std::string> ids;
49 return ids;
50}
51
52
53int
54LaneArea::getIDCount() {
55 std::vector<std::string> ids;
57}
58
59
60int
61LaneArea::getJamLengthVehicle(const std::string& detID) {
62 return getDetector(detID)->getCurrentJamLengthInVehicles();
63}
64
65
66double
67LaneArea::getJamLengthMeters(const std::string& detID) {
68 return getDetector(detID)->getCurrentJamLengthInMeters();
69}
70
71
72double
73LaneArea::getLastStepMeanSpeed(const std::string& detID) {
74 return getDetector(detID)->getCurrentMeanSpeed();
75}
76
77
78std::vector<std::string>
79LaneArea::getLastStepVehicleIDs(const std::string& detID) {
80 return getDetector(detID)->getCurrentVehicleIDs();
81}
82
83
84double
85LaneArea::getLastStepOccupancy(const std::string& detID) {
86 return getDetector(detID)->getCurrentOccupancy();
87}
88
89
90double
91LaneArea::getPosition(const std::string& detID) {
92 return getDetector(detID)->getStartPos();
93}
94
95
96std::string
97LaneArea::getLaneID(const std::string& detID) {
98 return getDetector(detID)->getLane()->getID();
99}
100
101
102double
103LaneArea::getLength(const std::string& detID) {
104 const MSE2Collector* const e2 = getDetector(detID);
105 return e2->getLength();
106}
107
108
109int
110LaneArea::getLastStepVehicleNumber(const std::string& detID) {
111 return getDetector(detID)->getCurrentVehicleNumber();
112}
113
114
115int
116LaneArea::getLastStepHaltingNumber(const std::string& detID) {
117 return getDetector(detID)->getCurrentHaltingNumber();
118}
119
120
121double
122LaneArea::getIntervalOccupancy(const std::string& detID) {
123 return getDetector(detID)->getIntervalOccupancy();
124}
125
126double
127LaneArea::getIntervalMeanSpeed(const std::string& detID) {
128 return getDetector(detID)->getIntervalMeanSpeed();
129}
130
131double
132LaneArea::getIntervalMaxJamLengthInMeters(const std::string& detID) {
133 return getDetector(detID)->getIntervalMaxJamLengthInMeters();
134}
135
136int
137LaneArea::getIntervalVehicleNumber(const std::string& detID) {
138 return getDetector(detID)->getIntervalVehicleNumber();
139}
140
141double
142LaneArea::getLastIntervalOccupancy(const std::string& detID) {
143 return getDetector(detID)->getLastIntervalOccupancy();
144}
145
146double
147LaneArea::getLastIntervalMeanSpeed(const std::string& detID) {
148 return getDetector(detID)->getLastIntervalMeanSpeed();
149}
150
151double
152LaneArea::getLastIntervalMaxJamLengthInMeters(const std::string& detID) {
153 return getDetector(detID)->getLastIntervalMaxJamLengthInMeters();
154}
155
156int
157LaneArea::getLastIntervalVehicleNumber(const std::string& detID) {
158 return getDetector(detID)->getLastIntervalVehicleNumber();
159}
160
161
162std::string
163LaneArea::getParameter(const std::string& detID, const std::string& param) {
164 return getDetector(detID)->getParameter(param, "");
165}
166
167
169
170
171void
172LaneArea::setParameter(const std::string& detID, const std::string& name, const std::string& value) {
173 getDetector(detID)->setParameter(name, value);
174}
175
176
178
179
181LaneArea::getDetector(const std::string& id) {
183 if (e2 == nullptr) {
184 throw TraCIException("Lane area detector '" + id + "' is not known");
185 }
186 return e2;
187}
188
189
191LaneArea::getTree() {
192 if (myTree == nullptr) {
193 myTree = new NamedRTree();
194 for (const std::string& id : getIDList()) {
195 PositionVector shape;
196 storeShape(id, shape);
197 Boundary b = shape.getBoxBoundary();
198 const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
199 const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
200 myTree->Insert(cmin, cmax, getDetector(id));
201 }
202 }
203 return myTree;
204}
205
206
207void
208LaneArea::cleanup() {
209 delete myTree;
210 myTree = nullptr;
211}
212
213
214void
215LaneArea::storeShape(const std::string& id, PositionVector& shape) {
216 MSE2Collector* const det = getDetector(id);
217 shape.push_back(det->getLanes().front()->getShape().positionAtOffset(det->getStartPos()));
218 shape.push_back(det->getLanes().back()->getShape().positionAtOffset(det->getEndPos()));
219}
220
221
222std::shared_ptr<VariableWrapper>
223LaneArea::makeWrapper() {
224 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
225}
226
227
228void
229LaneArea::overrideVehicleNumber(const std::string& detID, int vehNum) {
230 getDetector(detID)->overrideVehicleNumber(vehNum);
231}
232
233
234bool
235LaneArea::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
236 switch (variable) {
237 case TRACI_ID_LIST:
238 return wrapper->wrapStringList(objID, variable, getIDList());
239 case ID_COUNT:
240 return wrapper->wrapInt(objID, variable, getIDCount());
242 return wrapper->wrapInt(objID, variable, getLastStepVehicleNumber(objID));
244 return wrapper->wrapDouble(objID, variable, getLastStepMeanSpeed(objID));
246 return wrapper->wrapStringList(objID, variable, getLastStepVehicleIDs(objID));
248 return wrapper->wrapInt(objID, variable, getLastStepHaltingNumber(objID));
250 return wrapper->wrapInt(objID, variable, getJamLengthVehicle(objID));
252 return wrapper->wrapDouble(objID, variable, getJamLengthMeters(objID));
254 return wrapper->wrapDouble(objID, variable, getLastStepOccupancy(objID));
255 case VAR_POSITION:
256 return wrapper->wrapDouble(objID, variable, getPosition(objID));
257 case VAR_LANE_ID:
258 return wrapper->wrapString(objID, variable, getLaneID(objID));
259 case VAR_LENGTH:
260 return wrapper->wrapDouble(objID, variable, getLength(objID));
262 return wrapper->wrapDouble(objID, variable, getIntervalOccupancy(objID));
264 return wrapper->wrapDouble(objID, variable, getIntervalMeanSpeed(objID));
266 return wrapper->wrapDouble(objID, variable, getIntervalMaxJamLengthInMeters(objID));
268 return wrapper->wrapInt(objID, variable, getIntervalVehicleNumber(objID));
270 return wrapper->wrapDouble(objID, variable, getLastIntervalOccupancy(objID));
272 return wrapper->wrapDouble(objID, variable, getLastIntervalMeanSpeed(objID));
274 return wrapper->wrapDouble(objID, variable, getLastIntervalMaxJamLengthInMeters(objID));
276 return wrapper->wrapInt(objID, variable, getLastIntervalVehicleNumber(objID));
278 paramData->readUnsignedByte();
279 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
281 paramData->readUnsignedByte();
282 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
283 default:
284 return false;
285 }
286}
287
288
289}
290
291
292/****************************************************************************/
@ SUMO_TAG_LANE_AREA_DETECTOR
alternative tag for e2 detector
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:123
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:130
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:118
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:136
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:124
C++ TraCI client API implementation.
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.
std::vector< MSLane * > getLanes()
Returns a vector containing pointers to the lanes covered by the detector ordered from its first to i...
double getStartPos() const
Returns the begin position of the detector.
double getEndPos() const
Returns the end position of the detector.
double getLength() const
Returns the length of the detector.
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:185
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.
A RT-tree for efficient storing of SUMO's Named objects.
Definition NamedRTree.h:61
A list of positions.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
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 VAR_INTERVAL_NUMBER
TRACI_CONST int LAST_STEP_VEHICLE_NUMBER
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_LAST_INTERVAL_NUMBER
TRACI_CONST int VAR_LAST_INTERVAL_MAX_JAM_LENGTH_METERS
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition TraCIDefs.h:338
TRACI_CONST int VAR_INTERVAL_MAX_JAM_LENGTH_METERS
TRACI_CONST int VAR_POSITION
TRACI_CONST int LAST_STEP_MEAN_SPEED
TRACI_CONST int VAR_LAST_INTERVAL_OCCUPANCY
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition TraCIDefs.h:337
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 VAR_INTERVAL_SPEED
TRACI_CONST int VAR_LAST_INTERVAL_SPEED
TRACI_CONST int VAR_INTERVAL_OCCUPANCY
TRACI_CONST int JAM_LENGTH_VEHICLE