Line data Source code
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 53 : Lane::getIDList() {
45 105 : return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
46 : }
47 :
48 :
49 : int
50 2 : Lane::getIDCount() {
51 4 : return Dom::getInt(libsumo::ID_COUNT, "");
52 : }
53 :
54 :
55 : std::string
56 3 : Lane::getEdgeID(const std::string& laneID) {
57 3 : return Dom::getString(libsumo::LANE_EDGE_ID, laneID);
58 : }
59 :
60 :
61 : double
62 2200 : Lane::getLength(const std::string& laneID) {
63 2200 : return Dom::getDouble(libsumo::VAR_LENGTH, laneID);
64 : }
65 :
66 :
67 : double
68 7 : Lane::getMaxSpeed(const std::string& laneID) {
69 7 : return Dom::getDouble(libsumo::VAR_MAXSPEED, laneID);
70 : }
71 :
72 :
73 : double
74 0 : Lane::getFriction(const std::string& laneID) {
75 0 : return Dom::getDouble(libsumo::VAR_FRICTION, laneID);
76 : }
77 :
78 :
79 : int
80 3 : Lane::getLinkNumber(const std::string& laneID) {
81 3 : return Dom::getInt(libsumo::LANE_LINK_NUMBER, laneID);
82 : }
83 :
84 :
85 : std::vector<libsumo::TraCIConnection>
86 8 : Lane::getLinks(const std::string& laneID) {
87 8 : 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 8 : sto.readUnsignedByte();
91 8 : sto.readInt();
92 :
93 8 : const int linkNo = sto.readInt();
94 25 : for (int i = 0; i < linkNo; ++i) {
95 : libsumo::TraCIConnection conn;
96 17 : StoHelp::readConnection(sto, conn);
97 17 : ret.emplace_back(conn);
98 17 : }
99 8 : return ret;
100 0 : }
101 :
102 :
103 : std::vector<std::string>
104 14 : Lane::getAllowed(const std::string& laneID) {
105 14 : return Dom::getStringVector(libsumo::LANE_ALLOWED, laneID);
106 : }
107 :
108 :
109 : std::vector<std::string>
110 11 : Lane::getDisallowed(const std::string& laneID) {
111 11 : return Dom::getStringVector(libsumo::LANE_DISALLOWED, laneID); // negation yields disallowed
112 : }
113 :
114 :
115 : std::vector<std::string>
116 8 : Lane::getChangePermissions(const std::string& laneID, const int direction) {
117 8 : tcpip::Storage content;
118 : StoHelp::writeTypedByte(content, direction);
119 16 : return Dom::getStringVector(libsumo::LANE_CHANGES, laneID, &content);
120 8 : }
121 :
122 :
123 : libsumo::TraCIPositionVector
124 4007 : Lane::getShape(const std::string& laneID) {
125 4007 : return Dom::getPolygon(libsumo::VAR_SHAPE, laneID);
126 : }
127 :
128 :
129 : double
130 3 : Lane::getWidth(const std::string& laneID) {
131 3 : return Dom::getDouble(libsumo::VAR_WIDTH, laneID);
132 : }
133 :
134 :
135 : double
136 3 : Lane::getCO2Emission(const std::string& laneID) {
137 3 : return Dom::getDouble(libsumo::VAR_CO2EMISSION, laneID);
138 : }
139 :
140 :
141 : double
142 3 : Lane::getCOEmission(const std::string& laneID) {
143 3 : return Dom::getDouble(libsumo::VAR_COEMISSION, laneID);
144 : }
145 :
146 :
147 : double
148 3 : Lane::getHCEmission(const std::string& laneID) {
149 3 : return Dom::getDouble(libsumo::VAR_HCEMISSION, laneID);
150 : }
151 :
152 :
153 : double
154 3 : Lane::getPMxEmission(const std::string& laneID) {
155 3 : return Dom::getDouble(libsumo::VAR_PMXEMISSION, laneID);
156 : }
157 :
158 :
159 : double
160 3 : Lane::getNOxEmission(const std::string& laneID) {
161 3 : return Dom::getDouble(libsumo::VAR_NOXEMISSION, laneID);
162 : }
163 :
164 :
165 : double
166 3 : Lane::getFuelConsumption(const std::string& laneID) {
167 3 : return Dom::getDouble(libsumo::VAR_FUELCONSUMPTION, laneID);
168 : }
169 :
170 :
171 : double
172 3 : Lane::getNoiseEmission(const std::string& laneID) {
173 3 : return Dom::getDouble(libsumo::VAR_NOISEEMISSION, laneID);
174 : }
175 :
176 :
177 : double
178 3 : Lane::getElectricityConsumption(const std::string& laneID) {
179 3 : return Dom::getDouble(libsumo::VAR_ELECTRICITYCONSUMPTION, laneID);
180 : }
181 :
182 :
183 : double
184 3 : Lane::getLastStepMeanSpeed(const std::string& laneID) {
185 3 : return Dom::getDouble(libsumo::LAST_STEP_MEAN_SPEED, laneID);
186 : }
187 :
188 :
189 : double
190 3 : Lane::getLastStepOccupancy(const std::string& laneID) {
191 3 : return Dom::getDouble(libsumo::LAST_STEP_OCCUPANCY, laneID);
192 : }
193 :
194 :
195 : double
196 3 : Lane::getLastStepLength(const std::string& laneID) {
197 3 : return Dom::getDouble(libsumo::LAST_STEP_LENGTH, laneID);
198 : }
199 :
200 :
201 : double
202 3 : Lane::getWaitingTime(const std::string& laneID) {
203 3 : return Dom::getDouble(libsumo::VAR_WAITING_TIME, laneID);
204 : }
205 :
206 :
207 : double
208 3 : Lane::getTraveltime(const std::string& laneID) {
209 3 : return Dom::getDouble(libsumo::VAR_CURRENT_TRAVELTIME, laneID);
210 : }
211 :
212 :
213 : int
214 3 : Lane::getLastStepVehicleNumber(const std::string& laneID) {
215 3 : return Dom::getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, laneID);
216 : }
217 :
218 :
219 : int
220 3 : Lane::getLastStepHaltingNumber(const std::string& laneID) {
221 3 : return Dom::getInt(libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER, laneID);
222 : }
223 :
224 :
225 : std::vector<std::string>
226 209 : Lane::getLastStepVehicleIDs(const std::string& laneID) {
227 209 : return Dom::getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, laneID);
228 : }
229 :
230 :
231 : std::vector<std::string>
232 5 : Lane::getFoes(const std::string& laneID, const std::string& toLaneID) {
233 5 : tcpip::Storage content;
234 5 : content.writeUnsignedByte(libsumo::TYPE_STRING);
235 5 : content.writeString(toLaneID);
236 10 : return Dom::getStringVector(libsumo::VAR_FOES, laneID, &content);
237 5 : }
238 :
239 :
240 : std::vector<std::string>
241 2 : Lane::getInternalFoes(const std::string& laneID) {
242 4 : return getFoes(laneID, "");
243 : }
244 :
245 :
246 : const std::vector<std::string>
247 9 : Lane::getPendingVehicles(const std::string& laneID) {
248 9 : return Dom::getStringVector(libsumo::VAR_PENDING_VEHICLES, laneID);
249 : }
250 :
251 :
252 : double
253 4 : Lane::getAngle(const std::string& laneID, double relativePosition) {
254 4 : tcpip::Storage content;
255 4 : content.writeUnsignedByte(libsumo::TYPE_DOUBLE);
256 4 : content.writeDouble(relativePosition);
257 8 : return Dom::getDouble(libsumo::VAR_ANGLE, laneID, &content);
258 4 : }
259 :
260 : std::string
261 18 : Lane::getBidiLane(const std::string& laneID) {
262 18 : return Dom::getString(libsumo::VAR_BIDI, laneID);
263 : }
264 :
265 : void
266 8 : Lane::setAllowed(const std::string& laneID, std::string allowedClass) {
267 16 : setAllowed(laneID, std::vector<std::string>({allowedClass}));
268 8 : }
269 :
270 :
271 : void
272 11 : Lane::setAllowed(const std::string& laneID, std::vector<std::string> allowedClasses) {
273 11 : Dom::setStringVector(libsumo::LANE_ALLOWED, laneID, allowedClasses);
274 11 : }
275 :
276 :
277 : void
278 0 : Lane::setDisallowed(const std::string& laneID, std::string disallowedClasses) {
279 0 : setDisallowed(laneID, std::vector<std::string>({disallowedClasses}));
280 0 : }
281 :
282 :
283 : void
284 4 : Lane::setDisallowed(const std::string& laneID, std::vector<std::string> disallowedClasses) {
285 4 : Dom::setStringVector(libsumo::LANE_DISALLOWED, laneID, disallowedClasses);
286 4 : }
287 :
288 :
289 : void
290 4 : Lane::setChangePermissions(const std::string& laneID, std::vector<std::string> allowedClasses, const int direction) {
291 4 : tcpip::Storage content;
292 : StoHelp::writeCompound(content, 2);
293 : StoHelp::writeTypedStringList(content, allowedClasses);
294 : StoHelp::writeTypedByte(content, direction);
295 4 : Dom::set(libsumo::LANE_CHANGES, laneID, &content);
296 4 : }
297 :
298 :
299 : void
300 7 : Lane::setMaxSpeed(const std::string& laneID, double speed) {
301 7 : Dom::setDouble(libsumo::VAR_MAXSPEED, laneID, speed);
302 7 : }
303 :
304 :
305 : void
306 0 : Lane::setFriction(const std::string& laneID, double friction) {
307 0 : Dom::setDouble(libsumo::VAR_FRICTION, laneID, friction);
308 0 : }
309 :
310 :
311 : void
312 3 : Lane::setLength(const std::string& laneID, double length) {
313 3 : Dom::setDouble(libsumo::VAR_LENGTH, laneID, length);
314 3 : }
315 :
316 :
317 8319 : LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(Lane, LANE)
318 41 : LIBTRACI_PARAMETER_IMPLEMENTATION(Lane, LANE)
319 :
320 : }
321 :
322 :
323 : /****************************************************************************/
|