Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libtraci/Lane.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2017-2025 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
/****************************************************************************/
14
/// @file Lane.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Mario Krumnow
17
/// @author Jakob Erdmann
18
/// @author Michael Behrisch
19
/// @author Robert Hilbrich
20
/// @author Leonhard Luecken
21
/// @author Mirko Barthauer
22
/// @date 30.05.2012
23
///
24
// C++ TraCI client API implementation
25
/****************************************************************************/
26
#include <config.h>
27
28
#define LIBTRACI 1
29
#include <libsumo/Lane.h>
30
#include <libsumo/TraCIConstants.h>
31
#include "Domain.h"
32
33
34
namespace libtraci {
35
36
typedef Domain<libsumo::CMD_GET_LANE_VARIABLE, libsumo::CMD_SET_LANE_VARIABLE> Dom;
37
38
39
40
// ===========================================================================
41
// static member definitions
42
// ===========================================================================
43
std::vector<std::string>
44
Lane::getIDList() {
45
return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
46
}
47
48
49
int
50
Lane::getIDCount() {
51
return Dom::getInt(libsumo::ID_COUNT, "");
52
}
53
54
55
std::string
56
Lane::getEdgeID(const std::string& laneID) {
57
return Dom::getString(libsumo::LANE_EDGE_ID, laneID);
58
}
59
60
61
double
62
Lane::getLength(const std::string& laneID) {
63
return Dom::getDouble(libsumo::VAR_LENGTH, laneID);
64
}
65
66
67
double
68
Lane::getMaxSpeed(const std::string& laneID) {
69
return Dom::getDouble(libsumo::VAR_MAXSPEED, laneID);
70
}
71
72
73
double
74
Lane::getFriction(const std::string& laneID) {
75
return Dom::getDouble(libsumo::VAR_FRICTION, laneID);
76
}
77
78
79
int
80
Lane::getLinkNumber(const std::string& laneID) {
81
return Dom::getInt(libsumo::LANE_LINK_NUMBER, laneID);
82
}
83
84
85
std::vector<libsumo::TraCIConnection>
86
Lane::getLinks(const std::string& laneID) {
87
std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
88
std::vector<libsumo::TraCIConnection> ret;
89
tcpip::Storage& sto = Dom::get(libsumo::LANE_LINKS, laneID);
90
sto.readUnsignedByte();
91
sto.readInt();
92
93
const int linkNo = sto.readInt();
94
for (int i = 0; i < linkNo; ++i) {
95
libsumo::TraCIConnection conn;
96
StoHelp::readConnection(sto, conn);
97
ret.emplace_back(conn);
98
}
99
return ret;
100
}
101
102
103
std::vector<std::string>
104
Lane::getAllowed(const std::string& laneID) {
105
return Dom::getStringVector(libsumo::LANE_ALLOWED, laneID);
106
}
107
108
109
std::vector<std::string>
110
Lane::getDisallowed(const std::string& laneID) {
111
return Dom::getStringVector(libsumo::LANE_DISALLOWED, laneID); // negation yields disallowed
112
}
113
114
115
std::vector<std::string>
116
Lane::getChangePermissions(const std::string& laneID, const int direction) {
117
tcpip::Storage content;
118
StoHelp::writeTypedByte(content, direction);
119
return Dom::getStringVector(libsumo::LANE_CHANGES, laneID, &content);
120
}
121
122
123
libsumo::TraCIPositionVector
124
Lane::getShape(const std::string& laneID) {
125
return Dom::getPolygon(libsumo::VAR_SHAPE, laneID);
126
}
127
128
129
double
130
Lane::getWidth(const std::string& laneID) {
131
return Dom::getDouble(libsumo::VAR_WIDTH, laneID);
132
}
133
134
135
double
136
Lane::getCO2Emission(const std::string& laneID) {
137
return Dom::getDouble(libsumo::VAR_CO2EMISSION, laneID);
138
}
139
140
141
double
142
Lane::getCOEmission(const std::string& laneID) {
143
return Dom::getDouble(libsumo::VAR_COEMISSION, laneID);
144
}
145
146
147
double
148
Lane::getHCEmission(const std::string& laneID) {
149
return Dom::getDouble(libsumo::VAR_HCEMISSION, laneID);
150
}
151
152
153
double
154
Lane::getPMxEmission(const std::string& laneID) {
155
return Dom::getDouble(libsumo::VAR_PMXEMISSION, laneID);
156
}
157
158
159
double
160
Lane::getNOxEmission(const std::string& laneID) {
161
return Dom::getDouble(libsumo::VAR_NOXEMISSION, laneID);
162
}
163
164
165
double
166
Lane::getFuelConsumption(const std::string& laneID) {
167
return Dom::getDouble(libsumo::VAR_FUELCONSUMPTION, laneID);
168
}
169
170
171
double
172
Lane::getNoiseEmission(const std::string& laneID) {
173
return Dom::getDouble(libsumo::VAR_NOISEEMISSION, laneID);
174
}
175
176
177
double
178
Lane::getElectricityConsumption(const std::string& laneID) {
179
return Dom::getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, laneID);
180
}
181
182
183
double
184
Lane::getLastStepMeanSpeed(const std::string& laneID) {
185
return Dom::getDouble(libsumo::LAST_STEP_MEAN_SPEED, laneID);
186
}
187
188
189
double
190
Lane::getLastStepOccupancy(const std::string& laneID) {
191
return Dom::getDouble(libsumo::LAST_STEP_OCCUPANCY, laneID);
192
}
193
194
195
double
196
Lane::getLastStepLength(const std::string& laneID) {
197
return Dom::getDouble(libsumo::LAST_STEP_LENGTH, laneID);
198
}
199
200
201
double
202
Lane::getWaitingTime(const std::string& laneID) {
203
return Dom::getDouble(libsumo::VAR_WAITING_TIME, laneID);
204
}
205
206
207
double
208
Lane::getTraveltime(const std::string& laneID) {
209
return Dom::getDouble(libsumo::VAR_CURRENT_TRAVELTIME, laneID);
210
}
211
212
213
int
214
Lane::getLastStepVehicleNumber(const std::string& laneID) {
215
return Dom::getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, laneID);
216
}
217
218
219
int
220
Lane::getLastStepHaltingNumber(const std::string& laneID) {
221
return Dom::getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, laneID);
222
}
223
224
225
std::vector<std::string>
226
Lane::getLastStepVehicleIDs(const std::string& laneID) {
227
return Dom::getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, laneID);
228
}
229
230
231
std::vector<std::string>
232
Lane::getFoes(const std::string& laneID, const std::string& toLaneID) {
233
tcpip::Storage content;
234
content.writeUnsignedByte(libsumo::TYPE_STRING);
235
content.writeString(toLaneID);
236
return Dom::getStringVector(libsumo::VAR_FOES, laneID, &content);
237
}
238
239
240
std::vector<std::string>
241
Lane::getInternalFoes(const std::string& laneID) {
242
return getFoes(laneID, "");
243
}
244
245
246
const std::vector<std::string>
247
Lane::getPendingVehicles(const std::string& laneID) {
248
return Dom::getStringVector(libsumo::VAR_PENDING_VEHICLES, laneID);
249
}
250
251
252
double
253
Lane::getAngle(const std::string& laneID, double relativePosition) {
254
tcpip::Storage content;
255
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
256
content.writeDouble(relativePosition);
257
return Dom::getDouble(libsumo::VAR_ANGLE, laneID, &content);
258
}
259
260
std::string
261
Lane::getBidiLane(const std::string& laneID) {
262
return Dom::getString(libsumo::VAR_BIDI, laneID);
263
}
264
265
void
266
Lane::setAllowed(const std::string& laneID, std::string allowedClass) {
267
setAllowed(laneID, std::vector<std::string>({allowedClass}));
268
}
269
270
271
void
272
Lane::setAllowed(const std::string& laneID, std::vector<std::string> allowedClasses) {
273
Dom::setStringVector(libsumo::LANE_ALLOWED, laneID, allowedClasses);
274
}
275
276
277
void
278
Lane::setDisallowed(const std::string& laneID, std::string disallowedClasses) {
279
setDisallowed(laneID, std::vector<std::string>({disallowedClasses}));
280
}
281
282
283
void
284
Lane::setDisallowed(const std::string& laneID, std::vector<std::string> disallowedClasses) {
285
Dom::setStringVector(libsumo::LANE_DISALLOWED, laneID, disallowedClasses);
286
}
287
288
289
void
290
Lane::setChangePermissions(const std::string& laneID, std::vector<std::string> allowedClasses, const int direction) {
291
tcpip::Storage content;
292
StoHelp::writeCompound(content, 2);
293
StoHelp::writeTypedStringList(content, allowedClasses);
294
StoHelp::writeTypedByte(content, direction);
295
Dom::set(libsumo::LANE_CHANGES, laneID, &content);
296
}
297
298
299
void
300
Lane::setMaxSpeed(const std::string& laneID, double speed) {
301
Dom::setDouble(libsumo::VAR_MAXSPEED, laneID, speed);
302
}
303
304
305
void
306
Lane::setFriction(const std::string& laneID, double friction) {
307
Dom::setDouble(libsumo::VAR_FRICTION, laneID, friction);
308
}
309
310
311
void
312
Lane::setLength(const std::string& laneID, double length) {
313
Dom::setDouble(libsumo::VAR_LENGTH, laneID, length);
314
}
315
316
317
LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(Lane, LANE)
318
LIBTRACI_PARAMETER_IMPLEMENTATION(Lane, LANE)
319
320
}
321
322
323
/****************************************************************************/
324
325