Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libtraci/Lane.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2017-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/****************************************************************************/
24// C++ TraCI client API implementation
25/****************************************************************************/
26#include <config.h>
27
28#define LIBTRACI 1
29#include <libsumo/Lane.h>
31#include "Domain.h"
32
33
34namespace libtraci {
35
36typedef Domain<libsumo::CMD_GET_LANE_VARIABLE, libsumo::CMD_SET_LANE_VARIABLE> Dom;
37
38
39
40// ===========================================================================
41// static member definitions
42// ===========================================================================
43std::vector<std::string>
44Lane::getIDList() {
46}
47
48
49int
50Lane::getIDCount() {
52}
53
54
55std::string
56Lane::getEdgeID(const std::string& laneID) {
58}
59
60
61double
62Lane::getLength(const std::string& laneID) {
63 return Dom::getDouble(libsumo::VAR_LENGTH, laneID);
64}
65
66
67double
68Lane::getMaxSpeed(const std::string& laneID) {
70}
71
72
73double
74Lane::getFriction(const std::string& laneID) {
76}
77
78
79int
80Lane::getLinkNumber(const std::string& laneID) {
82}
83
84
85std::vector<libsumo::TraCIConnection>
86Lane::getLinks(const std::string& laneID) {
87 std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
88 std::vector<libsumo::TraCIConnection> ret;
90 sto.readUnsignedByte();
91 sto.readInt();
92
93 int linkNo = sto.readInt();
94 for (int i = 0; i < linkNo; ++i) {
95
96 sto.readUnsignedByte();
97 std::string approachedLane = sto.readString();
98
99 sto.readUnsignedByte();
100 std::string approachedLaneInternal = sto.readString();
101
102 sto.readUnsignedByte();
103 bool hasPrio = sto.readUnsignedByte() != 0;
104
105 sto.readUnsignedByte();
106 bool isOpen = sto.readUnsignedByte() != 0;
107
108 sto.readUnsignedByte();
109 bool hasFoe = sto.readUnsignedByte() != 0;
110
111 sto.readUnsignedByte();
112 std::string state = sto.readString();
113
114 sto.readUnsignedByte();
115 std::string direction = sto.readString();
116
117 sto.readUnsignedByte();
118 double length = sto.readDouble();
119
120 ret.push_back(libsumo::TraCIConnection(approachedLane,
121 hasPrio,
122 isOpen,
123 hasFoe,
124 approachedLaneInternal,
125 state,
126 direction,
127 length));
128
129 }
130 return ret;
131}
132
133
134std::vector<std::string>
135Lane::getAllowed(const std::string& laneID) {
137}
138
139
140std::vector<std::string>
141Lane::getDisallowed(const std::string& laneID) {
142 return Dom::getStringVector(libsumo::LANE_DISALLOWED, laneID); // negation yields disallowed
143}
144
145
146std::vector<std::string>
147Lane::getChangePermissions(const std::string& laneID, const int direction) {
148 tcpip::Storage content;
149 StoHelp::writeTypedByte(content, direction);
150 return Dom::getStringVector(libsumo::LANE_CHANGES, laneID, &content);
151}
152
153
155Lane::getShape(const std::string& laneID) {
156 return Dom::getPolygon(libsumo::VAR_SHAPE, laneID);
157}
158
159
160double
161Lane::getWidth(const std::string& laneID) {
162 return Dom::getDouble(libsumo::VAR_WIDTH, laneID);
163}
164
165
166double
167Lane::getCO2Emission(const std::string& laneID) {
169}
170
171
172double
173Lane::getCOEmission(const std::string& laneID) {
175}
176
177
178double
179Lane::getHCEmission(const std::string& laneID) {
181}
182
183
184double
185Lane::getPMxEmission(const std::string& laneID) {
187}
188
189
190double
191Lane::getNOxEmission(const std::string& laneID) {
193}
194
195
196double
197Lane::getFuelConsumption(const std::string& laneID) {
199}
200
201
202double
203Lane::getNoiseEmission(const std::string& laneID) {
205}
206
207
208double
209Lane::getElectricityConsumption(const std::string& laneID) {
211}
212
213
214double
215Lane::getLastStepMeanSpeed(const std::string& laneID) {
217}
218
219
220double
221Lane::getLastStepOccupancy(const std::string& laneID) {
223}
224
225
226double
227Lane::getLastStepLength(const std::string& laneID) {
229}
230
231
232double
233Lane::getWaitingTime(const std::string& laneID) {
235}
236
237
238double
239Lane::getTraveltime(const std::string& laneID) {
241}
242
243
244int
245Lane::getLastStepVehicleNumber(const std::string& laneID) {
247}
248
249
250int
251Lane::getLastStepHaltingNumber(const std::string& laneID) {
253}
254
255
256std::vector<std::string>
257Lane::getLastStepVehicleIDs(const std::string& laneID) {
259}
260
261
262std::vector<std::string>
263Lane::getFoes(const std::string& laneID, const std::string& toLaneID) {
264 tcpip::Storage content;
266 content.writeString(toLaneID);
267 return Dom::getStringVector(libsumo::VAR_FOES, laneID, &content);
268}
269
270
271// XXX: there seems to be no "Dom::getFoes"
272std::vector<std::string>
273Lane::getInternalFoes(const std::string& laneID) {
274 //tcpip::Storage content;
275 //content.writeUnsignedByte(libsumo::TYPE_STRING);
276 //content.writeString("");
277 //return Dom::getStringVector(libsumo::VAR_FOES, laneID, &content);
278 return getFoes(laneID, "");
279 //return Dom::getFoes(laneID, "");
280}
281
282
283const std::vector<std::string>
284Lane::getPendingVehicles(const std::string& laneID) {
286}
287
288
289double
290Lane::getAngle(const std::string& laneID, double relativePosition) {
291 tcpip::Storage content;
293 content.writeDouble(relativePosition);
294 return Dom::getDouble(libsumo::VAR_ANGLE, laneID, &content);
295}
296
297std::string
298Lane::getBidiLane(const std::string& laneID) {
299 return Dom::getString(libsumo::VAR_BIDI, laneID);
300}
301
302void
303Lane::setAllowed(const std::string& laneID, std::string allowedClass) {
304 setAllowed(laneID, std::vector<std::string>({allowedClass}));
305}
306
307
308void
309Lane::setAllowed(const std::string& laneID, std::vector<std::string> allowedClasses) {
310 Dom::setStringVector(libsumo::LANE_ALLOWED, laneID, allowedClasses);
311}
312
313
314void
315Lane::setDisallowed(const std::string& laneID, std::string disallowedClasses) {
316 setDisallowed(laneID, std::vector<std::string>({disallowedClasses}));
317}
318
319
320void
321Lane::setDisallowed(const std::string& laneID, std::vector<std::string> disallowedClasses) {
322 Dom::setStringVector(libsumo::LANE_DISALLOWED, laneID, disallowedClasses);
323}
324
325
326void
327Lane::setChangePermissions(const std::string& laneID, std::vector<std::string> allowedClasses, const int direction) {
328 tcpip::Storage content;
329 StoHelp::writeCompound(content, 2);
330 StoHelp::writeTypedStringList(content, allowedClasses);
331 StoHelp::writeTypedByte(content, direction);
332 Dom::set(libsumo::LANE_CHANGES, laneID, &content);
333}
334
335
336void
337Lane::setMaxSpeed(const std::string& laneID, double speed) {
339}
340
341
342void
343Lane::setFriction(const std::string& laneID, double friction) {
344 Dom::setDouble(libsumo::VAR_FRICTION, laneID, friction);
345}
346
347
348void
349Lane::setLength(const std::string& laneID, double length) {
350 Dom::setDouble(libsumo::VAR_LENGTH, laneID, length);
351}
352
353
356
357}
358
359
360/****************************************************************************/
#define LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition Domain.h:38
#define LIBTRACI_PARAMETER_IMPLEMENTATION(CLASS, DOMAIN)
Definition Domain.h:77
C++ TraCI client API implementation.
static void writeCompound(tcpip::Storage &content, int size)
static void writeTypedStringList(tcpip::Storage &content, const std::vector< std::string > &value)
static void writeTypedByte(tcpip::Storage &content, int value)
static Connection & getActive()
Definition Connection.h:57
std::mutex & getMutex() const
Definition Connection.h:76
static void setDouble(int var, const std::string &id, double value)
Definition Domain.h:231
static std::vector< std::string > getStringVector(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:177
static void setStringVector(int var, const std::string &id, const std::vector< std::string > &value)
Definition Domain.h:245
static std::string getString(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:172
static int getInt(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:125
static libsumo::TraCIPositionVector getPolygon(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:135
static void set(int var, const std::string &id, tcpip::Storage *add)
Definition Domain.h:219
static double getDouble(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition Domain.h:130
static tcpip::Storage & get(int var, const std::string &id, tcpip::Storage *add=nullptr, int expectedType=libsumo::TYPE_COMPOUND)
Definition Domain.h:111
virtual std::string readString()
Definition storage.cpp:180
virtual void writeString(const std::string &s)
Definition storage.cpp:197
virtual void writeDouble(double)
Definition storage.cpp:354
virtual int readUnsignedByte()
Definition storage.cpp:155
virtual void writeUnsignedByte(int)
Definition storage.cpp:165
virtual double readDouble()
Definition storage.cpp:362
virtual int readInt()
Definition storage.cpp:311
TRACI_CONST int LAST_STEP_VEHICLE_ID_LIST
TRACI_CONST int LAST_STEP_VEHICLE_NUMBER
TRACI_CONST int VAR_NOXEMISSION
TRACI_CONST int LANE_LINKS
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_WAITING_TIME
TRACI_CONST int LANE_LINK_NUMBER
TRACI_CONST int LANE_CHANGES
TRACI_CONST int LAST_STEP_LENGTH
TRACI_CONST int VAR_ANGLE
TRACI_CONST int LANE_EDGE_ID
TRACI_CONST int VAR_PMXEMISSION
TRACI_CONST int VAR_COEMISSION
TRACI_CONST int VAR_WIDTH
TRACI_CONST int VAR_MAXSPEED
TRACI_CONST int LAST_STEP_MEAN_SPEED
TRACI_CONST int VAR_CO2EMISSION
TRACI_CONST int VAR_PENDING_VEHICLES
TRACI_CONST int VAR_FUELCONSUMPTION
TRACI_CONST int VAR_SHAPE
TRACI_CONST int LAST_STEP_VEHICLE_HALTING_NUMBER
TRACI_CONST int VAR_LENGTH
TRACI_CONST int VAR_HCEMISSION
TRACI_CONST int ID_COUNT
TRACI_CONST int LAST_STEP_OCCUPANCY
TRACI_CONST int VAR_BIDI
TRACI_CONST int VAR_NOISEEMISSION
TRACI_CONST int LANE_DISALLOWED
TRACI_CONST int VAR_FRICTION
TRACI_CONST int TYPE_DOUBLE
TRACI_CONST int VAR_CURRENT_TRAVELTIME
TRACI_CONST int VAR_FOES
TRACI_CONST int LANE_ALLOWED
TRACI_CONST int VAR_ELECTRICITYCONSUMPTION
TRACI_CONST int TYPE_STRING
Domain< libsumo::CMD_GET_BUSSTOP_VARIABLE, libsumo::CMD_SET_BUSSTOP_VARIABLE > Dom
A list of positions.
Definition TraCIDefs.h:234