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