Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libtraci/Edge.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 Edge.cpp
15
/// @author Gregor Laemmel
16
/// @date 15.09.2017
17
///
18
// C++ TraCI client API implementation
19
/****************************************************************************/
20
#include <config.h>
21
22
#define LIBTRACI 1
23
#include <iterator>
24
#include <libsumo/Edge.h>
25
#include "Connection.h"
26
#include "Domain.h"
27
28
29
namespace libtraci {
30
31
typedef Domain<libsumo::CMD_GET_EDGE_VARIABLE, libsumo::CMD_SET_EDGE_VARIABLE> Dom;
32
33
34
// ===========================================================================
35
// static member definitions
36
// ===========================================================================
37
std::vector<std::string>
38
Edge::getIDList() {
39
return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
40
}
41
42
43
int
44
Edge::getIDCount() {
45
return Dom::getInt(libsumo::ID_COUNT, "");
46
}
47
48
49
double
50
Edge::getAdaptedTraveltime(const std::string& edgeID, double time) {
51
tcpip::Storage content;
52
content.writeByte(libsumo::TYPE_DOUBLE);
53
content.writeDouble(time);
54
return Dom::getDouble(libsumo::VAR_EDGE_TRAVELTIME, edgeID, &content);
55
}
56
57
58
double
59
Edge::getEffort(const std::string& edgeID, double time) {
60
tcpip::Storage content;
61
content.writeByte(libsumo::TYPE_DOUBLE);
62
content.writeDouble(time);
63
return Dom::getDouble(libsumo::VAR_EDGE_EFFORT, edgeID, &content);
64
}
65
66
67
double
68
Edge::getTraveltime(const std::string& edgeID) {
69
return Dom::getDouble(libsumo::VAR_CURRENT_TRAVELTIME, edgeID);
70
}
71
72
73
double
74
Edge::getWaitingTime(const std::string& edgeID) {
75
return Dom::getDouble(libsumo::VAR_WAITING_TIME, edgeID);
76
}
77
78
79
const std::vector<std::string>
80
Edge::getLastStepPersonIDs(const std::string& edgeID) {
81
return Dom::getStringVector(libsumo::LAST_STEP_PERSON_ID_LIST, edgeID);
82
}
83
84
85
const std::vector<std::string>
86
Edge::getLastStepVehicleIDs(const std::string& edgeID) {
87
return Dom::getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, edgeID);
88
}
89
90
91
double
92
Edge::getCO2Emission(const std::string& edgeID) {
93
return Dom::getDouble(libsumo::VAR_CO2EMISSION, edgeID);
94
}
95
96
97
double
98
Edge::getCOEmission(const std::string& edgeID) {
99
return Dom::getDouble(libsumo::VAR_COEMISSION, edgeID);
100
}
101
102
103
double
104
Edge::getHCEmission(const std::string& edgeID) {
105
return Dom::getDouble(libsumo::VAR_HCEMISSION, edgeID);
106
}
107
108
109
double
110
Edge::getPMxEmission(const std::string& edgeID) {
111
return Dom::getDouble(libsumo::VAR_PMXEMISSION, edgeID);
112
}
113
114
115
double
116
Edge::getNOxEmission(const std::string& edgeID) {
117
return Dom::getDouble(libsumo::VAR_NOXEMISSION, edgeID);
118
}
119
120
121
double
122
Edge::getFuelConsumption(const std::string& edgeID) {
123
return Dom::getDouble(libsumo::VAR_FUELCONSUMPTION, edgeID);
124
}
125
126
127
double
128
Edge::getNoiseEmission(const std::string& edgeID) {
129
return Dom::getDouble(libsumo::VAR_NOISEEMISSION, edgeID);
130
}
131
132
133
double
134
Edge::getElectricityConsumption(const std::string& edgeID) {
135
return Dom::getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, edgeID);
136
}
137
138
139
int
140
Edge::getLastStepVehicleNumber(const std::string& edgeID) {
141
return Dom::getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, edgeID);
142
}
143
144
145
double
146
Edge::getLastStepMeanSpeed(const std::string& edgeID) {
147
return Dom::getDouble(libsumo::LAST_STEP_MEAN_SPEED, edgeID);
148
}
149
150
151
double
152
Edge::getMeanFriction(const std::string& edgeID) {
153
return Dom::getDouble(libsumo::VAR_FRICTION, edgeID);
154
}
155
156
157
double
158
Edge::getLastStepOccupancy(const std::string& edgeID) {
159
return Dom::getDouble(libsumo::LAST_STEP_OCCUPANCY, edgeID);
160
}
161
162
163
int
164
Edge::getLastStepHaltingNumber(const std::string& edgeID) {
165
return Dom::getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, edgeID);
166
}
167
168
169
double
170
Edge::getLastStepLength(const std::string& edgeID) {
171
return Dom::getDouble(libsumo::LAST_STEP_LENGTH, edgeID);
172
}
173
174
175
int
176
Edge::getLaneNumber(const std::string& edgeID) {
177
return Dom::getInt(libsumo::VAR_LANE_INDEX, edgeID);
178
}
179
180
181
std::string
182
Edge::getStreetName(const std::string& edgeID) {
183
return Dom::getString(libsumo::VAR_NAME, edgeID);
184
}
185
186
187
const std::vector<std::string>
188
Edge::getPendingVehicles(const std::string& edgeID) {
189
return Dom::getStringVector(libsumo::VAR_PENDING_VEHICLES, edgeID);
190
}
191
192
193
double
194
Edge::getAngle(const std::string& edgeID, double relativePosition) {
195
tcpip::Storage content;
196
content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
197
content.writeDouble(relativePosition);
198
return Dom::getDouble(libsumo::VAR_ANGLE, edgeID, &content);
199
}
200
201
202
std::string
203
Edge::getFromJunction(const std::string& edgeID) {
204
return Dom::getString(libsumo::FROM_JUNCTION, edgeID);
205
}
206
207
208
std::string
209
Edge::getToJunction(const std::string& edgeID) {
210
return Dom::getString(libsumo::TO_JUNCTION, edgeID);
211
}
212
213
std::string
214
Edge::getBidiEdge(const std::string& edgeID) {
215
return Dom::getString(libsumo::VAR_BIDI, edgeID);
216
}
217
218
LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(Edge, EDGE)
219
LIBTRACI_PARAMETER_IMPLEMENTATION(Edge, EDGE)
220
221
222
void
223
Edge::setAllowed(const std::string& edgeID, std::string allowedClasses) {
224
setAllowed(edgeID, std::vector<std::string>({allowedClasses}));
225
}
226
227
228
void
229
Edge::setAllowed(const std::string& edgeID, std::vector<std::string> allowedClasses) {
230
Dom::setStringVector(libsumo::LANE_ALLOWED, edgeID, allowedClasses);
231
}
232
233
234
void
235
Edge::setDisallowed(const std::string& edgeID, std::string disallowedClasses) {
236
setDisallowed(edgeID, std::vector<std::string>({disallowedClasses}));
237
}
238
239
240
void
241
Edge::setDisallowed(const std::string& edgeID, std::vector<std::string> disallowedClasses) {
242
Dom::setStringVector(libsumo::LANE_DISALLOWED, edgeID, disallowedClasses);
243
}
244
245
246
void
247
Edge::adaptTraveltime(const std::string& edgeID, double time, double beginSeconds, double endSeconds) {
248
tcpip::Storage content;
249
content.writeByte(libsumo::TYPE_COMPOUND);
250
if (endSeconds != std::numeric_limits<double>::max()) {
251
content.writeInt(3);
252
content.writeByte(libsumo::TYPE_DOUBLE);
253
content.writeDouble(beginSeconds);
254
content.writeByte(libsumo::TYPE_DOUBLE);
255
content.writeDouble(endSeconds);
256
} else {
257
content.writeInt(1);
258
}
259
content.writeByte(libsumo::TYPE_DOUBLE);
260
content.writeDouble(time);
261
Dom::set(libsumo::VAR_EDGE_TRAVELTIME, edgeID, &content);
262
}
263
264
265
void
266
Edge::setEffort(const std::string& edgeID, double effort, double beginSeconds, double endSeconds) {
267
tcpip::Storage content;
268
content.writeByte(libsumo::TYPE_COMPOUND);
269
if (endSeconds != std::numeric_limits<double>::max()) {
270
content.writeInt(3);
271
content.writeByte(libsumo::TYPE_DOUBLE);
272
content.writeDouble(beginSeconds);
273
content.writeByte(libsumo::TYPE_DOUBLE);
274
content.writeDouble(endSeconds);
275
} else {
276
content.writeInt(1);
277
}
278
content.writeByte(libsumo::TYPE_DOUBLE);
279
content.writeDouble(effort);
280
Dom::set(libsumo::VAR_EDGE_EFFORT, edgeID, &content);
281
}
282
283
284
void
285
Edge::setMaxSpeed(const std::string& edgeID, double speed) {
286
Dom::setDouble(libsumo::VAR_MAXSPEED, edgeID, speed);
287
}
288
289
290
void
291
Edge::setFriction(const std::string& edgeID, double friction) {
292
Dom::setDouble(libsumo::VAR_MAXSPEED, edgeID, friction);
293
}
294
295
}
296
297
298
/****************************************************************************/
299
300