traci._vehicle
1# -*- coding: utf-8 -*- 2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3# Copyright (C) 2011-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 _vehicle.py 15# @author Michael Behrisch 16# @author Lena Kalleske 17# @author Mario Krumnow 18# @author Lena Kalleske 19# @author Jakob Erdmann 20# @author Laura Bieker 21# @author Daniel Krajzewicz 22# @author Leonhard Luecken 23# @author Mirko Barthauer 24# @date 2011-03-09 25 26from __future__ import absolute_import 27import warnings 28from ._vehicletype import VTypeDomain 29from . import constants as tc 30from .exceptions import TraCIException, deprecated, alias_param 31from ._lane import _readLinks 32 33 34_legacyGetLeader = True 35 36 37class StopData(object): 38 39 def __init__(self, 40 lane="", 41 startPos=-1, 42 endPos=-1, 43 stoppingPlaceID="", 44 stopFlags=0, 45 duration=-1, 46 until=-1, 47 intendedArrival=-1, 48 arrival=-1, 49 depart=-1, 50 split="", 51 join="", 52 actType="", 53 tripId="", 54 line="", 55 speed=0): 56 self.lane = lane 57 self.startPos = startPos 58 self.endPos = endPos 59 self.stoppingPlaceID = stoppingPlaceID 60 self.stopFlags = stopFlags 61 self.duration = duration 62 self.until = until 63 self.intendedArrival = intendedArrival 64 self.arrival = arrival 65 self.depart = depart 66 self.split = split 67 self.join = join 68 self.actType = actType 69 self.tripId = tripId 70 self.line = line 71 self.speed = speed 72 73 def __attr_repr__(self, attrname, default=""): 74 if getattr(self, attrname) == default: 75 return "" 76 else: 77 val = getattr(self, attrname) 78 if val == tc.INVALID_DOUBLE_VALUE: 79 val = "INVALID" 80 return "%s=%s" % (attrname, val) 81 82 def __repr__(self): 83 return "StopData(%s)" % ', '.join([v for v in [ 84 self.__attr_repr__("lane"), 85 self.__attr_repr__("startPos"), 86 self.__attr_repr__("endPos"), 87 self.__attr_repr__("stoppingPlaceID"), 88 self.__attr_repr__("stopFlags"), 89 self.__attr_repr__("duration", tc.INVALID_DOUBLE_VALUE), 90 self.__attr_repr__("until", tc.INVALID_DOUBLE_VALUE), 91 self.__attr_repr__("intendedArrival", tc.INVALID_DOUBLE_VALUE), 92 self.__attr_repr__("arrival", tc.INVALID_DOUBLE_VALUE), 93 self.__attr_repr__("depart", tc.INVALID_DOUBLE_VALUE), 94 self.__attr_repr__("split"), 95 self.__attr_repr__("join"), 96 self.__attr_repr__("actType"), 97 self.__attr_repr__("tripId"), 98 self.__attr_repr__("line"), 99 self.__attr_repr__("speed", 0), 100 ] if v != ""]) 101 102 103def _readStopData(result): 104 result.read("!iB") # numCompounds, TYPE_INT 105 numStops = result.read("!i")[0] 106 nextStops = [] 107 for _ in range(numStops): 108 lane = result.readTypedString() 109 endPos = result.readTypedDouble() 110 stoppingPlaceID = result.readTypedString() 111 stopFlags = result.readTypedInt() 112 duration = result.readTypedDouble() 113 until = result.readTypedDouble() 114 startPos = result.readTypedDouble() 115 intendedArrival = result.readTypedDouble() 116 arrival = result.readTypedDouble() 117 depart = result.readTypedDouble() 118 split = result.readTypedString() 119 join = result.readTypedString() 120 actType = result.readTypedString() 121 tripId = result.readTypedString() 122 line = result.readTypedString() 123 speed = result.readTypedDouble() 124 nextStops.append(StopData(lane, startPos, endPos, stoppingPlaceID, 125 stopFlags, duration, until, intendedArrival, arrival, depart, split, join, 126 actType, tripId, line, speed)) 127 return tuple(nextStops) 128 129 130def _readBestLanes(result): 131 result.read("!iB") 132 nbLanes = result.read("!i")[0] # Length 133 lanes = [] 134 for _ in range(nbLanes): 135 laneID = result.readTypedString() 136 length, occupation, offset = result.read("!BdBdBb")[1::2] 137 allowsContinuation = bool(result.read("!BB")[1]) 138 numNextLanes = result.read("!Bi")[1] 139 nextLanes = [result.readString() for __ in range(numNextLanes)] 140 lanes.append((laneID, length, occupation, offset, allowsContinuation, tuple(nextLanes))) 141 return tuple(lanes) 142 143 144def _readLeader(result): 145 assert result.read("!i")[0] == 2 # compound size 146 vehicleID = result.readTypedString() 147 dist = result.readTypedDouble() 148 if vehicleID == "" and _legacyGetLeader: 149 return None 150 return vehicleID, dist 151 152 153def _readFollower(result): 154 # note: merge this with _readLeader once the default of _legacyGetLeader has 155 # been changed to False 156 assert result.read("!i")[0] == 2 # compound size 157 vehicleID = result.readTypedString() 158 dist = result.readTypedDouble() 159 return vehicleID, dist 160 161 162def _readNeighbors(result): 163 """ result has structure: 164 byte(TYPE_COMPOUND) | length(neighList) | Per list entry: string(vehID) | double(dist) 165 """ 166 num = result.readInt() # length of the vehicle list 167 neighs = [] 168 for _ in range(num): 169 vehID = result.readString() 170 dist = result.readDouble() 171 neighs.append((vehID, dist)) 172 return tuple(neighs) 173 174 175def _readNextTLS(result): 176 result.read("!iB") # numCompounds, TYPE_INT 177 numTLS = result.read("!i")[0] 178 nextTLS = [] 179 for _ in range(numTLS): 180 result.read("!B") 181 tlsID = result.readString() 182 tlsIndex, dist, state = result.read("!BiBdBB")[1::2] 183 nextTLS.append((tlsID, tlsIndex, dist, chr(state))) 184 return tuple(nextTLS) 185 186 187def _readNextStops(result): 188 result.read("!iB") # numCompounds, TYPE_INT 189 numStops = result.read("!i")[0] 190 nextStop = [] 191 for _ in range(numStops): 192 result.read("!B") 193 lane = result.readString() 194 result.read("!B") 195 endPos = result.readDouble() 196 result.read("!B") 197 stoppingPlaceID = result.readString() 198 result.read("!B") 199 stopFlags = result.readInt() 200 result.read("!B") 201 duration = result.readDouble() 202 result.read("!B") 203 until = result.readDouble() 204 nextStop.append((lane, endPos, stoppingPlaceID, stopFlags, duration, until)) 205 return tuple(nextStop) 206 207 208def _readJunctionFoes(result): 209 result.read("!Bi") 210 nbJunctionFoes = result.readInt() 211 junctionFoes = [] 212 for _ in range(nbJunctionFoes): 213 result.read("!B") 214 foeId = result.readString() 215 result.read("!B") 216 egoDist = result.readDouble() 217 result.read("!B") 218 foeDist = result.readDouble() 219 result.read("!B") 220 egoExitDist = result.readDouble() 221 result.read("!B") 222 foeExitDist = result.readDouble() 223 result.read("!B") 224 egoLane = result.readString() 225 result.read("!B") 226 foeLane = result.readString() 227 result.read("!B") 228 egoResponse = bool(result.read("!B")[0]) 229 result.read("!B") 230 foeResponse = bool(result.read("!B")[0]) 231 junctionFoes.append((foeId, egoDist, foeDist, egoExitDist, foeExitDist, 232 egoLane, foeLane, egoResponse, foeResponse)) 233 return tuple(junctionFoes) 234 235 236_RETURN_VALUE_FUNC = {tc.VAR_ROUTE_VALID: lambda result: bool(result.read("!i")[0]), 237 tc.VAR_BEST_LANES: _readBestLanes, 238 tc.VAR_LEADER: _readLeader, 239 tc.VAR_FOLLOWER: _readFollower, 240 tc.VAR_NEIGHBORS: _readNeighbors, 241 tc.VAR_NEXT_TLS: _readNextTLS, 242 tc.VAR_NEXT_STOPS: _readNextStops, 243 tc.VAR_NEXT_LINKS: _readLinks, 244 tc.VAR_NEXT_STOPS2: _readStopData, 245 tc.VAR_FOES: _readJunctionFoes, 246 # ignore num compounds and type int 247 tc.CMD_CHANGELANE: lambda result: result.read("!iBiBi")[2::2]} 248 249 250class VehicleDomain(VTypeDomain): 251 # imported for backwards compatibility 252 STOP_DEFAULT = tc.STOP_DEFAULT 253 STOP_PARKING = tc.STOP_PARKING 254 STOP_TRIGGERED = tc.STOP_TRIGGERED 255 STOP_CONTAINER_TRIGGERED = tc.STOP_CONTAINER_TRIGGERED 256 STOP_BUS_STOP = tc.STOP_BUS_STOP 257 STOP_CONTAINER_STOP = tc.STOP_CONTAINER_STOP 258 STOP_CHARGING_STATION = tc.STOP_CHARGING_STATION 259 STOP_PARKING_AREA = tc.STOP_PARKING_AREA 260 DEPART_TRIGGERED = tc.DEPARTFLAG_TRIGGERED 261 DEPART_CONTAINER_TRIGGERED = tc.DEPARTFLAG_CONTAINER_TRIGGERED 262 DEPART_NOW = tc.DEPARTFLAG_NOW 263 DEPART_SPEED_RANDOM = tc.DEPARTFLAG_SPEED_RANDOM 264 DEPART_SPEED_MAX = tc.DEPARTFLAG_SPEED_MAX 265 DEPART_LANE_RANDOM = tc.DEPARTFLAG_LANE_RANDOM 266 DEPART_LANE_FREE = tc.DEPARTFLAG_LANE_FREE 267 DEPART_LANE_ALLOWED_FREE = tc.DEPARTFLAG_LANE_ALLOWED_FREE 268 DEPART_LANE_BEST_FREE = tc.DEPARTFLAG_LANE_BEST_FREE 269 DEPART_LANE_FIRST_ALLOWED = tc.DEPARTFLAG_LANE_FIRST_ALLOWED 270 271 def __init__(self): 272 VTypeDomain.__init__(self, "vehicle", tc.CMD_GET_VEHICLE_VARIABLE, tc.CMD_SET_VEHICLE_VARIABLE, 273 tc.CMD_SUBSCRIBE_VEHICLE_VARIABLE, tc.RESPONSE_SUBSCRIBE_VEHICLE_VARIABLE, 274 tc.CMD_SUBSCRIBE_VEHICLE_CONTEXT, tc.RESPONSE_SUBSCRIBE_VEHICLE_CONTEXT, 275 _RETURN_VALUE_FUNC, subscriptionDefault=(tc.VAR_ROAD_ID, tc.VAR_LANEPOSITION)) 276 277 def getSpeed(self, vehID): 278 """getSpeed(string) -> double 279 280 Returns the (longitudinal) speed in m/s of the named vehicle within the last step. 281 """ 282 return self._getUniversal(tc.VAR_SPEED, vehID) 283 284 def getLateralSpeed(self, vehID): 285 """getLateralSpeed(string) -> double 286 287 Returns the lateral speed in m/s of the named vehicle within the last step. 288 """ 289 return self._getUniversal(tc.VAR_SPEED_LAT, vehID) 290 291 def getAcceleration(self, vehID): 292 """getAcceleration(string) -> double 293 294 Returns the acceleration in m/s^2 of the named vehicle within the last step. 295 """ 296 return self._getUniversal(tc.VAR_ACCELERATION, vehID) 297 298 def getSpeedWithoutTraCI(self, vehID): 299 """getSpeedWithoutTraCI(string) -> double 300 Returns the speed that the vehicle would drive if no speed-influencing 301 command such as setSpeed or slowDown was given. 302 """ 303 return self._getUniversal(tc.VAR_SPEED_WITHOUT_TRACI, vehID) 304 305 def getPosition(self, vehID): 306 """getPosition(string) -> (double, double) 307 308 Returns the position of the named vehicle within the last step [m,m]. 309 """ 310 return self._getUniversal(tc.VAR_POSITION, vehID) 311 312 def getPosition3D(self, vehID): 313 """getPosition3D(string) -> (double, double, double) 314 315 Returns the position of the named vehicle within the last step [m,m,m]. 316 """ 317 return self._getUniversal(tc.VAR_POSITION3D, vehID) 318 319 def getAngle(self, vehID): 320 """getAngle(string) -> double 321 322 Returns the angle in degrees of the named vehicle within the last step. 323 """ 324 return self._getUniversal(tc.VAR_ANGLE, vehID) 325 326 def getRoadID(self, vehID): 327 """getRoadID(string) -> string 328 329 Returns the id of the edge the named vehicle was at within the last step. 330 """ 331 return self._getUniversal(tc.VAR_ROAD_ID, vehID) 332 333 def getDeparture(self, vehID): 334 """getDeparture(string) -> double 335 336 Returns the actual departure time in seconds 337 """ 338 return self._getUniversal(tc.VAR_DEPARTURE, vehID) 339 340 def getDepartDelay(self, vehID): 341 """getDepartDelay(string) -> double 342 343 Returns the delay between intended and actual departure in seconds 344 """ 345 return self._getUniversal(tc.VAR_DEPART_DELAY, vehID) 346 347 def getLaneID(self, vehID): 348 """getLaneID(string) -> string 349 350 Returns the id of the lane the named vehicle was at within the last step. 351 """ 352 return self._getUniversal(tc.VAR_LANE_ID, vehID) 353 354 def getShadowLaneID(self, vehID): 355 """getShadowLaneID(string) -> string 356 357 Returns the id of the shadow lane if the vehicle is currently changing lanes. 358 """ 359 return self._getUniversal(tc.VAR_SHADOW_LANE_ID, vehID) 360 361 def getLaneIndex(self, vehID): 362 """getLaneIndex(string) -> integer 363 364 Returns the index of the lane the named vehicle was at within the last step. 365 """ 366 return self._getUniversal(tc.VAR_LANE_INDEX, vehID) 367 368 def getSegmentID(self, vehID): 369 """getSegmentID(string) -> string 370 371 Returns the id of the segment the named vehicle was at within the last step (mesosim). 372 """ 373 return self._getUniversal(tc.VAR_SEGMENT_ID, vehID) 374 375 def getSegmentIndex(self, vehID): 376 """getSegmentIndex(string) -> integer 377 378 Returns the index of the segment the named vehicle was at within the last step (mesosim). 379 """ 380 return self._getUniversal(tc.VAR_SEGMENT_INDEX, vehID) 381 382 def getTypeID(self, vehID): 383 """getTypeID(string) -> string 384 385 Returns the id of the type of the named vehicle. 386 """ 387 return self._getUniversal(tc.VAR_TYPE, vehID) 388 389 def getRouteID(self, vehID): 390 """getRouteID(string) -> string 391 392 Returns the id of the route of the named vehicle. 393 """ 394 return self._getUniversal(tc.VAR_ROUTE_ID, vehID) 395 396 def getRouteIndex(self, vehID): 397 """getRouteIndex(string) -> int 398 399 Returns the index of the current edge within the vehicles route or -1 if the 400 vehicle has not yet departed 401 """ 402 return self._getUniversal(tc.VAR_ROUTE_INDEX, vehID) 403 404 def getRoute(self, vehID): 405 """getRoute(string) -> tuple(string) 406 407 Returns the ids of the edges the vehicle's route is made of. 408 """ 409 return self._getUniversal(tc.VAR_EDGES, vehID) 410 411 def getLanePosition(self, vehID): 412 """getLanePosition(string) -> double 413 414 The position of the vehicle along the lane measured in m. 415 """ 416 return self._getUniversal(tc.VAR_LANEPOSITION, vehID) 417 418 def getArrivalPos(self, vehID): 419 """getArrivalPos(string) -> double 420 421 The position at which the vehicle will arrive on the last edge of its route in m. 422 """ 423 return self._getUniversal(tc.VAR_ARRIVALPOS, vehID) 424 425 def getCO2Emission(self, vehID): 426 """getCO2Emission(string) -> double 427 428 Returns the CO2 emission in mg/s for the last time step. 429 Multiply by the step length to get the value for one step. 430 """ 431 return self._getUniversal(tc.VAR_CO2EMISSION, vehID) 432 433 def getCOEmission(self, vehID): 434 """getCOEmission(string) -> double 435 436 Returns the CO emission in mg/s for the last time step. 437 Multiply by the step length to get the value for one step. 438 """ 439 return self._getUniversal(tc.VAR_COEMISSION, vehID) 440 441 def getHCEmission(self, vehID): 442 """getHCEmission(string) -> double 443 444 Returns the HC emission in mg/s for the last time step. 445 Multiply by the step length to get the value for one step. 446 """ 447 return self._getUniversal(tc.VAR_HCEMISSION, vehID) 448 449 def getPMxEmission(self, vehID): 450 """getPMxEmission(string) -> double 451 452 Returns the particular matter emission in mg/s for the last time step. 453 Multiply by the step length to get the value for one step. 454 """ 455 return self._getUniversal(tc.VAR_PMXEMISSION, vehID) 456 457 def getNOxEmission(self, vehID): 458 """getNOxEmission(string) -> double 459 460 Returns the NOx emission in mg/s for the last time step. 461 Multiply by the step length to get the value for one step. 462 """ 463 return self._getUniversal(tc.VAR_NOXEMISSION, vehID) 464 465 def getFuelConsumption(self, vehID): 466 """getFuelConsumption(string) -> double 467 468 Returns the fuel consumption in mg/s for the last time step. 469 Multiply by the step length to get the value for one step. 470 """ 471 return self._getUniversal(tc.VAR_FUELCONSUMPTION, vehID) 472 473 def getNoiseEmission(self, vehID): 474 """getNoiseEmission(string) -> double 475 476 Returns the noise emission in db for the last time step. 477 """ 478 return self._getUniversal(tc.VAR_NOISEEMISSION, vehID) 479 480 def getElectricityConsumption(self, vehID): 481 """getElectricityConsumption(string) -> double 482 483 Returns the electricity consumption in Wh/s for the last time step. 484 Multiply by the step length to get the value for one step. 485 """ 486 return self._getUniversal(tc.VAR_ELECTRICITYCONSUMPTION, vehID) 487 488 def getPersonNumber(self, vehID): 489 """getPersonNumber(string) -> integer 490 Returns the total number of persons which includes those defined 491 using attribute 'personNumber' as well as <person>-objects who are riding in 492 this vehicle. 493 """ 494 return self._getUniversal(tc.VAR_PERSON_NUMBER, vehID) 495 496 def getPersonIDList(self, vehID): 497 """getPersonIDList(string) -> tuple(string) 498 Returns the tuple of persons who are riding in this vehicle. 499 """ 500 return self._getUniversal(tc.LAST_STEP_PERSON_ID_LIST, vehID) 501 502 def getAdaptedTraveltime(self, vehID, time, edgeID): 503 """getAdaptedTraveltime(string, double, string) -> double 504 505 Returns the information about the travel time of edge "edgeID" valid 506 for the given time from the vehicle's internal edge weights 507 container (see setAdaptedTraveltime). 508 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 509 """ 510 return self._getUniversal(tc.VAR_EDGE_TRAVELTIME, vehID, "tds", 2, time, edgeID) 511 512 def getEffort(self, vehID, time, edgeID): 513 """getEffort(string, double, string) -> double 514 515 Returns the information about the effort needed for edge "edgeID" valid 516 for the given time from the vehicle's internal effort 517 container (see setEffort). 518 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 519 """ 520 return self._getUniversal(tc.VAR_EDGE_EFFORT, vehID, "tds", 2, time, edgeID) 521 522 def isRouteValid(self, vehID): 523 """isRouteValid(string) -> bool 524 Returns whether the current vehicle route is connected for the vehicle 525 class of the given vehicle. 526 """ 527 return self._getUniversal(tc.VAR_ROUTE_VALID, vehID) 528 529 def getSignals(self, vehID): 530 """getSignals(string) -> integer 531 532 Returns an integer encoding the state of a vehicle's signals. 533 """ 534 return self._getUniversal(tc.VAR_SIGNALS, vehID) 535 536 def getLateralLanePosition(self, vehID): 537 """getLateralLanePosition(string) -> double 538 539 Returns the lateral position of the vehicle on its current lane measured in m. 540 """ 541 return self._getUniversal(tc.VAR_LANEPOSITION_LAT, vehID) 542 543 def getAllowedSpeed(self, vehID): 544 """getAllowedSpeed(string) -> double 545 546 Returns the maximum allowed speed on the current lane regarding speed factor in m/s for this vehicle. 547 """ 548 return self._getUniversal(tc.VAR_ALLOWED_SPEED, vehID) 549 550 def getWaitingTime(self, vehID): 551 """getWaitingTime(string) -> double 552 The waiting time of a vehicle is defined as the time (in seconds) spent with a 553 speed below 0.1m/s since the last time it was faster than 0.1m/s. 554 (basically, the waiting time of a vehicle is reset to 0 every time it moves). 555 A vehicle that is stopping intentionally with a <stop> does not accumulate waiting time. 556 """ 557 return self._getUniversal(tc.VAR_WAITING_TIME, vehID) 558 559 def getAccumulatedWaitingTime(self, vehID): 560 """getAccumulatedWaitingTime(string) -> double 561 The accumulated waiting time of a vehicle collects the vehicle's waiting time 562 over a certain time interval (interval length is set per option '--waiting-time-memory') 563 """ 564 return self._getUniversal(tc.VAR_ACCUMULATED_WAITING_TIME, vehID) 565 566 def getLaneChangeMode(self, vehID): 567 """getLaneChangeMode(string) -> integer 568 569 Gets the vehicle's lane change mode as a bitset. 570 """ 571 return self._getUniversal(tc.VAR_LANECHANGE_MODE, vehID) 572 573 def getSpeedMode(self, vehID): 574 """getSpeedMode(string) -> int 575 The speed mode of a vehicle 576 """ 577 return self._getUniversal(tc.VAR_SPEEDSETMODE, vehID) 578 579 def getSlope(self, vehID): 580 """getSlope(string) -> double 581 The slope at the current position of the vehicle in degrees 582 """ 583 return self._getUniversal(tc.VAR_SLOPE, vehID) 584 585 def getLine(self, vehID): 586 """getLine(string) -> string 587 588 Returns the line information of this vehicle. 589 """ 590 return self._getUniversal(tc.VAR_LINE, vehID) 591 592 def getVia(self, vehID): 593 """getVia(string) -> tuple(string) 594 595 Returns the ids of via edges for this vehicle 596 """ 597 return self._getUniversal(tc.VAR_VIA, vehID) 598 599 def getLastActionTime(self, vehID): 600 """getLastActionTime(string) -> double 601 602 Returns the time in s of last action point for this vehicle. 603 """ 604 return self._getUniversal(tc.VAR_LASTACTIONTIME, vehID) 605 606 def getBestLanes(self, vehID): 607 """getBestLanes(string) -> tuple(data) 608 where data is a tuple of (laneID, length, occupation, offset, allowsContinuation, tuple(nextLanes)) 609 610 For each lane of the current edge a data tuple is returned where the 611 entries have the following meaning: 612 - laneID: the id of that lane on the current edge 613 - the length that can be driven without lane change (measured from the start of that lane) 614 - the occupation on the future lanes (brutto vehicle lengths) 615 - the offset of that lane from the lane that would be strategically 616 preferred (this is the lane that requires the least future lane 617 changes or a lane that needs to be used for stopping) 618 - whether that lane allows continuing the route (for at least one more edge) 619 - the sequence of lanes that would be driven starting at laneID if no 620 lane change were to take place 621 """ 622 return self._getUniversal(tc.VAR_BEST_LANES, vehID) 623 624 def getLeader(self, vehID, dist=100.): 625 """getLeader(string, double) -> (string, double) 626 627 Return the leading vehicle id together with the distance. The distance 628 is measured from the front + minGap to the back of the leader, so it does not include the 629 minGap of the vehicle. 630 The dist parameter defines the minimum lookahead, 0 calculates a lookahead from the brake gap. 631 Note that the returned leader may be further away than the given dist and that the vehicle 632 will only look on its current best lanes and not look beyond the end of its final route edge. 633 634 In the case where no leader is found, the function returns 'None'. 635 This special case is deprecated. The future behavior is to return the 636 pair ("", -1) when no leader is found. 637 The function 'traci.setLegacyGetLeader(bool) can be used to switch 638 between both behaviors. 639 """ 640 return self._getUniversal(tc.VAR_LEADER, vehID, "d", dist) 641 642 def getFollower(self, vehID, dist=0.): 643 """getFollower(string, double) -> (string, double) 644 645 Return the following vehicle id together with the distance. The distance 646 is measured from the front + minGap of the follower to the back of vehID, so it does not include the 647 minGap of the follower. 648 The dist parameter defines the minimum lookback, 0 calculates the 649 lookback distance from the braking distance at 4.5m/s^2 at 2*roadSpeedLimit. 650 Due to junctions and lane merges, there may be multiple followers. 651 In this case, the "critical" follower is returned. This is the follower 652 where the value of (getSecureGap - gap) is maximal. 653 Note that the returned follower may be further away than the given dist. 654 """ 655 return self._getUniversal(tc.VAR_FOLLOWER, vehID, "d", dist) 656 657 def getRightFollowers(self, vehID, blockingOnly=False): 658 """ getRightFollowers(string, bool) -> tuple(tuple(string, double)) 659 Convenience method, see getNeighbors() 660 """ 661 if blockingOnly: 662 mode = 5 663 else: 664 mode = 1 665 return self.getNeighbors(vehID, mode) 666 667 def getRightLeaders(self, vehID, blockingOnly=False): 668 """ getRightLeaders(string, bool) -> tuple(tuple(string, double)) 669 Convenience method, see getNeighbors() 670 """ 671 if blockingOnly: 672 mode = 7 673 else: 674 mode = 3 675 return self.getNeighbors(vehID, mode) 676 677 def getLeftFollowers(self, vehID, blockingOnly=False): 678 """ getLeftFollowers(string, bool) -> tuple(tuple(string, double)) 679 Convenience method, see getNeighbors() 680 """ 681 if blockingOnly: 682 mode = 4 683 else: 684 mode = 0 685 return self.getNeighbors(vehID, mode) 686 687 def getLeftLeaders(self, vehID, blockingOnly=False): 688 """ getLeftLeaders(string, bool) -> tuple(tuple(string, double)) 689 Convenience method, see getNeighbors() 690 """ 691 if blockingOnly: 692 mode = 6 693 else: 694 mode = 2 695 return self.getNeighbors(vehID, mode) 696 697 def getNeighbors(self, vehID, mode): 698 """ getNeighbors(string, byte) -> tuple(tuple(string, double)) 699 700 The parameter mode is a bitset (UBYTE), specifying the following: 701 bit 1: query lateral direction (left:0, right:1) 702 bit 2: query longitudinal direction (followers:0, leaders:1) 703 bit 3: blocking (return all:0, return only blockers:1) 704 705 The returned tuple contains pairs (ID, dist) for all lane change relevant neighboring leaders, resp. followers, 706 along with their longitudinal distance to the ego vehicle (egoFront - egoMinGap to leaderBack, resp. 707 followerFront - followerMinGap to egoBack. The value can be negative for overlapping neighs). 708 For the non-sublane case, the lists will contain at most one entry. 709 710 Note: The exact set of blockers in case blocking==1 is not determined for the sublane model, 711 but either all neighboring vehicles are returned (in case LCA_BLOCKED) or 712 none is returned (in case !LCA_BLOCKED). 713 """ 714 return self._getUniversal(tc.VAR_NEIGHBORS, vehID, "B", mode) 715 716 def getFollowSpeed(self, vehID, speed, gap, leaderSpeed, leaderMaxDecel, leaderID=""): 717 """getFollowSpeed(string, double, double, double, double, string) -> double 718 Return the follow speed computed by the carFollowModel of vehID 719 """ 720 return self._getUniversal(tc.VAR_FOLLOW_SPEED, vehID, "tdddds", 5, 721 speed, gap, leaderSpeed, leaderMaxDecel, leaderID) 722 723 def getSecureGap(self, vehID, speed, leaderSpeed, leaderMaxDecel, leaderID=""): 724 """getSecureGap(string, double, double, double, string) -> double 725 Return the secure gap computed by the carFollowModel of vehID 726 """ 727 return self._getUniversal(tc.VAR_SECURE_GAP, vehID, "tddds", 4, 728 speed, leaderSpeed, leaderMaxDecel, leaderID) 729 730 def getStopSpeed(self, vehID, speed, gap): 731 """getStopSpeed(string, double, double) -> double 732 Return the speed for stopping at gap computed by the carFollowModel of vehID 733 """ 734 return self._getUniversal(tc.VAR_STOP_SPEED, vehID, "tdd", 2, speed, gap) 735 736 def getStopDelay(self, vehID): 737 """getStopDelay(string) -> double 738 Returns the expected depart delay at the next stop (if that stop defines the 739 until-attribute) in seconds. Returns -1 if the next stop is not applicable 740 """ 741 return self._getUniversal(tc.VAR_STOP_DELAY, vehID) 742 743 def getStopArrivalDelay(self, vehID): 744 """getStopArrivalDelay(string) -> double 745 Returns the expected arrival delay at the next stop (if that stop defines the 746 arrival-attribute) in seconds. The returned value may be negative to 747 indicate early arrival. Returns INVALID_DOUBLE if the next stop is not applicable 748 """ 749 return self._getUniversal(tc.VAR_STOP_ARRIVALDELAY, vehID) 750 751 def getTimeLoss(self, vehID): 752 """getTimeLoss(string) -> double 753 Returns the time loss since departure 754 """ 755 return self._getUniversal(tc.VAR_TIMELOSS, vehID) 756 757 def getNextTLS(self, vehID): 758 """getNextTLS(string) -> tuple(tuple(string, int, double, string)) 759 760 Return tuple of upcoming traffic lights [(tlsID, tlsIndex, distance, state), ...] 761 """ 762 return self._getUniversal(tc.VAR_NEXT_TLS, vehID) 763 764 @alias_param("dist", "distance") 765 def getJunctionFoes(self, vehID, dist=0.): 766 """getJunctionFoes(string, double) -> complex 767 768 Return tuple of junction foes [(foeId, egoDist, foeDist, egoExitDist, foeExitDist, 769 egoLane, foeLane, egoResponse, foeResponse), ...] within the given distance to the given vehicle. 770 """ 771 return self._getUniversal(tc.VAR_FOES, vehID, "d", dist) 772 773 @deprecated() 774 def getNextStops(self, vehID): 775 """getNextStops(string) -> tuple(tuple(string, double, string, int, double, double)) 776 777 Return tuple of upcoming stops ((lane, endPos, stoppingPlaceID, stopFlags, duration, until), ...) 778 where integer stopFlag is defined as: 779 1 * stopped + 780 2 * parking + 781 4 * personTriggered + 782 8 * containerTriggered + 783 16 * isBusStop + 784 32 * isContainerStop + 785 64 * chargingStation + 786 128 * parkingarea 787 with each of these flags defined as 0 or 1. 788 """ 789 return self._getUniversal(tc.VAR_NEXT_STOPS, vehID) 790 791 def getNextLinks(self, vehID): 792 """getNextLinks(string) -> tuple(tuple(string, string, bool, bool, bool, string, string, double)) 793 794 Return tuple of upcoming links along the route ((lane, via, priority, opened, foe, 795 state, direction, length), ...) 796 """ 797 return self._getUniversal(tc.VAR_NEXT_LINKS, vehID) 798 799 def getStops(self, vehID, limit=0): 800 """getStops(string, int) -> tuple(StopData) 801 802 Return a tuple of StopData object. The flags are the same as for setStop and 803 replaceStop (and different from getNextStops(!) for backward compatibility): 804 1 * parking + 805 2 * personTriggered + 806 4 * containerTriggered + 807 8 * isBusStop + 808 16 * isContainerStop + 809 32 * chargingStation + 810 64 * parkingarea 811 with each of these flags defined as 0 or 1. 812 813 The optional argument limit can be used to limit the returned stops to 814 the next INT number (i.e. limit=1 if only the next stop is required). 815 Setting a negative limit returns up to 'limit' previous stops (or fewer 816 if the vehicle stopped fewer times previously) 817 """ 818 return self._getUniversal(tc.VAR_NEXT_STOPS2, vehID, "i", limit) 819 820 def subscribeLeader(self, vehID, dist=0., begin=0, end=2**31 - 1): 821 """subscribeLeader(string, double, double, double) -> None 822 823 Subscribe for the leading vehicle id together with the distance. 824 The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap. 825 """ 826 self.subscribe(vehID, (tc.VAR_LEADER,), begin, end, {tc.VAR_LEADER: ("d", dist)}) 827 828 def getDrivingDistance(self, vehID, edgeID, pos, laneIndex=0): 829 """getDrivingDistance(string, string, double, integer) -> double 830 831 For an edge along the remaining route of vehID, return the distance from the current vehicle position 832 to the given edge and position along the vehicles route. 833 Otherwise, return INVALID_DOUBLE_VALUE 834 """ 835 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tru", 2, 836 (edgeID, pos, laneIndex), tc.REQUEST_DRIVINGDIST) 837 838 def getDrivingDistance2D(self, vehID, x, y): 839 """getDrivingDistance2D(string, double, double) -> integer 840 841 Return the distance to the given network position along the vehicles route. 842 """ 843 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tou", 2, (x, y), tc.REQUEST_DRIVINGDIST) 844 845 def getDistance(self, vehID): 846 """getDistance(string) -> double 847 848 Returns the distance to the starting point like an odometer. 849 """ 850 return self._getUniversal(tc.VAR_DISTANCE, vehID) 851 852 def getReferenceDistance(self, vehID): 853 """getReferenceDistance(string) -> double 854 Returns the distance along the linear reference system 855 in which the current edge takes part (i.e. kilometrage/mile markers) 856 """ 857 return self._getUniversal(tc.VAR_REFERENCE_DISTANCE, vehID) 858 859 def getStopParameter(self, vehID, nextStopIndex, param, customParam=False): 860 """getStopParameter(string, int, string) -> string 861 Gets the value of the given parameter for the stop at the given index 862 Negative indices permit access to past stops. 863 Supported params correspond to all legal stop xml-attributes 864 If customParam is set to True, the user defined stop parameter with the 865 specified param name will be returned instead (or "" if undefined) 866 """ 867 return self._getUniversal(tc.VAR_STOP_PARAMETER, vehID, "tisb", 3, nextStopIndex, param, customParam) 868 869 def getStopState(self, vehID): 870 """getStopState(string) -> integer 871 872 Returns information in regard to stopping: 873 The returned integer is defined as 1 * stopped + 2 * parking 874 + 4 * personTriggered + 8 * containerTriggered + 16 * isBusStop 875 + 32 * isContainerStop 876 with each of these flags defined as 0 or 1 877 """ 878 return self._getUniversal(tc.VAR_STOPSTATE, vehID) 879 880 def isStopped(self, vehID): 881 """isStopped(string) -> bool 882 Return whether the vehicle is stopped 883 """ 884 return (self.getStopState(vehID) & 1) == 1 885 886 def isStoppedParking(self, vehID): 887 """isStoppedParking(string) -> bool 888 Return whether the vehicle is parking (implies stopped) 889 """ 890 return (self.getStopState(vehID) & 2) == 2 891 892 def isStoppedTriggered(self, vehID): 893 """isStoppedTriggered(string) -> bool 894 Return whether the vehicle is stopped and waiting for a person or container 895 """ 896 return (self.getStopState(vehID) & 12) > 0 897 898 def isAtBusStop(self, vehID): 899 """isAtBusStop(string) -> bool 900 Return whether the vehicle is stopped at a bus stop 901 """ 902 return (self.getStopState(vehID) & 16) == 16 903 904 def isAtContainerStop(self, vehID): 905 """isAtContainerStop(string) -> bool 906 Return whether the vehicle is stopped at a container stop 907 """ 908 return (self.getStopState(vehID) & 32) == 32 909 910 def getLaneChangeState(self, vehID, direction): 911 """getLaneChangeState(string, int) -> (int, int) 912 Return the lane change state for the vehicle. The first value returns 913 the state as computed by the lane change model and the second value 914 returns the state after incorporation TraCI requests. 915 See getLaneChangeStatePretty for an interpretation of the integer/bitset 916 results 917 """ 918 return self._getUniversal(tc.CMD_CHANGELANE, vehID, "i", direction) 919 920 def getLaneChangeStatePretty(self, vehID, direction): 921 """getLaneChangeStatePretty(string, int) -> ([string, ...], [string, ...]) 922 Return the lane change state for the vehicle as two lists of string 923 constants. The first tuple returns the state as computed by the lane change 924 model and the second tuple returns the state after incorporation TraCI requests. 925 """ 926 constants = { 927 0: 'stay', 928 1: 'left', 929 2: 'right', 930 3: 'strategic', 931 4: 'cooperative', 932 5: 'speedGain', 933 6: 'keepRight', 934 7: 'TraCI', 935 8: 'urgent', 936 9: 'blocked by left leader', 937 10: 'blocked by left follower', 938 11: 'blocked by right leader', 939 12: 'blocked by right follower', 940 13: 'overlapping', 941 14: 'insufficient space', 942 15: 'sublane', 943 } 944 945 def prettifyBitstring(intval): 946 return tuple([v for k, v in constants.items() if (intval & 2**k)]) 947 948 state, stateTraCI = self.getLaneChangeState(vehID, direction) 949 return prettifyBitstring(state), prettifyBitstring(stateTraCI) 950 951 def couldChangeLane(self, vehID, direction, state=None): 952 """couldChangeLane(string, int) -> bool 953 Return whether the vehicle could change lanes in the specified direction. 954 This reflects the state after the last try to change lanes. 955 If you want to execute changeLane as a result of the evaluation of this function 956 it is not guaranteed to work because vehicle movements occur first. 957 """ 958 if state is None: 959 state, stateTraCI = self.getLaneChangeState(vehID, direction) 960 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 961 # vehicle changed in the last step. state is no longer applicable 962 return False 963 return state != tc.LCA_UNKNOWN and (state & tc.LCA_BLOCKED == 0) 964 965 def wantsAndCouldChangeLane(self, vehID, direction, state=None): 966 """wantsAndCouldChangeLane(string, int) -> bool 967 Return whether the vehicle wants to and could change lanes in the specified direction 968 This reflects the state after the last try to change lanes. 969 If you want to execute changeLane as a result of the evaluation of this function 970 it is not guaranteed to work because vehicle movements occur first. 971 """ 972 if state is None: 973 state, stateTraCI = self.getLaneChangeState(vehID, direction) 974 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 975 # vehicle changed in the last step. state is no longer applicable 976 return False 977 if state & tc.LCA_BLOCKED == 0: 978 if direction == -1: 979 return state & tc.LCA_RIGHT != 0 980 if direction == 1: 981 return state & tc.LCA_LEFT != 0 982 return False 983 984 def getRoutingMode(self, vehID): 985 """getRoutingMode(string) 986 returns the current routing mode: 987 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 988 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 989 """ 990 return self._getUniversal(tc.VAR_ROUTING_MODE, vehID) 991 992 @alias_param("taxiState", "flag") 993 def getTaxiFleet(self, taxiState=0): 994 """getTaxiFleet(int) -> tuple(string) 995 Return the tuple of all taxis with the given taxiState: 996 0 : empty 997 1 : pickup 998 2 : occupied 999 """ 1000 return self._getUniversal(tc.VAR_TAXI_FLEET, "", "i", taxiState) 1001 1002 def getLoadedIDList(self): 1003 """getLoadedIDList() -> tuple(string) 1004 returns all loaded vehicles that have not yet left the simulation 1005 """ 1006 return self._getUniversal(tc.VAR_LOADED_LIST, "") 1007 1008 def getTeleportingIDList(self): 1009 """getTeleportingIDList() -> tuple(string) 1010 returns all teleporting or jumping vehicles 1011 """ 1012 return self._getUniversal(tc.VAR_TELEPORTING_LIST, "") 1013 1014 def rerouteParkingArea(self, vehID, parkingAreaID): 1015 """rerouteParkingArea(string, string) 1016 1017 Changes the next parking area in parkingAreaID, updates the vehicle route, 1018 and preserve consistency in case of passengers/containers on board. 1019 """ 1020 self._setCmd(tc.CMD_REROUTE_TO_PARKING, vehID, "ts", 1, parkingAreaID) 1021 1022 def setStop(self, vehID, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1023 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, until=tc.INVALID_DOUBLE_VALUE): 1024 """setStop(string, string, double, integer, double, integer, double, double) -> None 1025 1026 Adds or modifies a stop with the given parameters. The duration and the until attribute are 1027 in seconds. 1028 """ 1029 if type(duration) is int and duration >= 1000 and duration % 1000 == 0: 1030 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1031 self._setCmd(tc.CMD_STOP, vehID, "tsdbdbdd", 7, edgeID, pos, laneIndex, duration, flags, startPos, until) 1032 1033 def setBusStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1034 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1035 """setBusStop(string, string, double, double, integer) -> None 1036 1037 Adds or modifies a bus stop with the given parameters. The duration and the until attribute are 1038 in seconds. 1039 """ 1040 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_BUS_STOP) 1041 1042 def setContainerStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1043 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1044 """setContainerStop(string, string, double, double, integer) -> None 1045 1046 Adds or modifies a container stop with the given parameters. The duration and the until attribute are 1047 in seconds. 1048 """ 1049 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CONTAINER_STOP) 1050 1051 def setChargingStationStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1052 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1053 """setChargingStationStop(string, string, double, double, integer) -> None 1054 1055 Adds or modifies a stop at a chargingStation with the given parameters. The duration and the until attribute are 1056 in seconds. 1057 """ 1058 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CHARGING_STATION) 1059 1060 def setParkingAreaStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1061 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_PARKING): 1062 """setParkingAreaStop(string, string, double, double, integer) -> None 1063 1064 Adds or modifies a stop at a parkingArea with the given parameters. The duration and the until attribute are 1065 in seconds. 1066 """ 1067 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_PARKING_AREA) 1068 1069 def replaceStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1070 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1071 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1072 """replaceStop(string, int, string, double, integer, double, integer, double, double) -> None 1073 1074 Replaces stop at the given index (within the list of all stops) with a new stop. 1075 Automatically modifies the route if the replacement stop is at another location. 1076 For edgeID a stopping place id may be given if the flag marks this 1077 stop as stopping on busStop, parkingArea, containerStop etc. 1078 If edgeID is "", the stop at the given index will be removed without 1079 replacement and the route will not be modified (unless setting 1080 teleport=2 which will trigger rerouting between the prior and next stop) 1081 If teleport is set to 1, the route to the replacement stop will be 1082 disconnected (forcing a teleport). 1083 If stopIndex is 0 the gap will be between the current 1084 edge and the new stop. Otherwise the gap will be between the stop edge for 1085 nextStopIndex - 1 and the new stop. 1086 """ 1087 self._setCmd(tc.CMD_REPLACE_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1088 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport) 1089 1090 def insertStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1091 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1092 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1093 """insertStop(string, int, string, double, integer, double, integer, double, double) -> None 1094 1095 Insert stop at the given index (within the list of all existing stops). 1096 Automatically modifies the route if the new stop is not along the route between the preceeding 1097 and succeeding stops (or start / end). 1098 For edgeID a stopping place id may be given if the flag marks this 1099 stop as stopping on busStop, parkingArea, containerStop etc. 1100 If teleport is set to 1, the route to the new stop will be 1101 disconnected (forcing a teleport). 1102 If stopIndex is 0 the gap will be between the current 1103 edge and the new stop. Otherwise the gap will be between the stop edge for 1104 nextStopIndex - 1 and the new stop. 1105 """ 1106 self._setCmd(tc.CMD_INSERT_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1107 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport) 1108 1109 def setStopParameter(self, vehID, nextStopIndex, param, value, customParam=False): 1110 """setStopParameter(string, int, string, string) -> None 1111 Sets the value of the given parameter for the (upcoming) stop at the 1112 given index (within the list of all stops). 1113 Supported params correspond to (almost) all legal stop xml-attributes 1114 and their value semantics 1115 If customParam is set to True, the user defined stop parameter with the 1116 specified param name will be set instead 1117 """ 1118 self._setCmd(tc.VAR_STOP_PARAMETER, vehID, "tissb", 4, nextStopIndex, param, value, customParam) 1119 1120 def resume(self, vehID): 1121 """resume(string) -> None 1122 1123 Resumes the vehicle from the current stop (throws an error if the vehicle is not stopped). 1124 """ 1125 self._setCmd(tc.CMD_RESUME, vehID, "t", 0) 1126 1127 def changeLane(self, vehID, laneIndex, duration): 1128 """changeLane(string, int, double) -> None 1129 Forces a lane change to the lane with the given index; The lane change 1130 will be attempted for the given duration (in s) and if it succeeds, 1131 the vehicle will stay on that lane for the remaining duration. 1132 """ 1133 if type(duration) is int and duration >= 1000: 1134 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1135 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbd", 2, laneIndex, duration) 1136 1137 def changeLaneRelative(self, vehID, indexOffset, duration): 1138 """changeLaneRelative(string, int, double) -> None 1139 1140 Forces a relative lane change; if successful, 1141 the lane will be chosen for the given amount of time (in s). 1142 The indexOffset specifies the target lane relative to the vehicles current lane 1143 """ 1144 if type(duration) is int and duration >= 1000: 1145 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1146 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbdb", 3, indexOffset, duration, 1) 1147 1148 def changeSublane(self, vehID, latDist): 1149 """changeSublane(string, double) -> None 1150 Forces a lateral change by the given amount (negative values indicate changing to the right, positive 1151 to the left). This will override any other lane change motivations but conform to 1152 safety-constraints as configured by laneChangeMode. 1153 """ 1154 self._setCmd(tc.CMD_CHANGESUBLANE, vehID, "d", latDist) 1155 1156 def slowDown(self, vehID, speed, duration): 1157 """slowDown(string, double, double) -> None 1158 1159 Changes the speed smoothly to the given value over the given amount 1160 of time in seconds (can also be used to increase speed). 1161 """ 1162 if type(duration) is int and duration >= 1000: 1163 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1164 self._setCmd(tc.CMD_SLOWDOWN, vehID, "tdd", 2, speed, duration) 1165 1166 def openGap(self, vehID, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel=-1, referenceVehID=None): 1167 """openGap(string, double, double, double, double, double, string) -> None 1168 1169 Changes the vehicle's desired time headway (cf-parameter tau) smoothly to the given new value 1170 using the given change rate. Similarly, the given space headway is applied gradually 1171 to achieve a minimal spatial gap. 1172 The vehicle is commanded to keep the increased headway for 1173 the given duration once its target value is attained. The maximal value for the 1174 deceleration can be given to prevent harsh braking due to the change of tau. If maxDecel=-1, 1175 the limit determined by the CF model is used. 1176 A vehicle ID for a reference vehicle can optionally be given, otherwise, the gap is created with 1177 respect to the current leader on the ego vehicle's current lane. 1178 Note that this does only affect the following behavior regarding the current leader and does 1179 not influence the gap acceptance during lane change, etc. 1180 """ 1181 if type(duration) is int and duration >= 1000: 1182 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1183 if referenceVehID is None: 1184 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddd", 5, 1185 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel) 1186 else: 1187 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddds", 6, 1188 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, referenceVehID) 1189 1190 def deactivateGapControl(self, vehID): 1191 """deactivateGapControl(string) -> None 1192 1193 Deactivate the vehicle's gap control 1194 """ 1195 self.openGap(vehID, -1, -1, -1, -1) 1196 1197 def requestToC(self, vehID, leadTime): 1198 """ requestToC(string, double) -> None 1199 1200 Interface for triggering a transition of control for a vehicle equipped with a ToC device. 1201 """ 1202 self.setParameter(vehID, "device.toc.requestToC", str(leadTime)) 1203 1204 def changeTarget(self, vehID, edgeID): 1205 """changeTarget(string, string) -> None 1206 1207 The vehicle's destination edge is set to the given edge id. The route is rebuilt. 1208 """ 1209 self._setCmd(tc.CMD_CHANGETARGET, vehID, "s", edgeID) 1210 1211 def setType(self, vehID, typeID): 1212 """setType(string, string) -> None 1213 1214 Sets the id of the type for the named vehicle. 1215 """ 1216 self._setCmd(tc.VAR_TYPE, vehID, "s", typeID) 1217 1218 def setRouteID(self, vehID, routeID): 1219 """setRouteID(string, string) -> None 1220 1221 Changes the vehicles route to the route with the given id. 1222 """ 1223 self._setCmd(tc.VAR_ROUTE_ID, vehID, "s", routeID) 1224 1225 def setRoute(self, vehID, edgeList): 1226 """ 1227 setRoute(string, list) -> None 1228 1229 changes the vehicle route to given edges list. 1230 The first edge in the list has to be the one that the vehicle is at the moment. 1231 1232 example usage: 1233 setRoute('1', ['1', '2', '4', '6', '7']) 1234 1235 this changes route for vehicle id 1 to edges 1-2-4-6-7 1236 """ 1237 if isinstance(edgeList, str): 1238 edgeList = [edgeList] 1239 self._setCmd(tc.VAR_ROUTE, vehID, "l", edgeList) 1240 1241 def setLateralLanePosition(self, vehID, posLat): 1242 """setLateralLanePosition(string, double) -> None 1243 1244 Sets the lateral vehicle position relative to the center line of the 1245 lane in m (negative values are to the right in right-hand networks). 1246 The vehicle may adapt this position in the same step unless this is 1247 disabled via setLaneChangeMode. 1248 """ 1249 self._setCmd(tc.VAR_LANEPOSITION_LAT, vehID, "d", posLat) 1250 1251 def updateBestLanes(self, vehID): 1252 """ updateBestLanes(string) -> None 1253 Triggers an update of the vehicle's bestLanes (structure determining the lane preferences used by LC models) 1254 It may be called after modifying the vClass for instance. 1255 """ 1256 self._setCmd(tc.VAR_UPDATE_BESTLANES, vehID) 1257 1258 def setAdaptedTraveltime(self, vehID, edgeID, time=None, begTime=None, endTime=None): 1259 """setAdaptedTraveltime(string, string, double, double, double) -> None 1260 Inserts the information about the travel time of edge "edgeID" valid 1261 from begin time to end time into the vehicle's internal edge weights 1262 container. 1263 If the time is not specified, any previously set values for that edge 1264 are removed. 1265 If begTime or endTime are not specified the value is set for the whole 1266 simulation duration. 1267 """ 1268 if not isinstance(edgeID, str) and isinstance(begTime, str): 1269 # legacy handling 1270 warnings.warn( 1271 "Parameter order has changed for setAdaptedTraveltime(). Attempting legacy ordering. " + 1272 "Please update your code.", stacklevel=2) 1273 return self.setAdaptedTraveltime(vehID, begTime, endTime, edgeID, time) 1274 if time is None: 1275 # reset 1276 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "ts", 1, edgeID) 1277 elif begTime is None: 1278 # set value for the whole simulation 1279 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tsd", 2, edgeID, time) 1280 else: 1281 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tddsd", 4, begTime, endTime, edgeID, time) 1282 1283 def setEffort(self, vehID, edgeID, effort=None, begTime=None, endTime=None): 1284 """setEffort(string, string, double, double, double) -> None 1285 Inserts the information about the effort of edge "edgeID" valid from 1286 begin time to end time into the vehicle's internal edge weights 1287 container. 1288 If the time is not specified, any previously set values for that edge 1289 are removed. 1290 If begTime or endTime are not specified the value is set for the whole 1291 simulation duration. 1292 """ 1293 if not isinstance(edgeID, str) and isinstance(begTime, str): 1294 # legacy handling 1295 warnings.warn( 1296 "Parameter order has changed for setEffort(). Attempting legacy ordering. Please update your code.", 1297 stacklevel=2) 1298 return self.setEffort(vehID, begTime, endTime, edgeID, effort) 1299 if effort is None: 1300 # reset 1301 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "ts", 1, edgeID) 1302 elif begTime is None: 1303 # set value for the whole simulation 1304 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tsd", 2, edgeID, effort) 1305 else: 1306 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tddsd", 4, begTime, endTime, edgeID, effort) 1307 1308 LAST_TRAVEL_TIME_UPDATE = -1 1309 1310 def setRoutingMode(self, vehID, routingMode): 1311 """setRoutingMode(string, int) -> None 1312 Sets the current routing mode: 1313 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 1314 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 1315 tc.ROUTING_MODE_AGGREGATED_CUSTOM : use weight storages and fall-back to smoothed travel times 1316 """ 1317 self._setCmd(tc.VAR_ROUTING_MODE, vehID, "i", routingMode) 1318 1319 def rerouteTraveltime(self, vehID, currentTravelTimes=True): 1320 """rerouteTraveltime(string, bool) -> None 1321 Reroutes a vehicle. 1322 If currentTravelTimes is True (default) and the routing mode is still ROUTING_MODE_DEFAULT 1323 then the ROUTING_MODE_AGGREGATED_CUSTOM gets activated temporarily 1324 and used for rerouting. The various functions and options for 1325 customizing travel times are described at https://sumo.dlr.de/wiki/Simulation/Routing 1326 1327 When rerouteTraveltime has been called once with an aggregated routing mode, 1328 edge weight storage and update gets activated which might slow down the simulation. 1329 """ 1330 if currentTravelTimes: 1331 routingMode = self.getRoutingMode(vehID) 1332 if routingMode == tc.ROUTING_MODE_DEFAULT: 1333 self.setRoutingMode(vehID, tc.ROUTING_MODE_AGGREGATED_CUSTOM) 1334 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, vehID, "t", 0) 1335 if currentTravelTimes and routingMode == tc.ROUTING_MODE_DEFAULT: 1336 self.setRoutingMode(vehID, routingMode) 1337 1338 def rerouteEffort(self, vehID): 1339 """rerouteEffort(string) -> None 1340 Reroutes a vehicle according to the effort values. 1341 """ 1342 self._setCmd(tc.CMD_REROUTE_EFFORT, vehID, "t", 0) 1343 1344 def setSignals(self, vehID, signals): 1345 """setSignals(string, integer) -> None 1346 1347 Sets an integer encoding the state of the vehicle's signals. 1348 """ 1349 self._setCmd(tc.VAR_SIGNALS, vehID, "i", signals) 1350 1351 def moveTo(self, vehID, laneID, pos, reason=tc.MOVE_AUTOMATIC): 1352 """moveTo(string, string, double, integer) -> None 1353 1354 Move a vehicle to a new position along its current route. 1355 """ 1356 self._setCmd(tc.VAR_MOVE_TO, vehID, "tsdi", 3, laneID, pos, reason) 1357 1358 def setSpeed(self, vehID, speed): 1359 """setSpeed(string, double) -> None 1360 1361 Sets the speed in m/s for the named vehicle within the last step. 1362 Calling with speed=-1 hands the vehicle control back to SUMO. 1363 """ 1364 self._setCmd(tc.VAR_SPEED, vehID, "d", speed) 1365 1366 def setAcceleration(self, vehID, acceleration, duration): 1367 """setAcceleration(string, double, double) -> None 1368 1369 Sets the acceleration in m/s^2 for the named vehicle and the given duration. 1370 """ 1371 self._setCmd(tc.VAR_ACCELERATION, vehID, "tdd", 2, acceleration, duration) 1372 1373 def setPreviousSpeed(self, vehID, speed, acceleration=tc.INVALID_DOUBLE_VALUE): 1374 """setPreviousSpeed(string, double, double) -> None 1375 1376 Sets the previous speed in m/s for the named vehicle wich will be used for 1377 calculations in the current step. Optionally, the acceleration for the 1378 previous step (in m/s^2) can be set as well. 1379 """ 1380 self._setCmd(tc.VAR_PREV_SPEED, vehID, "tdd", 2, speed, acceleration) 1381 1382 def setLine(self, vehID, line): 1383 """setLine(string, string) -> None 1384 1385 Sets the line information for this vehicle. 1386 """ 1387 self._setCmd(tc.VAR_LINE, vehID, "s", line) 1388 1389 def setVia(self, vehID, edgeList): 1390 """ 1391 setVia(string, list) -> None 1392 1393 changes the via edges to the given edges list (to be used during 1394 subsequent rerouting calls). 1395 1396 Note: a single edgeId as argument is allowed as shorthand for a list of length 1 1397 """ 1398 if isinstance(edgeList, str): 1399 edgeList = [edgeList] 1400 self._setCmd(tc.VAR_VIA, vehID, "l", edgeList) 1401 1402 def highlight(self, vehID, color=(255, 0, 0, 255), size=-1, alphaMax=-1, duration=-1, type=0): 1403 """ highlight(string, color, float, ubyte, float, ubyte) -> None 1404 Adds a circle of the given color tracking the vehicle. 1405 If a positive size [in m] is given the size of the highlight is chosen accordingly, 1406 otherwise the length of the vehicle is used as reference. 1407 If alphaMax and duration are positive, the circle fades in and out within the given duration, 1408 otherwise it permanently follows the vehicle. 1409 """ 1410 if type > 255: 1411 raise TraCIException("vehicle.highlight(): maximal value for type is 255") 1412 if alphaMax > 255: 1413 raise TraCIException("vehicle.highlight(): maximal value for alphaMax is 255") 1414 if alphaMax <= 0 and duration > 0: 1415 raise TraCIException("vehicle.highlight(): duration>0 requires alphaMax>0") 1416 if alphaMax > 0 and duration <= 0: 1417 raise TraCIException("vehicle.highlight(): alphaMax>0 requires duration>0") 1418 1419 if alphaMax > 0: 1420 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcdBdB", 5, color, size, alphaMax, duration, type) 1421 else: 1422 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcd", 2, color, size) 1423 1424 @alias_param("laneChangeMode", "lcm") 1425 def setLaneChangeMode(self, vehID, laneChangeMode): 1426 """setLaneChangeMode(string, integer) -> None 1427 1428 Sets the vehicle's lane change mode as a bitset. 1429 """ 1430 self._setCmd(tc.VAR_LANECHANGE_MODE, vehID, "i", laneChangeMode) 1431 1432 @alias_param("speedMode", "sm") 1433 def setSpeedMode(self, vehID, speedMode): 1434 """setSpeedMode(string, integer) -> None 1435 1436 Sets the vehicle's speed mode as a bitset. 1437 """ 1438 self._setCmd(tc.VAR_SPEEDSETMODE, vehID, "i", speedMode) 1439 1440 def addLegacy(self, vehID, routeID, depart=tc.DEPARTFLAG_NOW, pos=0, speed=0, 1441 lane=tc.DEPARTFLAG_LANE_FIRST_ALLOWED, typeID="DEFAULT_VEHTYPE"): 1442 """ 1443 Add a new vehicle (old style) 1444 """ 1445 if depart == tc.DEPARTFLAG_NOW: 1446 depart = "now" 1447 elif depart == tc.DEPARTFLAG_TRIGGERED: 1448 depart = "triggered" 1449 else: 1450 depart = str(depart) 1451 if pos < 0: 1452 print("Invalid departure position.") 1453 return 1454 if lane == tc.DEPARTFLAG_LANE_FIRST_ALLOWED: 1455 lane = "first" 1456 elif lane == tc.DEPARTFLAG_LANE_FREE: 1457 lane = "free" 1458 else: 1459 lane = str(lane) 1460 self.addFull(vehID, routeID, typeID, depart, lane, str(pos), str(speed)) 1461 1462 def add(self, vehID, routeID, typeID="DEFAULT_VEHTYPE", depart="now", 1463 departLane="first", departPos="base", departSpeed="0", 1464 arrivalLane="current", arrivalPos="max", arrivalSpeed="current", 1465 fromTaz="", toTaz="", line="", personCapacity=0, personNumber=0, 1466 departPosLat="", arrivalPosLat="", speedFactor=-1, insertionChecks=""): 1467 """ 1468 Add a new vehicle (new style with all possible parameters) 1469 If routeID is "", the vehicle will be inserted on a random network edge 1470 if route consists of two disconnected edges, the vehicle will be treated 1471 like a <trip> and use the fastest route between the two edges. 1472 """ 1473 if depart is None: 1474 # legacy compatibility 1475 depart = str(self._connection.simulation.getTime()) 1476 withOptional = (departPosLat != "" or arrivalPosLat != "" 1477 or speedFactor != -1 or insertionChecks != "") 1478 if withOptional: 1479 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii" + "ss" + "d" + "s", 18, 1480 routeID, typeID, depart, departLane, departPos, departSpeed, 1481 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, 1482 personCapacity, personNumber, departPosLat, arrivalPosLat, 1483 speedFactor, insertionChecks) 1484 else: 1485 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii", 14, 1486 routeID, typeID, depart, departLane, departPos, departSpeed, 1487 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, 1488 personCapacity, personNumber) 1489 1490 addFull = add 1491 1492 def dispatchTaxi(self, vehID, reservations): 1493 """dispatchTaxi(string, list(string)) -> None 1494 dispatches the taxi with the given id to service the given reservations. 1495 If only a single reservation is given, this implies pickup and drop-off 1496 If multiple reservations are given, each reservation id must occur twice 1497 (once for pickup and once for drop-off) and the list encodes ride 1498 sharing of passengers (in pickup and drop-off order) 1499 """ 1500 if isinstance(reservations, str): 1501 reservations = [reservations] 1502 self._setCmd(tc.CMD_TAXI_DISPATCH, vehID, "l", reservations) 1503 1504 def remove(self, vehID, reason=tc.REMOVE_VAPORIZED): 1505 '''Remove vehicle with the given ID for the give reason. 1506 Reasons are defined in module constants and start with REMOVE_''' 1507 self._setCmd(tc.REMOVE, vehID, "b", reason) 1508 1509 @alias_param("laneIndex", "lane") 1510 def moveToXY(self, vehID, edgeID, laneIndex, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 1511 '''Place vehicle at the given x,y coordinates and force its angle to 1512 the given value (for drawing). 1513 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 1514 natural angle of the edge on which it is driving. 1515 If keepRoute is set to 1, the closest position 1516 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 1517 any edge in the network but its route then only consists of that edge. 1518 If keepRoute is set to 2 the vehicle has all the freedom of keepRoute=0 1519 but in addition to that may even move outside the road network. 1520 edgeID and lane are optional placement hints to resolve ambiguities. 1521 The command fails if no suitable target position is found within the 1522 distance given by matchThreshold. 1523 ''' 1524 self._setCmd(tc.MOVE_TO_XY, vehID, "tsidddbd", 7, edgeID, laneIndex, x, y, angle, keepRoute, matchThreshold) 1525 1526 def addSubscriptionFilterLanes(self, lanes, noOpposite=False, downstreamDist=None, upstreamDist=None): 1527 """addSubscriptionFilterLanes(list(integer), bool, double, double) -> None 1528 1529 Adds a lane-filter to the last modified vehicle context subscription (call it just after subscribing). 1530 lanes is a list of relative lane indices (-1 -> right neighboring lane of the ego, 0 -> ego lane, etc.) 1531 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1532 downstreamDist and upstreamDist specify the range of the search for surrounding vehicles along the road net. 1533 """ 1534 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes) 1535 if noOpposite: 1536 self.addSubscriptionFilterNoOpposite() 1537 if downstreamDist is not None: 1538 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1539 if upstreamDist is not None: 1540 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1541 1542 def addSubscriptionFilterNoOpposite(self): 1543 """addSubscriptionFilterNoOpposite() -> None 1544 1545 Omits vehicles on other edges than the ego's for the last modified vehicle context subscription 1546 (call it just after subscribing). 1547 """ 1548 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_NOOPPOSITE) 1549 1550 def addSubscriptionFilterDownstreamDistance(self, dist): 1551 """addSubscriptionFilterDownstreamDist(float) -> None 1552 1553 Sets the downstream distance along the network for vehicles to be returned by the last modified 1554 vehicle context subscription (call it just after subscribing). 1555 """ 1556 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_DOWNSTREAM_DIST, dist) 1557 1558 def addSubscriptionFilterUpstreamDistance(self, dist): 1559 """addSubscriptionFilterUpstreamDist(float) -> None 1560 1561 Sets the upstream distance along the network for vehicles to be returned by the last modified 1562 vehicle context subscription (call it just after subscribing). 1563 """ 1564 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_UPSTREAM_DIST, dist) 1565 1566 def addSubscriptionFilterCFManeuver(self, downstreamDist=None, upstreamDist=None): 1567 """addSubscriptionFilterCFManeuver() -> None 1568 1569 Restricts vehicles returned by the last modified vehicle context subscription to leader and follower of the ego. 1570 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1571 """ 1572 self.addSubscriptionFilterLeadFollow([0]) 1573 if downstreamDist is not None: 1574 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1575 if upstreamDist is not None: 1576 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1577 1578 def addSubscriptionFilterLCManeuver(self, direction=None, noOpposite=False, downstreamDist=None, upstreamDist=None): 1579 """addSubscriptionFilterLCManeuver(int) -> None 1580 1581 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1582 and follower of the ego. 1583 direction - lane change direction (in {-1=right, 1=left}) 1584 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1585 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1586 Combine with: distance filters; vClass/vType filter. 1587 """ 1588 if direction is None: 1589 # Using default: both directions 1590 lanes = [-1, 0, 1] 1591 elif not (direction == -1 or direction == 1): 1592 warnings.warn("Ignoring lane change subscription filter " + 1593 "with non-neighboring lane offset direction=%s." % direction) 1594 return 1595 else: 1596 lanes = [0, direction] 1597 self.addSubscriptionFilterLeadFollow(lanes) 1598 if noOpposite: 1599 self.addSubscriptionFilterNoOpposite() 1600 if downstreamDist is not None: 1601 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1602 if upstreamDist is not None: 1603 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1604 1605 def addSubscriptionFilterLeadFollow(self, lanes): 1606 """addSubscriptionFilterLCManeuver(lanes) -> None 1607 1608 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1609 and follower of the ego. 1610 Combine with: lanes-filter to restrict to one direction; distance filters; vClass/vType filter. 1611 """ 1612 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LEAD_FOLLOW) 1613 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes) 1614 1615 def addSubscriptionFilterTurn(self, downstreamDist=None, foeDistToJunction=None): 1616 """addSubscriptionFilterTurn(double, double) -> None 1617 1618 Restricts vehicles returned by the last modified vehicle context subscription to foes on upcoming junctions 1619 """ 1620 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_TURN, foeDistToJunction) 1621 if downstreamDist is not None: 1622 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1623 1624 def addSubscriptionFilterVClass(self, vClasses): 1625 """addSubscriptionFilterVClass(list(String)) -> None 1626 1627 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given classes 1628 """ 1629 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VCLASS, vClasses) 1630 1631 def addSubscriptionFilterVType(self, vTypes): 1632 """addSubscriptionFilterVType(list(String)) -> None 1633 1634 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given types 1635 """ 1636 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VTYPE, vTypes) 1637 1638 def addSubscriptionFilterFieldOfVision(self, openingAngle): 1639 """addSubscriptionFilterFieldOfVision(float) -> None 1640 1641 Restricts vehicles returned by the last modified vehicle context subscription 1642 to vehicles within field of vision with given opening angle 1643 """ 1644 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_FIELD_OF_VISION, openingAngle) 1645 1646 def addSubscriptionFilterLateralDistance(self, lateralDist, downstreamDist=None, upstreamDist=None): 1647 """addSubscriptionFilterLateralDist(double, double, double) -> None 1648 1649 Adds a lateral distance filter to the last modified vehicle context subscription 1650 (call it just after subscribing). 1651 downstreamDist and upstreamDist specify the longitudinal range of the search 1652 for surrounding vehicles along the ego vehicle's route. 1653 """ 1654 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LATERAL_DIST, lateralDist) 1655 if downstreamDist is not None: 1656 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1657 if upstreamDist is not None: 1658 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
38class StopData(object): 39 40 def __init__(self, 41 lane="", 42 startPos=-1, 43 endPos=-1, 44 stoppingPlaceID="", 45 stopFlags=0, 46 duration=-1, 47 until=-1, 48 intendedArrival=-1, 49 arrival=-1, 50 depart=-1, 51 split="", 52 join="", 53 actType="", 54 tripId="", 55 line="", 56 speed=0): 57 self.lane = lane 58 self.startPos = startPos 59 self.endPos = endPos 60 self.stoppingPlaceID = stoppingPlaceID 61 self.stopFlags = stopFlags 62 self.duration = duration 63 self.until = until 64 self.intendedArrival = intendedArrival 65 self.arrival = arrival 66 self.depart = depart 67 self.split = split 68 self.join = join 69 self.actType = actType 70 self.tripId = tripId 71 self.line = line 72 self.speed = speed 73 74 def __attr_repr__(self, attrname, default=""): 75 if getattr(self, attrname) == default: 76 return "" 77 else: 78 val = getattr(self, attrname) 79 if val == tc.INVALID_DOUBLE_VALUE: 80 val = "INVALID" 81 return "%s=%s" % (attrname, val) 82 83 def __repr__(self): 84 return "StopData(%s)" % ', '.join([v for v in [ 85 self.__attr_repr__("lane"), 86 self.__attr_repr__("startPos"), 87 self.__attr_repr__("endPos"), 88 self.__attr_repr__("stoppingPlaceID"), 89 self.__attr_repr__("stopFlags"), 90 self.__attr_repr__("duration", tc.INVALID_DOUBLE_VALUE), 91 self.__attr_repr__("until", tc.INVALID_DOUBLE_VALUE), 92 self.__attr_repr__("intendedArrival", tc.INVALID_DOUBLE_VALUE), 93 self.__attr_repr__("arrival", tc.INVALID_DOUBLE_VALUE), 94 self.__attr_repr__("depart", tc.INVALID_DOUBLE_VALUE), 95 self.__attr_repr__("split"), 96 self.__attr_repr__("join"), 97 self.__attr_repr__("actType"), 98 self.__attr_repr__("tripId"), 99 self.__attr_repr__("line"), 100 self.__attr_repr__("speed", 0), 101 ] if v != ""])
40 def __init__(self, 41 lane="", 42 startPos=-1, 43 endPos=-1, 44 stoppingPlaceID="", 45 stopFlags=0, 46 duration=-1, 47 until=-1, 48 intendedArrival=-1, 49 arrival=-1, 50 depart=-1, 51 split="", 52 join="", 53 actType="", 54 tripId="", 55 line="", 56 speed=0): 57 self.lane = lane 58 self.startPos = startPos 59 self.endPos = endPos 60 self.stoppingPlaceID = stoppingPlaceID 61 self.stopFlags = stopFlags 62 self.duration = duration 63 self.until = until 64 self.intendedArrival = intendedArrival 65 self.arrival = arrival 66 self.depart = depart 67 self.split = split 68 self.join = join 69 self.actType = actType 70 self.tripId = tripId 71 self.line = line 72 self.speed = speed
251class VehicleDomain(VTypeDomain): 252 # imported for backwards compatibility 253 STOP_DEFAULT = tc.STOP_DEFAULT 254 STOP_PARKING = tc.STOP_PARKING 255 STOP_TRIGGERED = tc.STOP_TRIGGERED 256 STOP_CONTAINER_TRIGGERED = tc.STOP_CONTAINER_TRIGGERED 257 STOP_BUS_STOP = tc.STOP_BUS_STOP 258 STOP_CONTAINER_STOP = tc.STOP_CONTAINER_STOP 259 STOP_CHARGING_STATION = tc.STOP_CHARGING_STATION 260 STOP_PARKING_AREA = tc.STOP_PARKING_AREA 261 DEPART_TRIGGERED = tc.DEPARTFLAG_TRIGGERED 262 DEPART_CONTAINER_TRIGGERED = tc.DEPARTFLAG_CONTAINER_TRIGGERED 263 DEPART_NOW = tc.DEPARTFLAG_NOW 264 DEPART_SPEED_RANDOM = tc.DEPARTFLAG_SPEED_RANDOM 265 DEPART_SPEED_MAX = tc.DEPARTFLAG_SPEED_MAX 266 DEPART_LANE_RANDOM = tc.DEPARTFLAG_LANE_RANDOM 267 DEPART_LANE_FREE = tc.DEPARTFLAG_LANE_FREE 268 DEPART_LANE_ALLOWED_FREE = tc.DEPARTFLAG_LANE_ALLOWED_FREE 269 DEPART_LANE_BEST_FREE = tc.DEPARTFLAG_LANE_BEST_FREE 270 DEPART_LANE_FIRST_ALLOWED = tc.DEPARTFLAG_LANE_FIRST_ALLOWED 271 272 def __init__(self): 273 VTypeDomain.__init__(self, "vehicle", tc.CMD_GET_VEHICLE_VARIABLE, tc.CMD_SET_VEHICLE_VARIABLE, 274 tc.CMD_SUBSCRIBE_VEHICLE_VARIABLE, tc.RESPONSE_SUBSCRIBE_VEHICLE_VARIABLE, 275 tc.CMD_SUBSCRIBE_VEHICLE_CONTEXT, tc.RESPONSE_SUBSCRIBE_VEHICLE_CONTEXT, 276 _RETURN_VALUE_FUNC, subscriptionDefault=(tc.VAR_ROAD_ID, tc.VAR_LANEPOSITION)) 277 278 def getSpeed(self, vehID): 279 """getSpeed(string) -> double 280 281 Returns the (longitudinal) speed in m/s of the named vehicle within the last step. 282 """ 283 return self._getUniversal(tc.VAR_SPEED, vehID) 284 285 def getLateralSpeed(self, vehID): 286 """getLateralSpeed(string) -> double 287 288 Returns the lateral speed in m/s of the named vehicle within the last step. 289 """ 290 return self._getUniversal(tc.VAR_SPEED_LAT, vehID) 291 292 def getAcceleration(self, vehID): 293 """getAcceleration(string) -> double 294 295 Returns the acceleration in m/s^2 of the named vehicle within the last step. 296 """ 297 return self._getUniversal(tc.VAR_ACCELERATION, vehID) 298 299 def getSpeedWithoutTraCI(self, vehID): 300 """getSpeedWithoutTraCI(string) -> double 301 Returns the speed that the vehicle would drive if no speed-influencing 302 command such as setSpeed or slowDown was given. 303 """ 304 return self._getUniversal(tc.VAR_SPEED_WITHOUT_TRACI, vehID) 305 306 def getPosition(self, vehID): 307 """getPosition(string) -> (double, double) 308 309 Returns the position of the named vehicle within the last step [m,m]. 310 """ 311 return self._getUniversal(tc.VAR_POSITION, vehID) 312 313 def getPosition3D(self, vehID): 314 """getPosition3D(string) -> (double, double, double) 315 316 Returns the position of the named vehicle within the last step [m,m,m]. 317 """ 318 return self._getUniversal(tc.VAR_POSITION3D, vehID) 319 320 def getAngle(self, vehID): 321 """getAngle(string) -> double 322 323 Returns the angle in degrees of the named vehicle within the last step. 324 """ 325 return self._getUniversal(tc.VAR_ANGLE, vehID) 326 327 def getRoadID(self, vehID): 328 """getRoadID(string) -> string 329 330 Returns the id of the edge the named vehicle was at within the last step. 331 """ 332 return self._getUniversal(tc.VAR_ROAD_ID, vehID) 333 334 def getDeparture(self, vehID): 335 """getDeparture(string) -> double 336 337 Returns the actual departure time in seconds 338 """ 339 return self._getUniversal(tc.VAR_DEPARTURE, vehID) 340 341 def getDepartDelay(self, vehID): 342 """getDepartDelay(string) -> double 343 344 Returns the delay between intended and actual departure in seconds 345 """ 346 return self._getUniversal(tc.VAR_DEPART_DELAY, vehID) 347 348 def getLaneID(self, vehID): 349 """getLaneID(string) -> string 350 351 Returns the id of the lane the named vehicle was at within the last step. 352 """ 353 return self._getUniversal(tc.VAR_LANE_ID, vehID) 354 355 def getShadowLaneID(self, vehID): 356 """getShadowLaneID(string) -> string 357 358 Returns the id of the shadow lane if the vehicle is currently changing lanes. 359 """ 360 return self._getUniversal(tc.VAR_SHADOW_LANE_ID, vehID) 361 362 def getLaneIndex(self, vehID): 363 """getLaneIndex(string) -> integer 364 365 Returns the index of the lane the named vehicle was at within the last step. 366 """ 367 return self._getUniversal(tc.VAR_LANE_INDEX, vehID) 368 369 def getSegmentID(self, vehID): 370 """getSegmentID(string) -> string 371 372 Returns the id of the segment the named vehicle was at within the last step (mesosim). 373 """ 374 return self._getUniversal(tc.VAR_SEGMENT_ID, vehID) 375 376 def getSegmentIndex(self, vehID): 377 """getSegmentIndex(string) -> integer 378 379 Returns the index of the segment the named vehicle was at within the last step (mesosim). 380 """ 381 return self._getUniversal(tc.VAR_SEGMENT_INDEX, vehID) 382 383 def getTypeID(self, vehID): 384 """getTypeID(string) -> string 385 386 Returns the id of the type of the named vehicle. 387 """ 388 return self._getUniversal(tc.VAR_TYPE, vehID) 389 390 def getRouteID(self, vehID): 391 """getRouteID(string) -> string 392 393 Returns the id of the route of the named vehicle. 394 """ 395 return self._getUniversal(tc.VAR_ROUTE_ID, vehID) 396 397 def getRouteIndex(self, vehID): 398 """getRouteIndex(string) -> int 399 400 Returns the index of the current edge within the vehicles route or -1 if the 401 vehicle has not yet departed 402 """ 403 return self._getUniversal(tc.VAR_ROUTE_INDEX, vehID) 404 405 def getRoute(self, vehID): 406 """getRoute(string) -> tuple(string) 407 408 Returns the ids of the edges the vehicle's route is made of. 409 """ 410 return self._getUniversal(tc.VAR_EDGES, vehID) 411 412 def getLanePosition(self, vehID): 413 """getLanePosition(string) -> double 414 415 The position of the vehicle along the lane measured in m. 416 """ 417 return self._getUniversal(tc.VAR_LANEPOSITION, vehID) 418 419 def getArrivalPos(self, vehID): 420 """getArrivalPos(string) -> double 421 422 The position at which the vehicle will arrive on the last edge of its route in m. 423 """ 424 return self._getUniversal(tc.VAR_ARRIVALPOS, vehID) 425 426 def getCO2Emission(self, vehID): 427 """getCO2Emission(string) -> double 428 429 Returns the CO2 emission in mg/s for the last time step. 430 Multiply by the step length to get the value for one step. 431 """ 432 return self._getUniversal(tc.VAR_CO2EMISSION, vehID) 433 434 def getCOEmission(self, vehID): 435 """getCOEmission(string) -> double 436 437 Returns the CO emission in mg/s for the last time step. 438 Multiply by the step length to get the value for one step. 439 """ 440 return self._getUniversal(tc.VAR_COEMISSION, vehID) 441 442 def getHCEmission(self, vehID): 443 """getHCEmission(string) -> double 444 445 Returns the HC emission in mg/s for the last time step. 446 Multiply by the step length to get the value for one step. 447 """ 448 return self._getUniversal(tc.VAR_HCEMISSION, vehID) 449 450 def getPMxEmission(self, vehID): 451 """getPMxEmission(string) -> double 452 453 Returns the particular matter emission in mg/s for the last time step. 454 Multiply by the step length to get the value for one step. 455 """ 456 return self._getUniversal(tc.VAR_PMXEMISSION, vehID) 457 458 def getNOxEmission(self, vehID): 459 """getNOxEmission(string) -> double 460 461 Returns the NOx emission in mg/s for the last time step. 462 Multiply by the step length to get the value for one step. 463 """ 464 return self._getUniversal(tc.VAR_NOXEMISSION, vehID) 465 466 def getFuelConsumption(self, vehID): 467 """getFuelConsumption(string) -> double 468 469 Returns the fuel consumption in mg/s for the last time step. 470 Multiply by the step length to get the value for one step. 471 """ 472 return self._getUniversal(tc.VAR_FUELCONSUMPTION, vehID) 473 474 def getNoiseEmission(self, vehID): 475 """getNoiseEmission(string) -> double 476 477 Returns the noise emission in db for the last time step. 478 """ 479 return self._getUniversal(tc.VAR_NOISEEMISSION, vehID) 480 481 def getElectricityConsumption(self, vehID): 482 """getElectricityConsumption(string) -> double 483 484 Returns the electricity consumption in Wh/s for the last time step. 485 Multiply by the step length to get the value for one step. 486 """ 487 return self._getUniversal(tc.VAR_ELECTRICITYCONSUMPTION, vehID) 488 489 def getPersonNumber(self, vehID): 490 """getPersonNumber(string) -> integer 491 Returns the total number of persons which includes those defined 492 using attribute 'personNumber' as well as <person>-objects who are riding in 493 this vehicle. 494 """ 495 return self._getUniversal(tc.VAR_PERSON_NUMBER, vehID) 496 497 def getPersonIDList(self, vehID): 498 """getPersonIDList(string) -> tuple(string) 499 Returns the tuple of persons who are riding in this vehicle. 500 """ 501 return self._getUniversal(tc.LAST_STEP_PERSON_ID_LIST, vehID) 502 503 def getAdaptedTraveltime(self, vehID, time, edgeID): 504 """getAdaptedTraveltime(string, double, string) -> double 505 506 Returns the information about the travel time of edge "edgeID" valid 507 for the given time from the vehicle's internal edge weights 508 container (see setAdaptedTraveltime). 509 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 510 """ 511 return self._getUniversal(tc.VAR_EDGE_TRAVELTIME, vehID, "tds", 2, time, edgeID) 512 513 def getEffort(self, vehID, time, edgeID): 514 """getEffort(string, double, string) -> double 515 516 Returns the information about the effort needed for edge "edgeID" valid 517 for the given time from the vehicle's internal effort 518 container (see setEffort). 519 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 520 """ 521 return self._getUniversal(tc.VAR_EDGE_EFFORT, vehID, "tds", 2, time, edgeID) 522 523 def isRouteValid(self, vehID): 524 """isRouteValid(string) -> bool 525 Returns whether the current vehicle route is connected for the vehicle 526 class of the given vehicle. 527 """ 528 return self._getUniversal(tc.VAR_ROUTE_VALID, vehID) 529 530 def getSignals(self, vehID): 531 """getSignals(string) -> integer 532 533 Returns an integer encoding the state of a vehicle's signals. 534 """ 535 return self._getUniversal(tc.VAR_SIGNALS, vehID) 536 537 def getLateralLanePosition(self, vehID): 538 """getLateralLanePosition(string) -> double 539 540 Returns the lateral position of the vehicle on its current lane measured in m. 541 """ 542 return self._getUniversal(tc.VAR_LANEPOSITION_LAT, vehID) 543 544 def getAllowedSpeed(self, vehID): 545 """getAllowedSpeed(string) -> double 546 547 Returns the maximum allowed speed on the current lane regarding speed factor in m/s for this vehicle. 548 """ 549 return self._getUniversal(tc.VAR_ALLOWED_SPEED, vehID) 550 551 def getWaitingTime(self, vehID): 552 """getWaitingTime(string) -> double 553 The waiting time of a vehicle is defined as the time (in seconds) spent with a 554 speed below 0.1m/s since the last time it was faster than 0.1m/s. 555 (basically, the waiting time of a vehicle is reset to 0 every time it moves). 556 A vehicle that is stopping intentionally with a <stop> does not accumulate waiting time. 557 """ 558 return self._getUniversal(tc.VAR_WAITING_TIME, vehID) 559 560 def getAccumulatedWaitingTime(self, vehID): 561 """getAccumulatedWaitingTime(string) -> double 562 The accumulated waiting time of a vehicle collects the vehicle's waiting time 563 over a certain time interval (interval length is set per option '--waiting-time-memory') 564 """ 565 return self._getUniversal(tc.VAR_ACCUMULATED_WAITING_TIME, vehID) 566 567 def getLaneChangeMode(self, vehID): 568 """getLaneChangeMode(string) -> integer 569 570 Gets the vehicle's lane change mode as a bitset. 571 """ 572 return self._getUniversal(tc.VAR_LANECHANGE_MODE, vehID) 573 574 def getSpeedMode(self, vehID): 575 """getSpeedMode(string) -> int 576 The speed mode of a vehicle 577 """ 578 return self._getUniversal(tc.VAR_SPEEDSETMODE, vehID) 579 580 def getSlope(self, vehID): 581 """getSlope(string) -> double 582 The slope at the current position of the vehicle in degrees 583 """ 584 return self._getUniversal(tc.VAR_SLOPE, vehID) 585 586 def getLine(self, vehID): 587 """getLine(string) -> string 588 589 Returns the line information of this vehicle. 590 """ 591 return self._getUniversal(tc.VAR_LINE, vehID) 592 593 def getVia(self, vehID): 594 """getVia(string) -> tuple(string) 595 596 Returns the ids of via edges for this vehicle 597 """ 598 return self._getUniversal(tc.VAR_VIA, vehID) 599 600 def getLastActionTime(self, vehID): 601 """getLastActionTime(string) -> double 602 603 Returns the time in s of last action point for this vehicle. 604 """ 605 return self._getUniversal(tc.VAR_LASTACTIONTIME, vehID) 606 607 def getBestLanes(self, vehID): 608 """getBestLanes(string) -> tuple(data) 609 where data is a tuple of (laneID, length, occupation, offset, allowsContinuation, tuple(nextLanes)) 610 611 For each lane of the current edge a data tuple is returned where the 612 entries have the following meaning: 613 - laneID: the id of that lane on the current edge 614 - the length that can be driven without lane change (measured from the start of that lane) 615 - the occupation on the future lanes (brutto vehicle lengths) 616 - the offset of that lane from the lane that would be strategically 617 preferred (this is the lane that requires the least future lane 618 changes or a lane that needs to be used for stopping) 619 - whether that lane allows continuing the route (for at least one more edge) 620 - the sequence of lanes that would be driven starting at laneID if no 621 lane change were to take place 622 """ 623 return self._getUniversal(tc.VAR_BEST_LANES, vehID) 624 625 def getLeader(self, vehID, dist=100.): 626 """getLeader(string, double) -> (string, double) 627 628 Return the leading vehicle id together with the distance. The distance 629 is measured from the front + minGap to the back of the leader, so it does not include the 630 minGap of the vehicle. 631 The dist parameter defines the minimum lookahead, 0 calculates a lookahead from the brake gap. 632 Note that the returned leader may be further away than the given dist and that the vehicle 633 will only look on its current best lanes and not look beyond the end of its final route edge. 634 635 In the case where no leader is found, the function returns 'None'. 636 This special case is deprecated. The future behavior is to return the 637 pair ("", -1) when no leader is found. 638 The function 'traci.setLegacyGetLeader(bool) can be used to switch 639 between both behaviors. 640 """ 641 return self._getUniversal(tc.VAR_LEADER, vehID, "d", dist) 642 643 def getFollower(self, vehID, dist=0.): 644 """getFollower(string, double) -> (string, double) 645 646 Return the following vehicle id together with the distance. The distance 647 is measured from the front + minGap of the follower to the back of vehID, so it does not include the 648 minGap of the follower. 649 The dist parameter defines the minimum lookback, 0 calculates the 650 lookback distance from the braking distance at 4.5m/s^2 at 2*roadSpeedLimit. 651 Due to junctions and lane merges, there may be multiple followers. 652 In this case, the "critical" follower is returned. This is the follower 653 where the value of (getSecureGap - gap) is maximal. 654 Note that the returned follower may be further away than the given dist. 655 """ 656 return self._getUniversal(tc.VAR_FOLLOWER, vehID, "d", dist) 657 658 def getRightFollowers(self, vehID, blockingOnly=False): 659 """ getRightFollowers(string, bool) -> tuple(tuple(string, double)) 660 Convenience method, see getNeighbors() 661 """ 662 if blockingOnly: 663 mode = 5 664 else: 665 mode = 1 666 return self.getNeighbors(vehID, mode) 667 668 def getRightLeaders(self, vehID, blockingOnly=False): 669 """ getRightLeaders(string, bool) -> tuple(tuple(string, double)) 670 Convenience method, see getNeighbors() 671 """ 672 if blockingOnly: 673 mode = 7 674 else: 675 mode = 3 676 return self.getNeighbors(vehID, mode) 677 678 def getLeftFollowers(self, vehID, blockingOnly=False): 679 """ getLeftFollowers(string, bool) -> tuple(tuple(string, double)) 680 Convenience method, see getNeighbors() 681 """ 682 if blockingOnly: 683 mode = 4 684 else: 685 mode = 0 686 return self.getNeighbors(vehID, mode) 687 688 def getLeftLeaders(self, vehID, blockingOnly=False): 689 """ getLeftLeaders(string, bool) -> tuple(tuple(string, double)) 690 Convenience method, see getNeighbors() 691 """ 692 if blockingOnly: 693 mode = 6 694 else: 695 mode = 2 696 return self.getNeighbors(vehID, mode) 697 698 def getNeighbors(self, vehID, mode): 699 """ getNeighbors(string, byte) -> tuple(tuple(string, double)) 700 701 The parameter mode is a bitset (UBYTE), specifying the following: 702 bit 1: query lateral direction (left:0, right:1) 703 bit 2: query longitudinal direction (followers:0, leaders:1) 704 bit 3: blocking (return all:0, return only blockers:1) 705 706 The returned tuple contains pairs (ID, dist) for all lane change relevant neighboring leaders, resp. followers, 707 along with their longitudinal distance to the ego vehicle (egoFront - egoMinGap to leaderBack, resp. 708 followerFront - followerMinGap to egoBack. The value can be negative for overlapping neighs). 709 For the non-sublane case, the lists will contain at most one entry. 710 711 Note: The exact set of blockers in case blocking==1 is not determined for the sublane model, 712 but either all neighboring vehicles are returned (in case LCA_BLOCKED) or 713 none is returned (in case !LCA_BLOCKED). 714 """ 715 return self._getUniversal(tc.VAR_NEIGHBORS, vehID, "B", mode) 716 717 def getFollowSpeed(self, vehID, speed, gap, leaderSpeed, leaderMaxDecel, leaderID=""): 718 """getFollowSpeed(string, double, double, double, double, string) -> double 719 Return the follow speed computed by the carFollowModel of vehID 720 """ 721 return self._getUniversal(tc.VAR_FOLLOW_SPEED, vehID, "tdddds", 5, 722 speed, gap, leaderSpeed, leaderMaxDecel, leaderID) 723 724 def getSecureGap(self, vehID, speed, leaderSpeed, leaderMaxDecel, leaderID=""): 725 """getSecureGap(string, double, double, double, string) -> double 726 Return the secure gap computed by the carFollowModel of vehID 727 """ 728 return self._getUniversal(tc.VAR_SECURE_GAP, vehID, "tddds", 4, 729 speed, leaderSpeed, leaderMaxDecel, leaderID) 730 731 def getStopSpeed(self, vehID, speed, gap): 732 """getStopSpeed(string, double, double) -> double 733 Return the speed for stopping at gap computed by the carFollowModel of vehID 734 """ 735 return self._getUniversal(tc.VAR_STOP_SPEED, vehID, "tdd", 2, speed, gap) 736 737 def getStopDelay(self, vehID): 738 """getStopDelay(string) -> double 739 Returns the expected depart delay at the next stop (if that stop defines the 740 until-attribute) in seconds. Returns -1 if the next stop is not applicable 741 """ 742 return self._getUniversal(tc.VAR_STOP_DELAY, vehID) 743 744 def getStopArrivalDelay(self, vehID): 745 """getStopArrivalDelay(string) -> double 746 Returns the expected arrival delay at the next stop (if that stop defines the 747 arrival-attribute) in seconds. The returned value may be negative to 748 indicate early arrival. Returns INVALID_DOUBLE if the next stop is not applicable 749 """ 750 return self._getUniversal(tc.VAR_STOP_ARRIVALDELAY, vehID) 751 752 def getTimeLoss(self, vehID): 753 """getTimeLoss(string) -> double 754 Returns the time loss since departure 755 """ 756 return self._getUniversal(tc.VAR_TIMELOSS, vehID) 757 758 def getNextTLS(self, vehID): 759 """getNextTLS(string) -> tuple(tuple(string, int, double, string)) 760 761 Return tuple of upcoming traffic lights [(tlsID, tlsIndex, distance, state), ...] 762 """ 763 return self._getUniversal(tc.VAR_NEXT_TLS, vehID) 764 765 @alias_param("dist", "distance") 766 def getJunctionFoes(self, vehID, dist=0.): 767 """getJunctionFoes(string, double) -> complex 768 769 Return tuple of junction foes [(foeId, egoDist, foeDist, egoExitDist, foeExitDist, 770 egoLane, foeLane, egoResponse, foeResponse), ...] within the given distance to the given vehicle. 771 """ 772 return self._getUniversal(tc.VAR_FOES, vehID, "d", dist) 773 774 @deprecated() 775 def getNextStops(self, vehID): 776 """getNextStops(string) -> tuple(tuple(string, double, string, int, double, double)) 777 778 Return tuple of upcoming stops ((lane, endPos, stoppingPlaceID, stopFlags, duration, until), ...) 779 where integer stopFlag is defined as: 780 1 * stopped + 781 2 * parking + 782 4 * personTriggered + 783 8 * containerTriggered + 784 16 * isBusStop + 785 32 * isContainerStop + 786 64 * chargingStation + 787 128 * parkingarea 788 with each of these flags defined as 0 or 1. 789 """ 790 return self._getUniversal(tc.VAR_NEXT_STOPS, vehID) 791 792 def getNextLinks(self, vehID): 793 """getNextLinks(string) -> tuple(tuple(string, string, bool, bool, bool, string, string, double)) 794 795 Return tuple of upcoming links along the route ((lane, via, priority, opened, foe, 796 state, direction, length), ...) 797 """ 798 return self._getUniversal(tc.VAR_NEXT_LINKS, vehID) 799 800 def getStops(self, vehID, limit=0): 801 """getStops(string, int) -> tuple(StopData) 802 803 Return a tuple of StopData object. The flags are the same as for setStop and 804 replaceStop (and different from getNextStops(!) for backward compatibility): 805 1 * parking + 806 2 * personTriggered + 807 4 * containerTriggered + 808 8 * isBusStop + 809 16 * isContainerStop + 810 32 * chargingStation + 811 64 * parkingarea 812 with each of these flags defined as 0 or 1. 813 814 The optional argument limit can be used to limit the returned stops to 815 the next INT number (i.e. limit=1 if only the next stop is required). 816 Setting a negative limit returns up to 'limit' previous stops (or fewer 817 if the vehicle stopped fewer times previously) 818 """ 819 return self._getUniversal(tc.VAR_NEXT_STOPS2, vehID, "i", limit) 820 821 def subscribeLeader(self, vehID, dist=0., begin=0, end=2**31 - 1): 822 """subscribeLeader(string, double, double, double) -> None 823 824 Subscribe for the leading vehicle id together with the distance. 825 The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap. 826 """ 827 self.subscribe(vehID, (tc.VAR_LEADER,), begin, end, {tc.VAR_LEADER: ("d", dist)}) 828 829 def getDrivingDistance(self, vehID, edgeID, pos, laneIndex=0): 830 """getDrivingDistance(string, string, double, integer) -> double 831 832 For an edge along the remaining route of vehID, return the distance from the current vehicle position 833 to the given edge and position along the vehicles route. 834 Otherwise, return INVALID_DOUBLE_VALUE 835 """ 836 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tru", 2, 837 (edgeID, pos, laneIndex), tc.REQUEST_DRIVINGDIST) 838 839 def getDrivingDistance2D(self, vehID, x, y): 840 """getDrivingDistance2D(string, double, double) -> integer 841 842 Return the distance to the given network position along the vehicles route. 843 """ 844 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tou", 2, (x, y), tc.REQUEST_DRIVINGDIST) 845 846 def getDistance(self, vehID): 847 """getDistance(string) -> double 848 849 Returns the distance to the starting point like an odometer. 850 """ 851 return self._getUniversal(tc.VAR_DISTANCE, vehID) 852 853 def getReferenceDistance(self, vehID): 854 """getReferenceDistance(string) -> double 855 Returns the distance along the linear reference system 856 in which the current edge takes part (i.e. kilometrage/mile markers) 857 """ 858 return self._getUniversal(tc.VAR_REFERENCE_DISTANCE, vehID) 859 860 def getStopParameter(self, vehID, nextStopIndex, param, customParam=False): 861 """getStopParameter(string, int, string) -> string 862 Gets the value of the given parameter for the stop at the given index 863 Negative indices permit access to past stops. 864 Supported params correspond to all legal stop xml-attributes 865 If customParam is set to True, the user defined stop parameter with the 866 specified param name will be returned instead (or "" if undefined) 867 """ 868 return self._getUniversal(tc.VAR_STOP_PARAMETER, vehID, "tisb", 3, nextStopIndex, param, customParam) 869 870 def getStopState(self, vehID): 871 """getStopState(string) -> integer 872 873 Returns information in regard to stopping: 874 The returned integer is defined as 1 * stopped + 2 * parking 875 + 4 * personTriggered + 8 * containerTriggered + 16 * isBusStop 876 + 32 * isContainerStop 877 with each of these flags defined as 0 or 1 878 """ 879 return self._getUniversal(tc.VAR_STOPSTATE, vehID) 880 881 def isStopped(self, vehID): 882 """isStopped(string) -> bool 883 Return whether the vehicle is stopped 884 """ 885 return (self.getStopState(vehID) & 1) == 1 886 887 def isStoppedParking(self, vehID): 888 """isStoppedParking(string) -> bool 889 Return whether the vehicle is parking (implies stopped) 890 """ 891 return (self.getStopState(vehID) & 2) == 2 892 893 def isStoppedTriggered(self, vehID): 894 """isStoppedTriggered(string) -> bool 895 Return whether the vehicle is stopped and waiting for a person or container 896 """ 897 return (self.getStopState(vehID) & 12) > 0 898 899 def isAtBusStop(self, vehID): 900 """isAtBusStop(string) -> bool 901 Return whether the vehicle is stopped at a bus stop 902 """ 903 return (self.getStopState(vehID) & 16) == 16 904 905 def isAtContainerStop(self, vehID): 906 """isAtContainerStop(string) -> bool 907 Return whether the vehicle is stopped at a container stop 908 """ 909 return (self.getStopState(vehID) & 32) == 32 910 911 def getLaneChangeState(self, vehID, direction): 912 """getLaneChangeState(string, int) -> (int, int) 913 Return the lane change state for the vehicle. The first value returns 914 the state as computed by the lane change model and the second value 915 returns the state after incorporation TraCI requests. 916 See getLaneChangeStatePretty for an interpretation of the integer/bitset 917 results 918 """ 919 return self._getUniversal(tc.CMD_CHANGELANE, vehID, "i", direction) 920 921 def getLaneChangeStatePretty(self, vehID, direction): 922 """getLaneChangeStatePretty(string, int) -> ([string, ...], [string, ...]) 923 Return the lane change state for the vehicle as two lists of string 924 constants. The first tuple returns the state as computed by the lane change 925 model and the second tuple returns the state after incorporation TraCI requests. 926 """ 927 constants = { 928 0: 'stay', 929 1: 'left', 930 2: 'right', 931 3: 'strategic', 932 4: 'cooperative', 933 5: 'speedGain', 934 6: 'keepRight', 935 7: 'TraCI', 936 8: 'urgent', 937 9: 'blocked by left leader', 938 10: 'blocked by left follower', 939 11: 'blocked by right leader', 940 12: 'blocked by right follower', 941 13: 'overlapping', 942 14: 'insufficient space', 943 15: 'sublane', 944 } 945 946 def prettifyBitstring(intval): 947 return tuple([v for k, v in constants.items() if (intval & 2**k)]) 948 949 state, stateTraCI = self.getLaneChangeState(vehID, direction) 950 return prettifyBitstring(state), prettifyBitstring(stateTraCI) 951 952 def couldChangeLane(self, vehID, direction, state=None): 953 """couldChangeLane(string, int) -> bool 954 Return whether the vehicle could change lanes in the specified direction. 955 This reflects the state after the last try to change lanes. 956 If you want to execute changeLane as a result of the evaluation of this function 957 it is not guaranteed to work because vehicle movements occur first. 958 """ 959 if state is None: 960 state, stateTraCI = self.getLaneChangeState(vehID, direction) 961 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 962 # vehicle changed in the last step. state is no longer applicable 963 return False 964 return state != tc.LCA_UNKNOWN and (state & tc.LCA_BLOCKED == 0) 965 966 def wantsAndCouldChangeLane(self, vehID, direction, state=None): 967 """wantsAndCouldChangeLane(string, int) -> bool 968 Return whether the vehicle wants to and could change lanes in the specified direction 969 This reflects the state after the last try to change lanes. 970 If you want to execute changeLane as a result of the evaluation of this function 971 it is not guaranteed to work because vehicle movements occur first. 972 """ 973 if state is None: 974 state, stateTraCI = self.getLaneChangeState(vehID, direction) 975 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 976 # vehicle changed in the last step. state is no longer applicable 977 return False 978 if state & tc.LCA_BLOCKED == 0: 979 if direction == -1: 980 return state & tc.LCA_RIGHT != 0 981 if direction == 1: 982 return state & tc.LCA_LEFT != 0 983 return False 984 985 def getRoutingMode(self, vehID): 986 """getRoutingMode(string) 987 returns the current routing mode: 988 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 989 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 990 """ 991 return self._getUniversal(tc.VAR_ROUTING_MODE, vehID) 992 993 @alias_param("taxiState", "flag") 994 def getTaxiFleet(self, taxiState=0): 995 """getTaxiFleet(int) -> tuple(string) 996 Return the tuple of all taxis with the given taxiState: 997 0 : empty 998 1 : pickup 999 2 : occupied 1000 """ 1001 return self._getUniversal(tc.VAR_TAXI_FLEET, "", "i", taxiState) 1002 1003 def getLoadedIDList(self): 1004 """getLoadedIDList() -> tuple(string) 1005 returns all loaded vehicles that have not yet left the simulation 1006 """ 1007 return self._getUniversal(tc.VAR_LOADED_LIST, "") 1008 1009 def getTeleportingIDList(self): 1010 """getTeleportingIDList() -> tuple(string) 1011 returns all teleporting or jumping vehicles 1012 """ 1013 return self._getUniversal(tc.VAR_TELEPORTING_LIST, "") 1014 1015 def rerouteParkingArea(self, vehID, parkingAreaID): 1016 """rerouteParkingArea(string, string) 1017 1018 Changes the next parking area in parkingAreaID, updates the vehicle route, 1019 and preserve consistency in case of passengers/containers on board. 1020 """ 1021 self._setCmd(tc.CMD_REROUTE_TO_PARKING, vehID, "ts", 1, parkingAreaID) 1022 1023 def setStop(self, vehID, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1024 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, until=tc.INVALID_DOUBLE_VALUE): 1025 """setStop(string, string, double, integer, double, integer, double, double) -> None 1026 1027 Adds or modifies a stop with the given parameters. The duration and the until attribute are 1028 in seconds. 1029 """ 1030 if type(duration) is int and duration >= 1000 and duration % 1000 == 0: 1031 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1032 self._setCmd(tc.CMD_STOP, vehID, "tsdbdbdd", 7, edgeID, pos, laneIndex, duration, flags, startPos, until) 1033 1034 def setBusStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1035 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1036 """setBusStop(string, string, double, double, integer) -> None 1037 1038 Adds or modifies a bus stop with the given parameters. The duration and the until attribute are 1039 in seconds. 1040 """ 1041 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_BUS_STOP) 1042 1043 def setContainerStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1044 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1045 """setContainerStop(string, string, double, double, integer) -> None 1046 1047 Adds or modifies a container stop with the given parameters. The duration and the until attribute are 1048 in seconds. 1049 """ 1050 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CONTAINER_STOP) 1051 1052 def setChargingStationStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1053 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1054 """setChargingStationStop(string, string, double, double, integer) -> None 1055 1056 Adds or modifies a stop at a chargingStation with the given parameters. The duration and the until attribute are 1057 in seconds. 1058 """ 1059 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CHARGING_STATION) 1060 1061 def setParkingAreaStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1062 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_PARKING): 1063 """setParkingAreaStop(string, string, double, double, integer) -> None 1064 1065 Adds or modifies a stop at a parkingArea with the given parameters. The duration and the until attribute are 1066 in seconds. 1067 """ 1068 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_PARKING_AREA) 1069 1070 def replaceStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1071 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1072 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1073 """replaceStop(string, int, string, double, integer, double, integer, double, double) -> None 1074 1075 Replaces stop at the given index (within the list of all stops) with a new stop. 1076 Automatically modifies the route if the replacement stop is at another location. 1077 For edgeID a stopping place id may be given if the flag marks this 1078 stop as stopping on busStop, parkingArea, containerStop etc. 1079 If edgeID is "", the stop at the given index will be removed without 1080 replacement and the route will not be modified (unless setting 1081 teleport=2 which will trigger rerouting between the prior and next stop) 1082 If teleport is set to 1, the route to the replacement stop will be 1083 disconnected (forcing a teleport). 1084 If stopIndex is 0 the gap will be between the current 1085 edge and the new stop. Otherwise the gap will be between the stop edge for 1086 nextStopIndex - 1 and the new stop. 1087 """ 1088 self._setCmd(tc.CMD_REPLACE_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1089 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport) 1090 1091 def insertStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1092 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1093 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1094 """insertStop(string, int, string, double, integer, double, integer, double, double) -> None 1095 1096 Insert stop at the given index (within the list of all existing stops). 1097 Automatically modifies the route if the new stop is not along the route between the preceeding 1098 and succeeding stops (or start / end). 1099 For edgeID a stopping place id may be given if the flag marks this 1100 stop as stopping on busStop, parkingArea, containerStop etc. 1101 If teleport is set to 1, the route to the new stop will be 1102 disconnected (forcing a teleport). 1103 If stopIndex is 0 the gap will be between the current 1104 edge and the new stop. Otherwise the gap will be between the stop edge for 1105 nextStopIndex - 1 and the new stop. 1106 """ 1107 self._setCmd(tc.CMD_INSERT_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1108 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport) 1109 1110 def setStopParameter(self, vehID, nextStopIndex, param, value, customParam=False): 1111 """setStopParameter(string, int, string, string) -> None 1112 Sets the value of the given parameter for the (upcoming) stop at the 1113 given index (within the list of all stops). 1114 Supported params correspond to (almost) all legal stop xml-attributes 1115 and their value semantics 1116 If customParam is set to True, the user defined stop parameter with the 1117 specified param name will be set instead 1118 """ 1119 self._setCmd(tc.VAR_STOP_PARAMETER, vehID, "tissb", 4, nextStopIndex, param, value, customParam) 1120 1121 def resume(self, vehID): 1122 """resume(string) -> None 1123 1124 Resumes the vehicle from the current stop (throws an error if the vehicle is not stopped). 1125 """ 1126 self._setCmd(tc.CMD_RESUME, vehID, "t", 0) 1127 1128 def changeLane(self, vehID, laneIndex, duration): 1129 """changeLane(string, int, double) -> None 1130 Forces a lane change to the lane with the given index; The lane change 1131 will be attempted for the given duration (in s) and if it succeeds, 1132 the vehicle will stay on that lane for the remaining duration. 1133 """ 1134 if type(duration) is int and duration >= 1000: 1135 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1136 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbd", 2, laneIndex, duration) 1137 1138 def changeLaneRelative(self, vehID, indexOffset, duration): 1139 """changeLaneRelative(string, int, double) -> None 1140 1141 Forces a relative lane change; if successful, 1142 the lane will be chosen for the given amount of time (in s). 1143 The indexOffset specifies the target lane relative to the vehicles current lane 1144 """ 1145 if type(duration) is int and duration >= 1000: 1146 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1147 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbdb", 3, indexOffset, duration, 1) 1148 1149 def changeSublane(self, vehID, latDist): 1150 """changeSublane(string, double) -> None 1151 Forces a lateral change by the given amount (negative values indicate changing to the right, positive 1152 to the left). This will override any other lane change motivations but conform to 1153 safety-constraints as configured by laneChangeMode. 1154 """ 1155 self._setCmd(tc.CMD_CHANGESUBLANE, vehID, "d", latDist) 1156 1157 def slowDown(self, vehID, speed, duration): 1158 """slowDown(string, double, double) -> None 1159 1160 Changes the speed smoothly to the given value over the given amount 1161 of time in seconds (can also be used to increase speed). 1162 """ 1163 if type(duration) is int and duration >= 1000: 1164 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1165 self._setCmd(tc.CMD_SLOWDOWN, vehID, "tdd", 2, speed, duration) 1166 1167 def openGap(self, vehID, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel=-1, referenceVehID=None): 1168 """openGap(string, double, double, double, double, double, string) -> None 1169 1170 Changes the vehicle's desired time headway (cf-parameter tau) smoothly to the given new value 1171 using the given change rate. Similarly, the given space headway is applied gradually 1172 to achieve a minimal spatial gap. 1173 The vehicle is commanded to keep the increased headway for 1174 the given duration once its target value is attained. The maximal value for the 1175 deceleration can be given to prevent harsh braking due to the change of tau. If maxDecel=-1, 1176 the limit determined by the CF model is used. 1177 A vehicle ID for a reference vehicle can optionally be given, otherwise, the gap is created with 1178 respect to the current leader on the ego vehicle's current lane. 1179 Note that this does only affect the following behavior regarding the current leader and does 1180 not influence the gap acceptance during lane change, etc. 1181 """ 1182 if type(duration) is int and duration >= 1000: 1183 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1184 if referenceVehID is None: 1185 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddd", 5, 1186 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel) 1187 else: 1188 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddds", 6, 1189 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, referenceVehID) 1190 1191 def deactivateGapControl(self, vehID): 1192 """deactivateGapControl(string) -> None 1193 1194 Deactivate the vehicle's gap control 1195 """ 1196 self.openGap(vehID, -1, -1, -1, -1) 1197 1198 def requestToC(self, vehID, leadTime): 1199 """ requestToC(string, double) -> None 1200 1201 Interface for triggering a transition of control for a vehicle equipped with a ToC device. 1202 """ 1203 self.setParameter(vehID, "device.toc.requestToC", str(leadTime)) 1204 1205 def changeTarget(self, vehID, edgeID): 1206 """changeTarget(string, string) -> None 1207 1208 The vehicle's destination edge is set to the given edge id. The route is rebuilt. 1209 """ 1210 self._setCmd(tc.CMD_CHANGETARGET, vehID, "s", edgeID) 1211 1212 def setType(self, vehID, typeID): 1213 """setType(string, string) -> None 1214 1215 Sets the id of the type for the named vehicle. 1216 """ 1217 self._setCmd(tc.VAR_TYPE, vehID, "s", typeID) 1218 1219 def setRouteID(self, vehID, routeID): 1220 """setRouteID(string, string) -> None 1221 1222 Changes the vehicles route to the route with the given id. 1223 """ 1224 self._setCmd(tc.VAR_ROUTE_ID, vehID, "s", routeID) 1225 1226 def setRoute(self, vehID, edgeList): 1227 """ 1228 setRoute(string, list) -> None 1229 1230 changes the vehicle route to given edges list. 1231 The first edge in the list has to be the one that the vehicle is at the moment. 1232 1233 example usage: 1234 setRoute('1', ['1', '2', '4', '6', '7']) 1235 1236 this changes route for vehicle id 1 to edges 1-2-4-6-7 1237 """ 1238 if isinstance(edgeList, str): 1239 edgeList = [edgeList] 1240 self._setCmd(tc.VAR_ROUTE, vehID, "l", edgeList) 1241 1242 def setLateralLanePosition(self, vehID, posLat): 1243 """setLateralLanePosition(string, double) -> None 1244 1245 Sets the lateral vehicle position relative to the center line of the 1246 lane in m (negative values are to the right in right-hand networks). 1247 The vehicle may adapt this position in the same step unless this is 1248 disabled via setLaneChangeMode. 1249 """ 1250 self._setCmd(tc.VAR_LANEPOSITION_LAT, vehID, "d", posLat) 1251 1252 def updateBestLanes(self, vehID): 1253 """ updateBestLanes(string) -> None 1254 Triggers an update of the vehicle's bestLanes (structure determining the lane preferences used by LC models) 1255 It may be called after modifying the vClass for instance. 1256 """ 1257 self._setCmd(tc.VAR_UPDATE_BESTLANES, vehID) 1258 1259 def setAdaptedTraveltime(self, vehID, edgeID, time=None, begTime=None, endTime=None): 1260 """setAdaptedTraveltime(string, string, double, double, double) -> None 1261 Inserts the information about the travel time of edge "edgeID" valid 1262 from begin time to end time into the vehicle's internal edge weights 1263 container. 1264 If the time is not specified, any previously set values for that edge 1265 are removed. 1266 If begTime or endTime are not specified the value is set for the whole 1267 simulation duration. 1268 """ 1269 if not isinstance(edgeID, str) and isinstance(begTime, str): 1270 # legacy handling 1271 warnings.warn( 1272 "Parameter order has changed for setAdaptedTraveltime(). Attempting legacy ordering. " + 1273 "Please update your code.", stacklevel=2) 1274 return self.setAdaptedTraveltime(vehID, begTime, endTime, edgeID, time) 1275 if time is None: 1276 # reset 1277 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "ts", 1, edgeID) 1278 elif begTime is None: 1279 # set value for the whole simulation 1280 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tsd", 2, edgeID, time) 1281 else: 1282 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tddsd", 4, begTime, endTime, edgeID, time) 1283 1284 def setEffort(self, vehID, edgeID, effort=None, begTime=None, endTime=None): 1285 """setEffort(string, string, double, double, double) -> None 1286 Inserts the information about the effort of edge "edgeID" valid from 1287 begin time to end time into the vehicle's internal edge weights 1288 container. 1289 If the time is not specified, any previously set values for that edge 1290 are removed. 1291 If begTime or endTime are not specified the value is set for the whole 1292 simulation duration. 1293 """ 1294 if not isinstance(edgeID, str) and isinstance(begTime, str): 1295 # legacy handling 1296 warnings.warn( 1297 "Parameter order has changed for setEffort(). Attempting legacy ordering. Please update your code.", 1298 stacklevel=2) 1299 return self.setEffort(vehID, begTime, endTime, edgeID, effort) 1300 if effort is None: 1301 # reset 1302 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "ts", 1, edgeID) 1303 elif begTime is None: 1304 # set value for the whole simulation 1305 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tsd", 2, edgeID, effort) 1306 else: 1307 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tddsd", 4, begTime, endTime, edgeID, effort) 1308 1309 LAST_TRAVEL_TIME_UPDATE = -1 1310 1311 def setRoutingMode(self, vehID, routingMode): 1312 """setRoutingMode(string, int) -> None 1313 Sets the current routing mode: 1314 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 1315 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 1316 tc.ROUTING_MODE_AGGREGATED_CUSTOM : use weight storages and fall-back to smoothed travel times 1317 """ 1318 self._setCmd(tc.VAR_ROUTING_MODE, vehID, "i", routingMode) 1319 1320 def rerouteTraveltime(self, vehID, currentTravelTimes=True): 1321 """rerouteTraveltime(string, bool) -> None 1322 Reroutes a vehicle. 1323 If currentTravelTimes is True (default) and the routing mode is still ROUTING_MODE_DEFAULT 1324 then the ROUTING_MODE_AGGREGATED_CUSTOM gets activated temporarily 1325 and used for rerouting. The various functions and options for 1326 customizing travel times are described at https://sumo.dlr.de/wiki/Simulation/Routing 1327 1328 When rerouteTraveltime has been called once with an aggregated routing mode, 1329 edge weight storage and update gets activated which might slow down the simulation. 1330 """ 1331 if currentTravelTimes: 1332 routingMode = self.getRoutingMode(vehID) 1333 if routingMode == tc.ROUTING_MODE_DEFAULT: 1334 self.setRoutingMode(vehID, tc.ROUTING_MODE_AGGREGATED_CUSTOM) 1335 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, vehID, "t", 0) 1336 if currentTravelTimes and routingMode == tc.ROUTING_MODE_DEFAULT: 1337 self.setRoutingMode(vehID, routingMode) 1338 1339 def rerouteEffort(self, vehID): 1340 """rerouteEffort(string) -> None 1341 Reroutes a vehicle according to the effort values. 1342 """ 1343 self._setCmd(tc.CMD_REROUTE_EFFORT, vehID, "t", 0) 1344 1345 def setSignals(self, vehID, signals): 1346 """setSignals(string, integer) -> None 1347 1348 Sets an integer encoding the state of the vehicle's signals. 1349 """ 1350 self._setCmd(tc.VAR_SIGNALS, vehID, "i", signals) 1351 1352 def moveTo(self, vehID, laneID, pos, reason=tc.MOVE_AUTOMATIC): 1353 """moveTo(string, string, double, integer) -> None 1354 1355 Move a vehicle to a new position along its current route. 1356 """ 1357 self._setCmd(tc.VAR_MOVE_TO, vehID, "tsdi", 3, laneID, pos, reason) 1358 1359 def setSpeed(self, vehID, speed): 1360 """setSpeed(string, double) -> None 1361 1362 Sets the speed in m/s for the named vehicle within the last step. 1363 Calling with speed=-1 hands the vehicle control back to SUMO. 1364 """ 1365 self._setCmd(tc.VAR_SPEED, vehID, "d", speed) 1366 1367 def setAcceleration(self, vehID, acceleration, duration): 1368 """setAcceleration(string, double, double) -> None 1369 1370 Sets the acceleration in m/s^2 for the named vehicle and the given duration. 1371 """ 1372 self._setCmd(tc.VAR_ACCELERATION, vehID, "tdd", 2, acceleration, duration) 1373 1374 def setPreviousSpeed(self, vehID, speed, acceleration=tc.INVALID_DOUBLE_VALUE): 1375 """setPreviousSpeed(string, double, double) -> None 1376 1377 Sets the previous speed in m/s for the named vehicle wich will be used for 1378 calculations in the current step. Optionally, the acceleration for the 1379 previous step (in m/s^2) can be set as well. 1380 """ 1381 self._setCmd(tc.VAR_PREV_SPEED, vehID, "tdd", 2, speed, acceleration) 1382 1383 def setLine(self, vehID, line): 1384 """setLine(string, string) -> None 1385 1386 Sets the line information for this vehicle. 1387 """ 1388 self._setCmd(tc.VAR_LINE, vehID, "s", line) 1389 1390 def setVia(self, vehID, edgeList): 1391 """ 1392 setVia(string, list) -> None 1393 1394 changes the via edges to the given edges list (to be used during 1395 subsequent rerouting calls). 1396 1397 Note: a single edgeId as argument is allowed as shorthand for a list of length 1 1398 """ 1399 if isinstance(edgeList, str): 1400 edgeList = [edgeList] 1401 self._setCmd(tc.VAR_VIA, vehID, "l", edgeList) 1402 1403 def highlight(self, vehID, color=(255, 0, 0, 255), size=-1, alphaMax=-1, duration=-1, type=0): 1404 """ highlight(string, color, float, ubyte, float, ubyte) -> None 1405 Adds a circle of the given color tracking the vehicle. 1406 If a positive size [in m] is given the size of the highlight is chosen accordingly, 1407 otherwise the length of the vehicle is used as reference. 1408 If alphaMax and duration are positive, the circle fades in and out within the given duration, 1409 otherwise it permanently follows the vehicle. 1410 """ 1411 if type > 255: 1412 raise TraCIException("vehicle.highlight(): maximal value for type is 255") 1413 if alphaMax > 255: 1414 raise TraCIException("vehicle.highlight(): maximal value for alphaMax is 255") 1415 if alphaMax <= 0 and duration > 0: 1416 raise TraCIException("vehicle.highlight(): duration>0 requires alphaMax>0") 1417 if alphaMax > 0 and duration <= 0: 1418 raise TraCIException("vehicle.highlight(): alphaMax>0 requires duration>0") 1419 1420 if alphaMax > 0: 1421 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcdBdB", 5, color, size, alphaMax, duration, type) 1422 else: 1423 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcd", 2, color, size) 1424 1425 @alias_param("laneChangeMode", "lcm") 1426 def setLaneChangeMode(self, vehID, laneChangeMode): 1427 """setLaneChangeMode(string, integer) -> None 1428 1429 Sets the vehicle's lane change mode as a bitset. 1430 """ 1431 self._setCmd(tc.VAR_LANECHANGE_MODE, vehID, "i", laneChangeMode) 1432 1433 @alias_param("speedMode", "sm") 1434 def setSpeedMode(self, vehID, speedMode): 1435 """setSpeedMode(string, integer) -> None 1436 1437 Sets the vehicle's speed mode as a bitset. 1438 """ 1439 self._setCmd(tc.VAR_SPEEDSETMODE, vehID, "i", speedMode) 1440 1441 def addLegacy(self, vehID, routeID, depart=tc.DEPARTFLAG_NOW, pos=0, speed=0, 1442 lane=tc.DEPARTFLAG_LANE_FIRST_ALLOWED, typeID="DEFAULT_VEHTYPE"): 1443 """ 1444 Add a new vehicle (old style) 1445 """ 1446 if depart == tc.DEPARTFLAG_NOW: 1447 depart = "now" 1448 elif depart == tc.DEPARTFLAG_TRIGGERED: 1449 depart = "triggered" 1450 else: 1451 depart = str(depart) 1452 if pos < 0: 1453 print("Invalid departure position.") 1454 return 1455 if lane == tc.DEPARTFLAG_LANE_FIRST_ALLOWED: 1456 lane = "first" 1457 elif lane == tc.DEPARTFLAG_LANE_FREE: 1458 lane = "free" 1459 else: 1460 lane = str(lane) 1461 self.addFull(vehID, routeID, typeID, depart, lane, str(pos), str(speed)) 1462 1463 def add(self, vehID, routeID, typeID="DEFAULT_VEHTYPE", depart="now", 1464 departLane="first", departPos="base", departSpeed="0", 1465 arrivalLane="current", arrivalPos="max", arrivalSpeed="current", 1466 fromTaz="", toTaz="", line="", personCapacity=0, personNumber=0, 1467 departPosLat="", arrivalPosLat="", speedFactor=-1, insertionChecks=""): 1468 """ 1469 Add a new vehicle (new style with all possible parameters) 1470 If routeID is "", the vehicle will be inserted on a random network edge 1471 if route consists of two disconnected edges, the vehicle will be treated 1472 like a <trip> and use the fastest route between the two edges. 1473 """ 1474 if depart is None: 1475 # legacy compatibility 1476 depart = str(self._connection.simulation.getTime()) 1477 withOptional = (departPosLat != "" or arrivalPosLat != "" 1478 or speedFactor != -1 or insertionChecks != "") 1479 if withOptional: 1480 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii" + "ss" + "d" + "s", 18, 1481 routeID, typeID, depart, departLane, departPos, departSpeed, 1482 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, 1483 personCapacity, personNumber, departPosLat, arrivalPosLat, 1484 speedFactor, insertionChecks) 1485 else: 1486 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii", 14, 1487 routeID, typeID, depart, departLane, departPos, departSpeed, 1488 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, 1489 personCapacity, personNumber) 1490 1491 addFull = add 1492 1493 def dispatchTaxi(self, vehID, reservations): 1494 """dispatchTaxi(string, list(string)) -> None 1495 dispatches the taxi with the given id to service the given reservations. 1496 If only a single reservation is given, this implies pickup and drop-off 1497 If multiple reservations are given, each reservation id must occur twice 1498 (once for pickup and once for drop-off) and the list encodes ride 1499 sharing of passengers (in pickup and drop-off order) 1500 """ 1501 if isinstance(reservations, str): 1502 reservations = [reservations] 1503 self._setCmd(tc.CMD_TAXI_DISPATCH, vehID, "l", reservations) 1504 1505 def remove(self, vehID, reason=tc.REMOVE_VAPORIZED): 1506 '''Remove vehicle with the given ID for the give reason. 1507 Reasons are defined in module constants and start with REMOVE_''' 1508 self._setCmd(tc.REMOVE, vehID, "b", reason) 1509 1510 @alias_param("laneIndex", "lane") 1511 def moveToXY(self, vehID, edgeID, laneIndex, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 1512 '''Place vehicle at the given x,y coordinates and force its angle to 1513 the given value (for drawing). 1514 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 1515 natural angle of the edge on which it is driving. 1516 If keepRoute is set to 1, the closest position 1517 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 1518 any edge in the network but its route then only consists of that edge. 1519 If keepRoute is set to 2 the vehicle has all the freedom of keepRoute=0 1520 but in addition to that may even move outside the road network. 1521 edgeID and lane are optional placement hints to resolve ambiguities. 1522 The command fails if no suitable target position is found within the 1523 distance given by matchThreshold. 1524 ''' 1525 self._setCmd(tc.MOVE_TO_XY, vehID, "tsidddbd", 7, edgeID, laneIndex, x, y, angle, keepRoute, matchThreshold) 1526 1527 def addSubscriptionFilterLanes(self, lanes, noOpposite=False, downstreamDist=None, upstreamDist=None): 1528 """addSubscriptionFilterLanes(list(integer), bool, double, double) -> None 1529 1530 Adds a lane-filter to the last modified vehicle context subscription (call it just after subscribing). 1531 lanes is a list of relative lane indices (-1 -> right neighboring lane of the ego, 0 -> ego lane, etc.) 1532 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1533 downstreamDist and upstreamDist specify the range of the search for surrounding vehicles along the road net. 1534 """ 1535 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes) 1536 if noOpposite: 1537 self.addSubscriptionFilterNoOpposite() 1538 if downstreamDist is not None: 1539 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1540 if upstreamDist is not None: 1541 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1542 1543 def addSubscriptionFilterNoOpposite(self): 1544 """addSubscriptionFilterNoOpposite() -> None 1545 1546 Omits vehicles on other edges than the ego's for the last modified vehicle context subscription 1547 (call it just after subscribing). 1548 """ 1549 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_NOOPPOSITE) 1550 1551 def addSubscriptionFilterDownstreamDistance(self, dist): 1552 """addSubscriptionFilterDownstreamDist(float) -> None 1553 1554 Sets the downstream distance along the network for vehicles to be returned by the last modified 1555 vehicle context subscription (call it just after subscribing). 1556 """ 1557 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_DOWNSTREAM_DIST, dist) 1558 1559 def addSubscriptionFilterUpstreamDistance(self, dist): 1560 """addSubscriptionFilterUpstreamDist(float) -> None 1561 1562 Sets the upstream distance along the network for vehicles to be returned by the last modified 1563 vehicle context subscription (call it just after subscribing). 1564 """ 1565 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_UPSTREAM_DIST, dist) 1566 1567 def addSubscriptionFilterCFManeuver(self, downstreamDist=None, upstreamDist=None): 1568 """addSubscriptionFilterCFManeuver() -> None 1569 1570 Restricts vehicles returned by the last modified vehicle context subscription to leader and follower of the ego. 1571 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1572 """ 1573 self.addSubscriptionFilterLeadFollow([0]) 1574 if downstreamDist is not None: 1575 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1576 if upstreamDist is not None: 1577 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1578 1579 def addSubscriptionFilterLCManeuver(self, direction=None, noOpposite=False, downstreamDist=None, upstreamDist=None): 1580 """addSubscriptionFilterLCManeuver(int) -> None 1581 1582 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1583 and follower of the ego. 1584 direction - lane change direction (in {-1=right, 1=left}) 1585 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1586 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1587 Combine with: distance filters; vClass/vType filter. 1588 """ 1589 if direction is None: 1590 # Using default: both directions 1591 lanes = [-1, 0, 1] 1592 elif not (direction == -1 or direction == 1): 1593 warnings.warn("Ignoring lane change subscription filter " + 1594 "with non-neighboring lane offset direction=%s." % direction) 1595 return 1596 else: 1597 lanes = [0, direction] 1598 self.addSubscriptionFilterLeadFollow(lanes) 1599 if noOpposite: 1600 self.addSubscriptionFilterNoOpposite() 1601 if downstreamDist is not None: 1602 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1603 if upstreamDist is not None: 1604 self.addSubscriptionFilterUpstreamDistance(upstreamDist) 1605 1606 def addSubscriptionFilterLeadFollow(self, lanes): 1607 """addSubscriptionFilterLCManeuver(lanes) -> None 1608 1609 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1610 and follower of the ego. 1611 Combine with: lanes-filter to restrict to one direction; distance filters; vClass/vType filter. 1612 """ 1613 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LEAD_FOLLOW) 1614 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes) 1615 1616 def addSubscriptionFilterTurn(self, downstreamDist=None, foeDistToJunction=None): 1617 """addSubscriptionFilterTurn(double, double) -> None 1618 1619 Restricts vehicles returned by the last modified vehicle context subscription to foes on upcoming junctions 1620 """ 1621 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_TURN, foeDistToJunction) 1622 if downstreamDist is not None: 1623 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1624 1625 def addSubscriptionFilterVClass(self, vClasses): 1626 """addSubscriptionFilterVClass(list(String)) -> None 1627 1628 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given classes 1629 """ 1630 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VCLASS, vClasses) 1631 1632 def addSubscriptionFilterVType(self, vTypes): 1633 """addSubscriptionFilterVType(list(String)) -> None 1634 1635 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given types 1636 """ 1637 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VTYPE, vTypes) 1638 1639 def addSubscriptionFilterFieldOfVision(self, openingAngle): 1640 """addSubscriptionFilterFieldOfVision(float) -> None 1641 1642 Restricts vehicles returned by the last modified vehicle context subscription 1643 to vehicles within field of vision with given opening angle 1644 """ 1645 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_FIELD_OF_VISION, openingAngle) 1646 1647 def addSubscriptionFilterLateralDistance(self, lateralDist, downstreamDist=None, upstreamDist=None): 1648 """addSubscriptionFilterLateralDist(double, double, double) -> None 1649 1650 Adds a lateral distance filter to the last modified vehicle context subscription 1651 (call it just after subscribing). 1652 downstreamDist and upstreamDist specify the longitudinal range of the search 1653 for surrounding vehicles along the ego vehicle's route. 1654 """ 1655 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LATERAL_DIST, lateralDist) 1656 if downstreamDist is not None: 1657 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1658 if upstreamDist is not None: 1659 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
This class contains all functions which are common to the vehicletype, vehicle and person domain
278 def getSpeed(self, vehID): 279 """getSpeed(string) -> double 280 281 Returns the (longitudinal) speed in m/s of the named vehicle within the last step. 282 """ 283 return self._getUniversal(tc.VAR_SPEED, vehID)
getSpeed(string) -> double
Returns the (longitudinal) speed in m/s of the named vehicle within the last step.
285 def getLateralSpeed(self, vehID): 286 """getLateralSpeed(string) -> double 287 288 Returns the lateral speed in m/s of the named vehicle within the last step. 289 """ 290 return self._getUniversal(tc.VAR_SPEED_LAT, vehID)
getLateralSpeed(string) -> double
Returns the lateral speed in m/s of the named vehicle within the last step.
292 def getAcceleration(self, vehID): 293 """getAcceleration(string) -> double 294 295 Returns the acceleration in m/s^2 of the named vehicle within the last step. 296 """ 297 return self._getUniversal(tc.VAR_ACCELERATION, vehID)
getAcceleration(string) -> double
Returns the acceleration in m/s^2 of the named vehicle within the last step.
299 def getSpeedWithoutTraCI(self, vehID): 300 """getSpeedWithoutTraCI(string) -> double 301 Returns the speed that the vehicle would drive if no speed-influencing 302 command such as setSpeed or slowDown was given. 303 """ 304 return self._getUniversal(tc.VAR_SPEED_WITHOUT_TRACI, vehID)
getSpeedWithoutTraCI(string) -> double Returns the speed that the vehicle would drive if no speed-influencing command such as setSpeed or slowDown was given.
306 def getPosition(self, vehID): 307 """getPosition(string) -> (double, double) 308 309 Returns the position of the named vehicle within the last step [m,m]. 310 """ 311 return self._getUniversal(tc.VAR_POSITION, vehID)
getPosition(string) -> (double, double)
Returns the position of the named vehicle within the last step [m,m].
313 def getPosition3D(self, vehID): 314 """getPosition3D(string) -> (double, double, double) 315 316 Returns the position of the named vehicle within the last step [m,m,m]. 317 """ 318 return self._getUniversal(tc.VAR_POSITION3D, vehID)
getPosition3D(string) -> (double, double, double)
Returns the position of the named vehicle within the last step [m,m,m].
320 def getAngle(self, vehID): 321 """getAngle(string) -> double 322 323 Returns the angle in degrees of the named vehicle within the last step. 324 """ 325 return self._getUniversal(tc.VAR_ANGLE, vehID)
getAngle(string) -> double
Returns the angle in degrees of the named vehicle within the last step.
327 def getRoadID(self, vehID): 328 """getRoadID(string) -> string 329 330 Returns the id of the edge the named vehicle was at within the last step. 331 """ 332 return self._getUniversal(tc.VAR_ROAD_ID, vehID)
getRoadID(string) -> string
Returns the id of the edge the named vehicle was at within the last step.
334 def getDeparture(self, vehID): 335 """getDeparture(string) -> double 336 337 Returns the actual departure time in seconds 338 """ 339 return self._getUniversal(tc.VAR_DEPARTURE, vehID)
getDeparture(string) -> double
Returns the actual departure time in seconds
341 def getDepartDelay(self, vehID): 342 """getDepartDelay(string) -> double 343 344 Returns the delay between intended and actual departure in seconds 345 """ 346 return self._getUniversal(tc.VAR_DEPART_DELAY, vehID)
getDepartDelay(string) -> double
Returns the delay between intended and actual departure in seconds
348 def getLaneID(self, vehID): 349 """getLaneID(string) -> string 350 351 Returns the id of the lane the named vehicle was at within the last step. 352 """ 353 return self._getUniversal(tc.VAR_LANE_ID, vehID)
getLaneID(string) -> string
Returns the id of the lane the named vehicle was at within the last step.
355 def getShadowLaneID(self, vehID): 356 """getShadowLaneID(string) -> string 357 358 Returns the id of the shadow lane if the vehicle is currently changing lanes. 359 """ 360 return self._getUniversal(tc.VAR_SHADOW_LANE_ID, vehID)
getShadowLaneID(string) -> string
Returns the id of the shadow lane if the vehicle is currently changing lanes.
362 def getLaneIndex(self, vehID): 363 """getLaneIndex(string) -> integer 364 365 Returns the index of the lane the named vehicle was at within the last step. 366 """ 367 return self._getUniversal(tc.VAR_LANE_INDEX, vehID)
getLaneIndex(string) -> integer
Returns the index of the lane the named vehicle was at within the last step.
369 def getSegmentID(self, vehID): 370 """getSegmentID(string) -> string 371 372 Returns the id of the segment the named vehicle was at within the last step (mesosim). 373 """ 374 return self._getUniversal(tc.VAR_SEGMENT_ID, vehID)
getSegmentID(string) -> string
Returns the id of the segment the named vehicle was at within the last step (mesosim).
376 def getSegmentIndex(self, vehID): 377 """getSegmentIndex(string) -> integer 378 379 Returns the index of the segment the named vehicle was at within the last step (mesosim). 380 """ 381 return self._getUniversal(tc.VAR_SEGMENT_INDEX, vehID)
getSegmentIndex(string) -> integer
Returns the index of the segment the named vehicle was at within the last step (mesosim).
383 def getTypeID(self, vehID): 384 """getTypeID(string) -> string 385 386 Returns the id of the type of the named vehicle. 387 """ 388 return self._getUniversal(tc.VAR_TYPE, vehID)
getTypeID(string) -> string
Returns the id of the type of the named vehicle.
390 def getRouteID(self, vehID): 391 """getRouteID(string) -> string 392 393 Returns the id of the route of the named vehicle. 394 """ 395 return self._getUniversal(tc.VAR_ROUTE_ID, vehID)
getRouteID(string) -> string
Returns the id of the route of the named vehicle.
397 def getRouteIndex(self, vehID): 398 """getRouteIndex(string) -> int 399 400 Returns the index of the current edge within the vehicles route or -1 if the 401 vehicle has not yet departed 402 """ 403 return self._getUniversal(tc.VAR_ROUTE_INDEX, vehID)
getRouteIndex(string) -> int
Returns the index of the current edge within the vehicles route or -1 if the vehicle has not yet departed
405 def getRoute(self, vehID): 406 """getRoute(string) -> tuple(string) 407 408 Returns the ids of the edges the vehicle's route is made of. 409 """ 410 return self._getUniversal(tc.VAR_EDGES, vehID)
getRoute(string) -> tuple(string)
Returns the ids of the edges the vehicle's route is made of.
412 def getLanePosition(self, vehID): 413 """getLanePosition(string) -> double 414 415 The position of the vehicle along the lane measured in m. 416 """ 417 return self._getUniversal(tc.VAR_LANEPOSITION, vehID)
getLanePosition(string) -> double
The position of the vehicle along the lane measured in m.
419 def getArrivalPos(self, vehID): 420 """getArrivalPos(string) -> double 421 422 The position at which the vehicle will arrive on the last edge of its route in m. 423 """ 424 return self._getUniversal(tc.VAR_ARRIVALPOS, vehID)
getArrivalPos(string) -> double
The position at which the vehicle will arrive on the last edge of its route in m.
426 def getCO2Emission(self, vehID): 427 """getCO2Emission(string) -> double 428 429 Returns the CO2 emission in mg/s for the last time step. 430 Multiply by the step length to get the value for one step. 431 """ 432 return self._getUniversal(tc.VAR_CO2EMISSION, vehID)
getCO2Emission(string) -> double
Returns the CO2 emission in mg/s for the last time step. Multiply by the step length to get the value for one step.
434 def getCOEmission(self, vehID): 435 """getCOEmission(string) -> double 436 437 Returns the CO emission in mg/s for the last time step. 438 Multiply by the step length to get the value for one step. 439 """ 440 return self._getUniversal(tc.VAR_COEMISSION, vehID)
getCOEmission(string) -> double
Returns the CO emission in mg/s for the last time step. Multiply by the step length to get the value for one step.
442 def getHCEmission(self, vehID): 443 """getHCEmission(string) -> double 444 445 Returns the HC emission in mg/s for the last time step. 446 Multiply by the step length to get the value for one step. 447 """ 448 return self._getUniversal(tc.VAR_HCEMISSION, vehID)
getHCEmission(string) -> double
Returns the HC emission in mg/s for the last time step. Multiply by the step length to get the value for one step.
450 def getPMxEmission(self, vehID): 451 """getPMxEmission(string) -> double 452 453 Returns the particular matter emission in mg/s for the last time step. 454 Multiply by the step length to get the value for one step. 455 """ 456 return self._getUniversal(tc.VAR_PMXEMISSION, vehID)
getPMxEmission(string) -> double
Returns the particular matter emission in mg/s for the last time step. Multiply by the step length to get the value for one step.
458 def getNOxEmission(self, vehID): 459 """getNOxEmission(string) -> double 460 461 Returns the NOx emission in mg/s for the last time step. 462 Multiply by the step length to get the value for one step. 463 """ 464 return self._getUniversal(tc.VAR_NOXEMISSION, vehID)
getNOxEmission(string) -> double
Returns the NOx emission in mg/s for the last time step. Multiply by the step length to get the value for one step.
466 def getFuelConsumption(self, vehID): 467 """getFuelConsumption(string) -> double 468 469 Returns the fuel consumption in mg/s for the last time step. 470 Multiply by the step length to get the value for one step. 471 """ 472 return self._getUniversal(tc.VAR_FUELCONSUMPTION, vehID)
getFuelConsumption(string) -> double
Returns the fuel consumption in mg/s for the last time step. Multiply by the step length to get the value for one step.
474 def getNoiseEmission(self, vehID): 475 """getNoiseEmission(string) -> double 476 477 Returns the noise emission in db for the last time step. 478 """ 479 return self._getUniversal(tc.VAR_NOISEEMISSION, vehID)
getNoiseEmission(string) -> double
Returns the noise emission in db for the last time step.
481 def getElectricityConsumption(self, vehID): 482 """getElectricityConsumption(string) -> double 483 484 Returns the electricity consumption in Wh/s for the last time step. 485 Multiply by the step length to get the value for one step. 486 """ 487 return self._getUniversal(tc.VAR_ELECTRICITYCONSUMPTION, vehID)
getElectricityConsumption(string) -> double
Returns the electricity consumption in Wh/s for the last time step. Multiply by the step length to get the value for one step.
489 def getPersonNumber(self, vehID): 490 """getPersonNumber(string) -> integer 491 Returns the total number of persons which includes those defined 492 using attribute 'personNumber' as well as <person>-objects who are riding in 493 this vehicle. 494 """ 495 return self._getUniversal(tc.VAR_PERSON_NUMBER, vehID)
getPersonNumber(string) -> integer
Returns the total number of persons which includes those defined
using attribute 'personNumber' as well as
497 def getPersonIDList(self, vehID): 498 """getPersonIDList(string) -> tuple(string) 499 Returns the tuple of persons who are riding in this vehicle. 500 """ 501 return self._getUniversal(tc.LAST_STEP_PERSON_ID_LIST, vehID)
getPersonIDList(string) -> tuple(string) Returns the tuple of persons who are riding in this vehicle.
503 def getAdaptedTraveltime(self, vehID, time, edgeID): 504 """getAdaptedTraveltime(string, double, string) -> double 505 506 Returns the information about the travel time of edge "edgeID" valid 507 for the given time from the vehicle's internal edge weights 508 container (see setAdaptedTraveltime). 509 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 510 """ 511 return self._getUniversal(tc.VAR_EDGE_TRAVELTIME, vehID, "tds", 2, time, edgeID)
getAdaptedTraveltime(string, double, string) -> double
Returns the information about the travel time of edge "edgeID" valid for the given time from the vehicle's internal edge weights container (see setAdaptedTraveltime). If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned.
513 def getEffort(self, vehID, time, edgeID): 514 """getEffort(string, double, string) -> double 515 516 Returns the information about the effort needed for edge "edgeID" valid 517 for the given time from the vehicle's internal effort 518 container (see setEffort). 519 If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned. 520 """ 521 return self._getUniversal(tc.VAR_EDGE_EFFORT, vehID, "tds", 2, time, edgeID)
getEffort(string, double, string) -> double
Returns the information about the effort needed for edge "edgeID" valid for the given time from the vehicle's internal effort container (see setEffort). If there is no individual travel time set, INVALID_DOUBLE_VALUE is returned.
523 def isRouteValid(self, vehID): 524 """isRouteValid(string) -> bool 525 Returns whether the current vehicle route is connected for the vehicle 526 class of the given vehicle. 527 """ 528 return self._getUniversal(tc.VAR_ROUTE_VALID, vehID)
isRouteValid(string) -> bool Returns whether the current vehicle route is connected for the vehicle class of the given vehicle.
530 def getSignals(self, vehID): 531 """getSignals(string) -> integer 532 533 Returns an integer encoding the state of a vehicle's signals. 534 """ 535 return self._getUniversal(tc.VAR_SIGNALS, vehID)
getSignals(string) -> integer
Returns an integer encoding the state of a vehicle's signals.
537 def getLateralLanePosition(self, vehID): 538 """getLateralLanePosition(string) -> double 539 540 Returns the lateral position of the vehicle on its current lane measured in m. 541 """ 542 return self._getUniversal(tc.VAR_LANEPOSITION_LAT, vehID)
getLateralLanePosition(string) -> double
Returns the lateral position of the vehicle on its current lane measured in m.
544 def getAllowedSpeed(self, vehID): 545 """getAllowedSpeed(string) -> double 546 547 Returns the maximum allowed speed on the current lane regarding speed factor in m/s for this vehicle. 548 """ 549 return self._getUniversal(tc.VAR_ALLOWED_SPEED, vehID)
getAllowedSpeed(string) -> double
Returns the maximum allowed speed on the current lane regarding speed factor in m/s for this vehicle.
551 def getWaitingTime(self, vehID): 552 """getWaitingTime(string) -> double 553 The waiting time of a vehicle is defined as the time (in seconds) spent with a 554 speed below 0.1m/s since the last time it was faster than 0.1m/s. 555 (basically, the waiting time of a vehicle is reset to 0 every time it moves). 556 A vehicle that is stopping intentionally with a <stop> does not accumulate waiting time. 557 """ 558 return self._getUniversal(tc.VAR_WAITING_TIME, vehID)
getWaitingTime(string) -> double
The waiting time of a vehicle is defined as the time (in seconds) spent with a
speed below 0.1m/s since the last time it was faster than 0.1m/s.
(basically, the waiting time of a vehicle is reset to 0 every time it moves).
A vehicle that is stopping intentionally with a
560 def getAccumulatedWaitingTime(self, vehID): 561 """getAccumulatedWaitingTime(string) -> double 562 The accumulated waiting time of a vehicle collects the vehicle's waiting time 563 over a certain time interval (interval length is set per option '--waiting-time-memory') 564 """ 565 return self._getUniversal(tc.VAR_ACCUMULATED_WAITING_TIME, vehID)
getAccumulatedWaitingTime(string) -> double The accumulated waiting time of a vehicle collects the vehicle's waiting time over a certain time interval (interval length is set per option '--waiting-time-memory')
567 def getLaneChangeMode(self, vehID): 568 """getLaneChangeMode(string) -> integer 569 570 Gets the vehicle's lane change mode as a bitset. 571 """ 572 return self._getUniversal(tc.VAR_LANECHANGE_MODE, vehID)
getLaneChangeMode(string) -> integer
Gets the vehicle's lane change mode as a bitset.
574 def getSpeedMode(self, vehID): 575 """getSpeedMode(string) -> int 576 The speed mode of a vehicle 577 """ 578 return self._getUniversal(tc.VAR_SPEEDSETMODE, vehID)
getSpeedMode(string) -> int The speed mode of a vehicle
580 def getSlope(self, vehID): 581 """getSlope(string) -> double 582 The slope at the current position of the vehicle in degrees 583 """ 584 return self._getUniversal(tc.VAR_SLOPE, vehID)
getSlope(string) -> double The slope at the current position of the vehicle in degrees
586 def getLine(self, vehID): 587 """getLine(string) -> string 588 589 Returns the line information of this vehicle. 590 """ 591 return self._getUniversal(tc.VAR_LINE, vehID)
getLine(string) -> string
Returns the line information of this vehicle.
593 def getVia(self, vehID): 594 """getVia(string) -> tuple(string) 595 596 Returns the ids of via edges for this vehicle 597 """ 598 return self._getUniversal(tc.VAR_VIA, vehID)
getVia(string) -> tuple(string)
Returns the ids of via edges for this vehicle
600 def getLastActionTime(self, vehID): 601 """getLastActionTime(string) -> double 602 603 Returns the time in s of last action point for this vehicle. 604 """ 605 return self._getUniversal(tc.VAR_LASTACTIONTIME, vehID)
getLastActionTime(string) -> double
Returns the time in s of last action point for this vehicle.
607 def getBestLanes(self, vehID): 608 """getBestLanes(string) -> tuple(data) 609 where data is a tuple of (laneID, length, occupation, offset, allowsContinuation, tuple(nextLanes)) 610 611 For each lane of the current edge a data tuple is returned where the 612 entries have the following meaning: 613 - laneID: the id of that lane on the current edge 614 - the length that can be driven without lane change (measured from the start of that lane) 615 - the occupation on the future lanes (brutto vehicle lengths) 616 - the offset of that lane from the lane that would be strategically 617 preferred (this is the lane that requires the least future lane 618 changes or a lane that needs to be used for stopping) 619 - whether that lane allows continuing the route (for at least one more edge) 620 - the sequence of lanes that would be driven starting at laneID if no 621 lane change were to take place 622 """ 623 return self._getUniversal(tc.VAR_BEST_LANES, vehID)
getBestLanes(string) -> tuple(data) where data is a tuple of (laneID, length, occupation, offset, allowsContinuation, tuple(nextLanes))
For each lane of the current edge a data tuple is returned where the entries have the following meaning:
- laneID: the id of that lane on the current edge
- the length that can be driven without lane change (measured from the start of that lane)
- the occupation on the future lanes (brutto vehicle lengths)
- the offset of that lane from the lane that would be strategically preferred (this is the lane that requires the least future lane changes or a lane that needs to be used for stopping)
- whether that lane allows continuing the route (for at least one more edge)
- the sequence of lanes that would be driven starting at laneID if no lane change were to take place
625 def getLeader(self, vehID, dist=100.): 626 """getLeader(string, double) -> (string, double) 627 628 Return the leading vehicle id together with the distance. The distance 629 is measured from the front + minGap to the back of the leader, so it does not include the 630 minGap of the vehicle. 631 The dist parameter defines the minimum lookahead, 0 calculates a lookahead from the brake gap. 632 Note that the returned leader may be further away than the given dist and that the vehicle 633 will only look on its current best lanes and not look beyond the end of its final route edge. 634 635 In the case where no leader is found, the function returns 'None'. 636 This special case is deprecated. The future behavior is to return the 637 pair ("", -1) when no leader is found. 638 The function 'traci.setLegacyGetLeader(bool) can be used to switch 639 between both behaviors. 640 """ 641 return self._getUniversal(tc.VAR_LEADER, vehID, "d", dist)
getLeader(string, double) -> (string, double)
Return the leading vehicle id together with the distance. The distance is measured from the front + minGap to the back of the leader, so it does not include the minGap of the vehicle. The dist parameter defines the minimum lookahead, 0 calculates a lookahead from the brake gap. Note that the returned leader may be further away than the given dist and that the vehicle will only look on its current best lanes and not look beyond the end of its final route edge.
In the case where no leader is found, the function returns 'None'. This special case is deprecated. The future behavior is to return the pair ("", -1) when no leader is found. The function 'traci.setLegacyGetLeader(bool) can be used to switch between both behaviors.
643 def getFollower(self, vehID, dist=0.): 644 """getFollower(string, double) -> (string, double) 645 646 Return the following vehicle id together with the distance. The distance 647 is measured from the front + minGap of the follower to the back of vehID, so it does not include the 648 minGap of the follower. 649 The dist parameter defines the minimum lookback, 0 calculates the 650 lookback distance from the braking distance at 4.5m/s^2 at 2*roadSpeedLimit. 651 Due to junctions and lane merges, there may be multiple followers. 652 In this case, the "critical" follower is returned. This is the follower 653 where the value of (getSecureGap - gap) is maximal. 654 Note that the returned follower may be further away than the given dist. 655 """ 656 return self._getUniversal(tc.VAR_FOLLOWER, vehID, "d", dist)
getFollower(string, double) -> (string, double)
Return the following vehicle id together with the distance. The distance is measured from the front + minGap of the follower to the back of vehID, so it does not include the minGap of the follower. The dist parameter defines the minimum lookback, 0 calculates the lookback distance from the braking distance at 4.5m/s^2 at 2*roadSpeedLimit. Due to junctions and lane merges, there may be multiple followers. In this case, the "critical" follower is returned. This is the follower where the value of (getSecureGap - gap) is maximal. Note that the returned follower may be further away than the given dist.
658 def getRightFollowers(self, vehID, blockingOnly=False): 659 """ getRightFollowers(string, bool) -> tuple(tuple(string, double)) 660 Convenience method, see getNeighbors() 661 """ 662 if blockingOnly: 663 mode = 5 664 else: 665 mode = 1 666 return self.getNeighbors(vehID, mode)
getRightFollowers(string, bool) -> tuple(tuple(string, double)) Convenience method, see getNeighbors()
668 def getRightLeaders(self, vehID, blockingOnly=False): 669 """ getRightLeaders(string, bool) -> tuple(tuple(string, double)) 670 Convenience method, see getNeighbors() 671 """ 672 if blockingOnly: 673 mode = 7 674 else: 675 mode = 3 676 return self.getNeighbors(vehID, mode)
getRightLeaders(string, bool) -> tuple(tuple(string, double)) Convenience method, see getNeighbors()
678 def getLeftFollowers(self, vehID, blockingOnly=False): 679 """ getLeftFollowers(string, bool) -> tuple(tuple(string, double)) 680 Convenience method, see getNeighbors() 681 """ 682 if blockingOnly: 683 mode = 4 684 else: 685 mode = 0 686 return self.getNeighbors(vehID, mode)
getLeftFollowers(string, bool) -> tuple(tuple(string, double)) Convenience method, see getNeighbors()
688 def getLeftLeaders(self, vehID, blockingOnly=False): 689 """ getLeftLeaders(string, bool) -> tuple(tuple(string, double)) 690 Convenience method, see getNeighbors() 691 """ 692 if blockingOnly: 693 mode = 6 694 else: 695 mode = 2 696 return self.getNeighbors(vehID, mode)
getLeftLeaders(string, bool) -> tuple(tuple(string, double)) Convenience method, see getNeighbors()
698 def getNeighbors(self, vehID, mode): 699 """ getNeighbors(string, byte) -> tuple(tuple(string, double)) 700 701 The parameter mode is a bitset (UBYTE), specifying the following: 702 bit 1: query lateral direction (left:0, right:1) 703 bit 2: query longitudinal direction (followers:0, leaders:1) 704 bit 3: blocking (return all:0, return only blockers:1) 705 706 The returned tuple contains pairs (ID, dist) for all lane change relevant neighboring leaders, resp. followers, 707 along with their longitudinal distance to the ego vehicle (egoFront - egoMinGap to leaderBack, resp. 708 followerFront - followerMinGap to egoBack. The value can be negative for overlapping neighs). 709 For the non-sublane case, the lists will contain at most one entry. 710 711 Note: The exact set of blockers in case blocking==1 is not determined for the sublane model, 712 but either all neighboring vehicles are returned (in case LCA_BLOCKED) or 713 none is returned (in case !LCA_BLOCKED). 714 """ 715 return self._getUniversal(tc.VAR_NEIGHBORS, vehID, "B", mode)
getNeighbors(string, byte) -> tuple(tuple(string, double))
The parameter mode is a bitset (UBYTE), specifying the following: bit 1: query lateral direction (left:0, right:1) bit 2: query longitudinal direction (followers:0, leaders:1) bit 3: blocking (return all:0, return only blockers:1)
The returned tuple contains pairs (ID, dist) for all lane change relevant neighboring leaders, resp. followers, along with their longitudinal distance to the ego vehicle (egoFront - egoMinGap to leaderBack, resp. followerFront - followerMinGap to egoBack. The value can be negative for overlapping neighs). For the non-sublane case, the lists will contain at most one entry.
Note: The exact set of blockers in case blocking==1 is not determined for the sublane model, but either all neighboring vehicles are returned (in case LCA_BLOCKED) or none is returned (in case !LCA_BLOCKED).
717 def getFollowSpeed(self, vehID, speed, gap, leaderSpeed, leaderMaxDecel, leaderID=""): 718 """getFollowSpeed(string, double, double, double, double, string) -> double 719 Return the follow speed computed by the carFollowModel of vehID 720 """ 721 return self._getUniversal(tc.VAR_FOLLOW_SPEED, vehID, "tdddds", 5, 722 speed, gap, leaderSpeed, leaderMaxDecel, leaderID)
getFollowSpeed(string, double, double, double, double, string) -> double Return the follow speed computed by the carFollowModel of vehID
724 def getSecureGap(self, vehID, speed, leaderSpeed, leaderMaxDecel, leaderID=""): 725 """getSecureGap(string, double, double, double, string) -> double 726 Return the secure gap computed by the carFollowModel of vehID 727 """ 728 return self._getUniversal(tc.VAR_SECURE_GAP, vehID, "tddds", 4, 729 speed, leaderSpeed, leaderMaxDecel, leaderID)
getSecureGap(string, double, double, double, string) -> double Return the secure gap computed by the carFollowModel of vehID
731 def getStopSpeed(self, vehID, speed, gap): 732 """getStopSpeed(string, double, double) -> double 733 Return the speed for stopping at gap computed by the carFollowModel of vehID 734 """ 735 return self._getUniversal(tc.VAR_STOP_SPEED, vehID, "tdd", 2, speed, gap)
getStopSpeed(string, double, double) -> double Return the speed for stopping at gap computed by the carFollowModel of vehID
737 def getStopDelay(self, vehID): 738 """getStopDelay(string) -> double 739 Returns the expected depart delay at the next stop (if that stop defines the 740 until-attribute) in seconds. Returns -1 if the next stop is not applicable 741 """ 742 return self._getUniversal(tc.VAR_STOP_DELAY, vehID)
getStopDelay(string) -> double Returns the expected depart delay at the next stop (if that stop defines the until-attribute) in seconds. Returns -1 if the next stop is not applicable
744 def getStopArrivalDelay(self, vehID): 745 """getStopArrivalDelay(string) -> double 746 Returns the expected arrival delay at the next stop (if that stop defines the 747 arrival-attribute) in seconds. The returned value may be negative to 748 indicate early arrival. Returns INVALID_DOUBLE if the next stop is not applicable 749 """ 750 return self._getUniversal(tc.VAR_STOP_ARRIVALDELAY, vehID)
getStopArrivalDelay(string) -> double Returns the expected arrival delay at the next stop (if that stop defines the arrival-attribute) in seconds. The returned value may be negative to indicate early arrival. Returns INVALID_DOUBLE if the next stop is not applicable
752 def getTimeLoss(self, vehID): 753 """getTimeLoss(string) -> double 754 Returns the time loss since departure 755 """ 756 return self._getUniversal(tc.VAR_TIMELOSS, vehID)
getTimeLoss(string) -> double Returns the time loss since departure
758 def getNextTLS(self, vehID): 759 """getNextTLS(string) -> tuple(tuple(string, int, double, string)) 760 761 Return tuple of upcoming traffic lights [(tlsID, tlsIndex, distance, state), ...] 762 """ 763 return self._getUniversal(tc.VAR_NEXT_TLS, vehID)
getNextTLS(string) -> tuple(tuple(string, int, double, string))
Return tuple of upcoming traffic lights [(tlsID, tlsIndex, distance, state), ...]
765 @alias_param("dist", "distance") 766 def getJunctionFoes(self, vehID, dist=0.): 767 """getJunctionFoes(string, double) -> complex 768 769 Return tuple of junction foes [(foeId, egoDist, foeDist, egoExitDist, foeExitDist, 770 egoLane, foeLane, egoResponse, foeResponse), ...] within the given distance to the given vehicle. 771 """ 772 return self._getUniversal(tc.VAR_FOES, vehID, "d", dist)
getJunctionFoes(string, double) -> complex
Return tuple of junction foes [(foeId, egoDist, foeDist, egoExitDist, foeExitDist, egoLane, foeLane, egoResponse, foeResponse), ...] within the given distance to the given vehicle.
774 @deprecated() 775 def getNextStops(self, vehID): 776 """getNextStops(string) -> tuple(tuple(string, double, string, int, double, double)) 777 778 Return tuple of upcoming stops ((lane, endPos, stoppingPlaceID, stopFlags, duration, until), ...) 779 where integer stopFlag is defined as: 780 1 * stopped + 781 2 * parking + 782 4 * personTriggered + 783 8 * containerTriggered + 784 16 * isBusStop + 785 32 * isContainerStop + 786 64 * chargingStation + 787 128 * parkingarea 788 with each of these flags defined as 0 or 1. 789 """ 790 return self._getUniversal(tc.VAR_NEXT_STOPS, vehID)
getNextStops(string) -> tuple(tuple(string, double, string, int, double, double))
Return tuple of upcoming stops ((lane, endPos, stoppingPlaceID, stopFlags, duration, until), ...) where integer stopFlag is defined as: 1 * stopped + 2 * parking + 4 * personTriggered + 8 * containerTriggered + 16 * isBusStop + 32 * isContainerStop + 64 * chargingStation + 128 * parkingarea with each of these flags defined as 0 or 1.
792 def getNextLinks(self, vehID): 793 """getNextLinks(string) -> tuple(tuple(string, string, bool, bool, bool, string, string, double)) 794 795 Return tuple of upcoming links along the route ((lane, via, priority, opened, foe, 796 state, direction, length), ...) 797 """ 798 return self._getUniversal(tc.VAR_NEXT_LINKS, vehID)
getNextLinks(string) -> tuple(tuple(string, string, bool, bool, bool, string, string, double))
Return tuple of upcoming links along the route ((lane, via, priority, opened, foe, state, direction, length), ...)
800 def getStops(self, vehID, limit=0): 801 """getStops(string, int) -> tuple(StopData) 802 803 Return a tuple of StopData object. The flags are the same as for setStop and 804 replaceStop (and different from getNextStops(!) for backward compatibility): 805 1 * parking + 806 2 * personTriggered + 807 4 * containerTriggered + 808 8 * isBusStop + 809 16 * isContainerStop + 810 32 * chargingStation + 811 64 * parkingarea 812 with each of these flags defined as 0 or 1. 813 814 The optional argument limit can be used to limit the returned stops to 815 the next INT number (i.e. limit=1 if only the next stop is required). 816 Setting a negative limit returns up to 'limit' previous stops (or fewer 817 if the vehicle stopped fewer times previously) 818 """ 819 return self._getUniversal(tc.VAR_NEXT_STOPS2, vehID, "i", limit)
getStops(string, int) -> tuple(StopData)
Return a tuple of StopData object. The flags are the same as for setStop and replaceStop (and different from getNextStops(!) for backward compatibility): 1 * parking + 2 * personTriggered + 4 * containerTriggered + 8 * isBusStop + 16 * isContainerStop + 32 * chargingStation + 64 * parkingarea with each of these flags defined as 0 or 1.
The optional argument limit can be used to limit the returned stops to the next INT number (i.e. limit=1 if only the next stop is required). Setting a negative limit returns up to 'limit' previous stops (or fewer if the vehicle stopped fewer times previously)
821 def subscribeLeader(self, vehID, dist=0., begin=0, end=2**31 - 1): 822 """subscribeLeader(string, double, double, double) -> None 823 824 Subscribe for the leading vehicle id together with the distance. 825 The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap. 826 """ 827 self.subscribe(vehID, (tc.VAR_LEADER,), begin, end, {tc.VAR_LEADER: ("d", dist)})
subscribeLeader(string, double, double, double) -> None
Subscribe for the leading vehicle id together with the distance. The dist parameter defines the maximum lookahead, 0 calculates a lookahead from the brake gap.
829 def getDrivingDistance(self, vehID, edgeID, pos, laneIndex=0): 830 """getDrivingDistance(string, string, double, integer) -> double 831 832 For an edge along the remaining route of vehID, return the distance from the current vehicle position 833 to the given edge and position along the vehicles route. 834 Otherwise, return INVALID_DOUBLE_VALUE 835 """ 836 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tru", 2, 837 (edgeID, pos, laneIndex), tc.REQUEST_DRIVINGDIST)
getDrivingDistance(string, string, double, integer) -> double
For an edge along the remaining route of vehID, return the distance from the current vehicle position to the given edge and position along the vehicles route. Otherwise, return INVALID_DOUBLE_VALUE
839 def getDrivingDistance2D(self, vehID, x, y): 840 """getDrivingDistance2D(string, double, double) -> integer 841 842 Return the distance to the given network position along the vehicles route. 843 """ 844 return self._getUniversal(tc.DISTANCE_REQUEST, vehID, "tou", 2, (x, y), tc.REQUEST_DRIVINGDIST)
getDrivingDistance2D(string, double, double) -> integer
Return the distance to the given network position along the vehicles route.
846 def getDistance(self, vehID): 847 """getDistance(string) -> double 848 849 Returns the distance to the starting point like an odometer. 850 """ 851 return self._getUniversal(tc.VAR_DISTANCE, vehID)
getDistance(string) -> double
Returns the distance to the starting point like an odometer.
853 def getReferenceDistance(self, vehID): 854 """getReferenceDistance(string) -> double 855 Returns the distance along the linear reference system 856 in which the current edge takes part (i.e. kilometrage/mile markers) 857 """ 858 return self._getUniversal(tc.VAR_REFERENCE_DISTANCE, vehID)
getReferenceDistance(string) -> double Returns the distance along the linear reference system in which the current edge takes part (i.e. kilometrage/mile markers)
860 def getStopParameter(self, vehID, nextStopIndex, param, customParam=False): 861 """getStopParameter(string, int, string) -> string 862 Gets the value of the given parameter for the stop at the given index 863 Negative indices permit access to past stops. 864 Supported params correspond to all legal stop xml-attributes 865 If customParam is set to True, the user defined stop parameter with the 866 specified param name will be returned instead (or "" if undefined) 867 """ 868 return self._getUniversal(tc.VAR_STOP_PARAMETER, vehID, "tisb", 3, nextStopIndex, param, customParam)
getStopParameter(string, int, string) -> string Gets the value of the given parameter for the stop at the given index Negative indices permit access to past stops. Supported params correspond to all legal stop xml-attributes If customParam is set to True, the user defined stop parameter with the specified param name will be returned instead (or "" if undefined)
870 def getStopState(self, vehID): 871 """getStopState(string) -> integer 872 873 Returns information in regard to stopping: 874 The returned integer is defined as 1 * stopped + 2 * parking 875 + 4 * personTriggered + 8 * containerTriggered + 16 * isBusStop 876 + 32 * isContainerStop 877 with each of these flags defined as 0 or 1 878 """ 879 return self._getUniversal(tc.VAR_STOPSTATE, vehID)
getStopState(string) -> integer
Returns information in regard to stopping: The returned integer is defined as 1 * stopped + 2 * parking
- 4 * personTriggered + 8 * containerTriggered + 16 * isBusStop
- 32 * isContainerStop with each of these flags defined as 0 or 1
881 def isStopped(self, vehID): 882 """isStopped(string) -> bool 883 Return whether the vehicle is stopped 884 """ 885 return (self.getStopState(vehID) & 1) == 1
isStopped(string) -> bool Return whether the vehicle is stopped
887 def isStoppedParking(self, vehID): 888 """isStoppedParking(string) -> bool 889 Return whether the vehicle is parking (implies stopped) 890 """ 891 return (self.getStopState(vehID) & 2) == 2
isStoppedParking(string) -> bool Return whether the vehicle is parking (implies stopped)
893 def isStoppedTriggered(self, vehID): 894 """isStoppedTriggered(string) -> bool 895 Return whether the vehicle is stopped and waiting for a person or container 896 """ 897 return (self.getStopState(vehID) & 12) > 0
isStoppedTriggered(string) -> bool Return whether the vehicle is stopped and waiting for a person or container
899 def isAtBusStop(self, vehID): 900 """isAtBusStop(string) -> bool 901 Return whether the vehicle is stopped at a bus stop 902 """ 903 return (self.getStopState(vehID) & 16) == 16
isAtBusStop(string) -> bool Return whether the vehicle is stopped at a bus stop
905 def isAtContainerStop(self, vehID): 906 """isAtContainerStop(string) -> bool 907 Return whether the vehicle is stopped at a container stop 908 """ 909 return (self.getStopState(vehID) & 32) == 32
isAtContainerStop(string) -> bool Return whether the vehicle is stopped at a container stop
911 def getLaneChangeState(self, vehID, direction): 912 """getLaneChangeState(string, int) -> (int, int) 913 Return the lane change state for the vehicle. The first value returns 914 the state as computed by the lane change model and the second value 915 returns the state after incorporation TraCI requests. 916 See getLaneChangeStatePretty for an interpretation of the integer/bitset 917 results 918 """ 919 return self._getUniversal(tc.CMD_CHANGELANE, vehID, "i", direction)
getLaneChangeState(string, int) -> (int, int) Return the lane change state for the vehicle. The first value returns the state as computed by the lane change model and the second value returns the state after incorporation TraCI requests. See getLaneChangeStatePretty for an interpretation of the integer/bitset results
921 def getLaneChangeStatePretty(self, vehID, direction): 922 """getLaneChangeStatePretty(string, int) -> ([string, ...], [string, ...]) 923 Return the lane change state for the vehicle as two lists of string 924 constants. The first tuple returns the state as computed by the lane change 925 model and the second tuple returns the state after incorporation TraCI requests. 926 """ 927 constants = { 928 0: 'stay', 929 1: 'left', 930 2: 'right', 931 3: 'strategic', 932 4: 'cooperative', 933 5: 'speedGain', 934 6: 'keepRight', 935 7: 'TraCI', 936 8: 'urgent', 937 9: 'blocked by left leader', 938 10: 'blocked by left follower', 939 11: 'blocked by right leader', 940 12: 'blocked by right follower', 941 13: 'overlapping', 942 14: 'insufficient space', 943 15: 'sublane', 944 } 945 946 def prettifyBitstring(intval): 947 return tuple([v for k, v in constants.items() if (intval & 2**k)]) 948 949 state, stateTraCI = self.getLaneChangeState(vehID, direction) 950 return prettifyBitstring(state), prettifyBitstring(stateTraCI)
getLaneChangeStatePretty(string, int) -> ([string, ...], [string, ...]) Return the lane change state for the vehicle as two lists of string constants. The first tuple returns the state as computed by the lane change model and the second tuple returns the state after incorporation TraCI requests.
952 def couldChangeLane(self, vehID, direction, state=None): 953 """couldChangeLane(string, int) -> bool 954 Return whether the vehicle could change lanes in the specified direction. 955 This reflects the state after the last try to change lanes. 956 If you want to execute changeLane as a result of the evaluation of this function 957 it is not guaranteed to work because vehicle movements occur first. 958 """ 959 if state is None: 960 state, stateTraCI = self.getLaneChangeState(vehID, direction) 961 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 962 # vehicle changed in the last step. state is no longer applicable 963 return False 964 return state != tc.LCA_UNKNOWN and (state & tc.LCA_BLOCKED == 0)
couldChangeLane(string, int) -> bool Return whether the vehicle could change lanes in the specified direction. This reflects the state after the last try to change lanes. If you want to execute changeLane as a result of the evaluation of this function it is not guaranteed to work because vehicle movements occur first.
966 def wantsAndCouldChangeLane(self, vehID, direction, state=None): 967 """wantsAndCouldChangeLane(string, int) -> bool 968 Return whether the vehicle wants to and could change lanes in the specified direction 969 This reflects the state after the last try to change lanes. 970 If you want to execute changeLane as a result of the evaluation of this function 971 it is not guaranteed to work because vehicle movements occur first. 972 """ 973 if state is None: 974 state, stateTraCI = self.getLaneChangeState(vehID, direction) 975 if self.wantsAndCouldChangeLane(vehID, direction, stateTraCI): 976 # vehicle changed in the last step. state is no longer applicable 977 return False 978 if state & tc.LCA_BLOCKED == 0: 979 if direction == -1: 980 return state & tc.LCA_RIGHT != 0 981 if direction == 1: 982 return state & tc.LCA_LEFT != 0 983 return False
wantsAndCouldChangeLane(string, int) -> bool Return whether the vehicle wants to and could change lanes in the specified direction This reflects the state after the last try to change lanes. If you want to execute changeLane as a result of the evaluation of this function it is not guaranteed to work because vehicle movements occur first.
985 def getRoutingMode(self, vehID): 986 """getRoutingMode(string) 987 returns the current routing mode: 988 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 989 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 990 """ 991 return self._getUniversal(tc.VAR_ROUTING_MODE, vehID)
getRoutingMode(string) returns the current routing mode: tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting
993 @alias_param("taxiState", "flag") 994 def getTaxiFleet(self, taxiState=0): 995 """getTaxiFleet(int) -> tuple(string) 996 Return the tuple of all taxis with the given taxiState: 997 0 : empty 998 1 : pickup 999 2 : occupied 1000 """ 1001 return self._getUniversal(tc.VAR_TAXI_FLEET, "", "i", taxiState)
getTaxiFleet(int) -> tuple(string) Return the tuple of all taxis with the given taxiState: 0 : empty 1 : pickup 2 : occupied
1003 def getLoadedIDList(self): 1004 """getLoadedIDList() -> tuple(string) 1005 returns all loaded vehicles that have not yet left the simulation 1006 """ 1007 return self._getUniversal(tc.VAR_LOADED_LIST, "")
getLoadedIDList() -> tuple(string) returns all loaded vehicles that have not yet left the simulation
1009 def getTeleportingIDList(self): 1010 """getTeleportingIDList() -> tuple(string) 1011 returns all teleporting or jumping vehicles 1012 """ 1013 return self._getUniversal(tc.VAR_TELEPORTING_LIST, "")
getTeleportingIDList() -> tuple(string) returns all teleporting or jumping vehicles
1015 def rerouteParkingArea(self, vehID, parkingAreaID): 1016 """rerouteParkingArea(string, string) 1017 1018 Changes the next parking area in parkingAreaID, updates the vehicle route, 1019 and preserve consistency in case of passengers/containers on board. 1020 """ 1021 self._setCmd(tc.CMD_REROUTE_TO_PARKING, vehID, "ts", 1, parkingAreaID)
rerouteParkingArea(string, string)
Changes the next parking area in parkingAreaID, updates the vehicle route, and preserve consistency in case of passengers/containers on board.
1023 def setStop(self, vehID, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1024 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, until=tc.INVALID_DOUBLE_VALUE): 1025 """setStop(string, string, double, integer, double, integer, double, double) -> None 1026 1027 Adds or modifies a stop with the given parameters. The duration and the until attribute are 1028 in seconds. 1029 """ 1030 if type(duration) is int and duration >= 1000 and duration % 1000 == 0: 1031 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1032 self._setCmd(tc.CMD_STOP, vehID, "tsdbdbdd", 7, edgeID, pos, laneIndex, duration, flags, startPos, until)
setStop(string, string, double, integer, double, integer, double, double) -> None
Adds or modifies a stop with the given parameters. The duration and the until attribute are in seconds.
1034 def setBusStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1035 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1036 """setBusStop(string, string, double, double, integer) -> None 1037 1038 Adds or modifies a bus stop with the given parameters. The duration and the until attribute are 1039 in seconds. 1040 """ 1041 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_BUS_STOP)
setBusStop(string, string, double, double, integer) -> None
Adds or modifies a bus stop with the given parameters. The duration and the until attribute are in seconds.
1043 def setContainerStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1044 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1045 """setContainerStop(string, string, double, double, integer) -> None 1046 1047 Adds or modifies a container stop with the given parameters. The duration and the until attribute are 1048 in seconds. 1049 """ 1050 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CONTAINER_STOP)
setContainerStop(string, string, double, double, integer) -> None
Adds or modifies a container stop with the given parameters. The duration and the until attribute are in seconds.
1052 def setChargingStationStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1053 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_DEFAULT): 1054 """setChargingStationStop(string, string, double, double, integer) -> None 1055 1056 Adds or modifies a stop at a chargingStation with the given parameters. The duration and the until attribute are 1057 in seconds. 1058 """ 1059 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_CHARGING_STATION)
setChargingStationStop(string, string, double, double, integer) -> None
Adds or modifies a stop at a chargingStation with the given parameters. The duration and the until attribute are in seconds.
1061 def setParkingAreaStop(self, vehID, stopID, duration=tc.INVALID_DOUBLE_VALUE, 1062 until=tc.INVALID_DOUBLE_VALUE, flags=tc.STOP_PARKING): 1063 """setParkingAreaStop(string, string, double, double, integer) -> None 1064 1065 Adds or modifies a stop at a parkingArea with the given parameters. The duration and the until attribute are 1066 in seconds. 1067 """ 1068 self.setStop(vehID, stopID, duration=duration, until=until, flags=flags | tc.STOP_PARKING_AREA)
setParkingAreaStop(string, string, double, double, integer) -> None
Adds or modifies a stop at a parkingArea with the given parameters. The duration and the until attribute are in seconds.
1070 def replaceStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1071 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1072 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1073 """replaceStop(string, int, string, double, integer, double, integer, double, double) -> None 1074 1075 Replaces stop at the given index (within the list of all stops) with a new stop. 1076 Automatically modifies the route if the replacement stop is at another location. 1077 For edgeID a stopping place id may be given if the flag marks this 1078 stop as stopping on busStop, parkingArea, containerStop etc. 1079 If edgeID is "", the stop at the given index will be removed without 1080 replacement and the route will not be modified (unless setting 1081 teleport=2 which will trigger rerouting between the prior and next stop) 1082 If teleport is set to 1, the route to the replacement stop will be 1083 disconnected (forcing a teleport). 1084 If stopIndex is 0 the gap will be between the current 1085 edge and the new stop. Otherwise the gap will be between the stop edge for 1086 nextStopIndex - 1 and the new stop. 1087 """ 1088 self._setCmd(tc.CMD_REPLACE_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1089 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport)
replaceStop(string, int, string, double, integer, double, integer, double, double) -> None
Replaces stop at the given index (within the list of all stops) with a new stop. Automatically modifies the route if the replacement stop is at another location. For edgeID a stopping place id may be given if the flag marks this stop as stopping on busStop, parkingArea, containerStop etc. If edgeID is "", the stop at the given index will be removed without replacement and the route will not be modified (unless setting teleport=2 which will trigger rerouting between the prior and next stop) If teleport is set to 1, the route to the replacement stop will be disconnected (forcing a teleport). If stopIndex is 0 the gap will be between the current edge and the new stop. Otherwise the gap will be between the stop edge for nextStopIndex - 1 and the new stop.
1091 def insertStop(self, vehID, nextStopIndex, edgeID, pos=1., laneIndex=0, duration=tc.INVALID_DOUBLE_VALUE, 1092 flags=tc.STOP_DEFAULT, startPos=tc.INVALID_DOUBLE_VALUE, 1093 until=tc.INVALID_DOUBLE_VALUE, teleport=0): 1094 """insertStop(string, int, string, double, integer, double, integer, double, double) -> None 1095 1096 Insert stop at the given index (within the list of all existing stops). 1097 Automatically modifies the route if the new stop is not along the route between the preceeding 1098 and succeeding stops (or start / end). 1099 For edgeID a stopping place id may be given if the flag marks this 1100 stop as stopping on busStop, parkingArea, containerStop etc. 1101 If teleport is set to 1, the route to the new stop will be 1102 disconnected (forcing a teleport). 1103 If stopIndex is 0 the gap will be between the current 1104 edge and the new stop. Otherwise the gap will be between the stop edge for 1105 nextStopIndex - 1 and the new stop. 1106 """ 1107 self._setCmd(tc.CMD_INSERT_STOP, vehID, "tsdbdiddib", 9, edgeID, pos, 1108 laneIndex, duration, flags, startPos, until, nextStopIndex, teleport)
insertStop(string, int, string, double, integer, double, integer, double, double) -> None
Insert stop at the given index (within the list of all existing stops). Automatically modifies the route if the new stop is not along the route between the preceeding and succeeding stops (or start / end). For edgeID a stopping place id may be given if the flag marks this stop as stopping on busStop, parkingArea, containerStop etc. If teleport is set to 1, the route to the new stop will be disconnected (forcing a teleport). If stopIndex is 0 the gap will be between the current edge and the new stop. Otherwise the gap will be between the stop edge for nextStopIndex - 1 and the new stop.
1110 def setStopParameter(self, vehID, nextStopIndex, param, value, customParam=False): 1111 """setStopParameter(string, int, string, string) -> None 1112 Sets the value of the given parameter for the (upcoming) stop at the 1113 given index (within the list of all stops). 1114 Supported params correspond to (almost) all legal stop xml-attributes 1115 and their value semantics 1116 If customParam is set to True, the user defined stop parameter with the 1117 specified param name will be set instead 1118 """ 1119 self._setCmd(tc.VAR_STOP_PARAMETER, vehID, "tissb", 4, nextStopIndex, param, value, customParam)
setStopParameter(string, int, string, string) -> None Sets the value of the given parameter for the (upcoming) stop at the given index (within the list of all stops). Supported params correspond to (almost) all legal stop xml-attributes and their value semantics If customParam is set to True, the user defined stop parameter with the specified param name will be set instead
1121 def resume(self, vehID): 1122 """resume(string) -> None 1123 1124 Resumes the vehicle from the current stop (throws an error if the vehicle is not stopped). 1125 """ 1126 self._setCmd(tc.CMD_RESUME, vehID, "t", 0)
resume(string) -> None
Resumes the vehicle from the current stop (throws an error if the vehicle is not stopped).
1128 def changeLane(self, vehID, laneIndex, duration): 1129 """changeLane(string, int, double) -> None 1130 Forces a lane change to the lane with the given index; The lane change 1131 will be attempted for the given duration (in s) and if it succeeds, 1132 the vehicle will stay on that lane for the remaining duration. 1133 """ 1134 if type(duration) is int and duration >= 1000: 1135 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1136 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbd", 2, laneIndex, duration)
changeLane(string, int, double) -> None Forces a lane change to the lane with the given index; The lane change will be attempted for the given duration (in s) and if it succeeds, the vehicle will stay on that lane for the remaining duration.
1138 def changeLaneRelative(self, vehID, indexOffset, duration): 1139 """changeLaneRelative(string, int, double) -> None 1140 1141 Forces a relative lane change; if successful, 1142 the lane will be chosen for the given amount of time (in s). 1143 The indexOffset specifies the target lane relative to the vehicles current lane 1144 """ 1145 if type(duration) is int and duration >= 1000: 1146 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1147 self._setCmd(tc.CMD_CHANGELANE, vehID, "tbdb", 3, indexOffset, duration, 1)
changeLaneRelative(string, int, double) -> None
Forces a relative lane change; if successful, the lane will be chosen for the given amount of time (in s). The indexOffset specifies the target lane relative to the vehicles current lane
1149 def changeSublane(self, vehID, latDist): 1150 """changeSublane(string, double) -> None 1151 Forces a lateral change by the given amount (negative values indicate changing to the right, positive 1152 to the left). This will override any other lane change motivations but conform to 1153 safety-constraints as configured by laneChangeMode. 1154 """ 1155 self._setCmd(tc.CMD_CHANGESUBLANE, vehID, "d", latDist)
changeSublane(string, double) -> None Forces a lateral change by the given amount (negative values indicate changing to the right, positive to the left). This will override any other lane change motivations but conform to safety-constraints as configured by laneChangeMode.
1157 def slowDown(self, vehID, speed, duration): 1158 """slowDown(string, double, double) -> None 1159 1160 Changes the speed smoothly to the given value over the given amount 1161 of time in seconds (can also be used to increase speed). 1162 """ 1163 if type(duration) is int and duration >= 1000: 1164 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1165 self._setCmd(tc.CMD_SLOWDOWN, vehID, "tdd", 2, speed, duration)
slowDown(string, double, double) -> None
Changes the speed smoothly to the given value over the given amount of time in seconds (can also be used to increase speed).
1167 def openGap(self, vehID, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel=-1, referenceVehID=None): 1168 """openGap(string, double, double, double, double, double, string) -> None 1169 1170 Changes the vehicle's desired time headway (cf-parameter tau) smoothly to the given new value 1171 using the given change rate. Similarly, the given space headway is applied gradually 1172 to achieve a minimal spatial gap. 1173 The vehicle is commanded to keep the increased headway for 1174 the given duration once its target value is attained. The maximal value for the 1175 deceleration can be given to prevent harsh braking due to the change of tau. If maxDecel=-1, 1176 the limit determined by the CF model is used. 1177 A vehicle ID for a reference vehicle can optionally be given, otherwise, the gap is created with 1178 respect to the current leader on the ego vehicle's current lane. 1179 Note that this does only affect the following behavior regarding the current leader and does 1180 not influence the gap acceptance during lane change, etc. 1181 """ 1182 if type(duration) is int and duration >= 1000: 1183 warnings.warn("API change now handles duration as floating point seconds", stacklevel=2) 1184 if referenceVehID is None: 1185 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddd", 5, 1186 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel) 1187 else: 1188 self._setCmd(tc.CMD_OPENGAP, vehID, "tddddds", 6, 1189 newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, referenceVehID)
openGap(string, double, double, double, double, double, string) -> None
Changes the vehicle's desired time headway (cf-parameter tau) smoothly to the given new value using the given change rate. Similarly, the given space headway is applied gradually to achieve a minimal spatial gap. The vehicle is commanded to keep the increased headway for the given duration once its target value is attained. The maximal value for the deceleration can be given to prevent harsh braking due to the change of tau. If maxDecel=-1, the limit determined by the CF model is used. A vehicle ID for a reference vehicle can optionally be given, otherwise, the gap is created with respect to the current leader on the ego vehicle's current lane. Note that this does only affect the following behavior regarding the current leader and does not influence the gap acceptance during lane change, etc.
1191 def deactivateGapControl(self, vehID): 1192 """deactivateGapControl(string) -> None 1193 1194 Deactivate the vehicle's gap control 1195 """ 1196 self.openGap(vehID, -1, -1, -1, -1)
deactivateGapControl(string) -> None
Deactivate the vehicle's gap control
1198 def requestToC(self, vehID, leadTime): 1199 """ requestToC(string, double) -> None 1200 1201 Interface for triggering a transition of control for a vehicle equipped with a ToC device. 1202 """ 1203 self.setParameter(vehID, "device.toc.requestToC", str(leadTime))
requestToC(string, double) -> None
Interface for triggering a transition of control for a vehicle equipped with a ToC device.
1205 def changeTarget(self, vehID, edgeID): 1206 """changeTarget(string, string) -> None 1207 1208 The vehicle's destination edge is set to the given edge id. The route is rebuilt. 1209 """ 1210 self._setCmd(tc.CMD_CHANGETARGET, vehID, "s", edgeID)
changeTarget(string, string) -> None
The vehicle's destination edge is set to the given edge id. The route is rebuilt.
1212 def setType(self, vehID, typeID): 1213 """setType(string, string) -> None 1214 1215 Sets the id of the type for the named vehicle. 1216 """ 1217 self._setCmd(tc.VAR_TYPE, vehID, "s", typeID)
setType(string, string) -> None
Sets the id of the type for the named vehicle.
1219 def setRouteID(self, vehID, routeID): 1220 """setRouteID(string, string) -> None 1221 1222 Changes the vehicles route to the route with the given id. 1223 """ 1224 self._setCmd(tc.VAR_ROUTE_ID, vehID, "s", routeID)
setRouteID(string, string) -> None
Changes the vehicles route to the route with the given id.
1226 def setRoute(self, vehID, edgeList): 1227 """ 1228 setRoute(string, list) -> None 1229 1230 changes the vehicle route to given edges list. 1231 The first edge in the list has to be the one that the vehicle is at the moment. 1232 1233 example usage: 1234 setRoute('1', ['1', '2', '4', '6', '7']) 1235 1236 this changes route for vehicle id 1 to edges 1-2-4-6-7 1237 """ 1238 if isinstance(edgeList, str): 1239 edgeList = [edgeList] 1240 self._setCmd(tc.VAR_ROUTE, vehID, "l", edgeList)
setRoute(string, list) -> None
changes the vehicle route to given edges list. The first edge in the list has to be the one that the vehicle is at the moment.
example usage: setRoute('1', ['1', '2', '4', '6', '7'])
this changes route for vehicle id 1 to edges 1-2-4-6-7
1242 def setLateralLanePosition(self, vehID, posLat): 1243 """setLateralLanePosition(string, double) -> None 1244 1245 Sets the lateral vehicle position relative to the center line of the 1246 lane in m (negative values are to the right in right-hand networks). 1247 The vehicle may adapt this position in the same step unless this is 1248 disabled via setLaneChangeMode. 1249 """ 1250 self._setCmd(tc.VAR_LANEPOSITION_LAT, vehID, "d", posLat)
setLateralLanePosition(string, double) -> None
Sets the lateral vehicle position relative to the center line of the lane in m (negative values are to the right in right-hand networks). The vehicle may adapt this position in the same step unless this is disabled via setLaneChangeMode.
1252 def updateBestLanes(self, vehID): 1253 """ updateBestLanes(string) -> None 1254 Triggers an update of the vehicle's bestLanes (structure determining the lane preferences used by LC models) 1255 It may be called after modifying the vClass for instance. 1256 """ 1257 self._setCmd(tc.VAR_UPDATE_BESTLANES, vehID)
updateBestLanes(string) -> None Triggers an update of the vehicle's bestLanes (structure determining the lane preferences used by LC models) It may be called after modifying the vClass for instance.
1259 def setAdaptedTraveltime(self, vehID, edgeID, time=None, begTime=None, endTime=None): 1260 """setAdaptedTraveltime(string, string, double, double, double) -> None 1261 Inserts the information about the travel time of edge "edgeID" valid 1262 from begin time to end time into the vehicle's internal edge weights 1263 container. 1264 If the time is not specified, any previously set values for that edge 1265 are removed. 1266 If begTime or endTime are not specified the value is set for the whole 1267 simulation duration. 1268 """ 1269 if not isinstance(edgeID, str) and isinstance(begTime, str): 1270 # legacy handling 1271 warnings.warn( 1272 "Parameter order has changed for setAdaptedTraveltime(). Attempting legacy ordering. " + 1273 "Please update your code.", stacklevel=2) 1274 return self.setAdaptedTraveltime(vehID, begTime, endTime, edgeID, time) 1275 if time is None: 1276 # reset 1277 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "ts", 1, edgeID) 1278 elif begTime is None: 1279 # set value for the whole simulation 1280 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tsd", 2, edgeID, time) 1281 else: 1282 self._setCmd(tc.VAR_EDGE_TRAVELTIME, vehID, "tddsd", 4, begTime, endTime, edgeID, time)
setAdaptedTraveltime(string, string, double, double, double) -> None Inserts the information about the travel time of edge "edgeID" valid from begin time to end time into the vehicle's internal edge weights container. If the time is not specified, any previously set values for that edge are removed. If begTime or endTime are not specified the value is set for the whole simulation duration.
1284 def setEffort(self, vehID, edgeID, effort=None, begTime=None, endTime=None): 1285 """setEffort(string, string, double, double, double) -> None 1286 Inserts the information about the effort of edge "edgeID" valid from 1287 begin time to end time into the vehicle's internal edge weights 1288 container. 1289 If the time is not specified, any previously set values for that edge 1290 are removed. 1291 If begTime or endTime are not specified the value is set for the whole 1292 simulation duration. 1293 """ 1294 if not isinstance(edgeID, str) and isinstance(begTime, str): 1295 # legacy handling 1296 warnings.warn( 1297 "Parameter order has changed for setEffort(). Attempting legacy ordering. Please update your code.", 1298 stacklevel=2) 1299 return self.setEffort(vehID, begTime, endTime, edgeID, effort) 1300 if effort is None: 1301 # reset 1302 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "ts", 1, edgeID) 1303 elif begTime is None: 1304 # set value for the whole simulation 1305 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tsd", 2, edgeID, effort) 1306 else: 1307 self._setCmd(tc.VAR_EDGE_EFFORT, vehID, "tddsd", 4, begTime, endTime, edgeID, effort)
setEffort(string, string, double, double, double) -> None Inserts the information about the effort of edge "edgeID" valid from begin time to end time into the vehicle's internal edge weights container. If the time is not specified, any previously set values for that edge are removed. If begTime or endTime are not specified the value is set for the whole simulation duration.
1311 def setRoutingMode(self, vehID, routingMode): 1312 """setRoutingMode(string, int) -> None 1313 Sets the current routing mode: 1314 tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) 1315 tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting 1316 tc.ROUTING_MODE_AGGREGATED_CUSTOM : use weight storages and fall-back to smoothed travel times 1317 """ 1318 self._setCmd(tc.VAR_ROUTING_MODE, vehID, "i", routingMode)
setRoutingMode(string, int) -> None Sets the current routing mode: tc.ROUTING_MODE_DEFAULT : use weight storages and fall-back to edge speeds (default) tc.ROUTING_MODE_AGGREGATED : use global smoothed travel times from device.rerouting tc.ROUTING_MODE_AGGREGATED_CUSTOM : use weight storages and fall-back to smoothed travel times
1320 def rerouteTraveltime(self, vehID, currentTravelTimes=True): 1321 """rerouteTraveltime(string, bool) -> None 1322 Reroutes a vehicle. 1323 If currentTravelTimes is True (default) and the routing mode is still ROUTING_MODE_DEFAULT 1324 then the ROUTING_MODE_AGGREGATED_CUSTOM gets activated temporarily 1325 and used for rerouting. The various functions and options for 1326 customizing travel times are described at https://sumo.dlr.de/wiki/Simulation/Routing 1327 1328 When rerouteTraveltime has been called once with an aggregated routing mode, 1329 edge weight storage and update gets activated which might slow down the simulation. 1330 """ 1331 if currentTravelTimes: 1332 routingMode = self.getRoutingMode(vehID) 1333 if routingMode == tc.ROUTING_MODE_DEFAULT: 1334 self.setRoutingMode(vehID, tc.ROUTING_MODE_AGGREGATED_CUSTOM) 1335 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, vehID, "t", 0) 1336 if currentTravelTimes and routingMode == tc.ROUTING_MODE_DEFAULT: 1337 self.setRoutingMode(vehID, routingMode)
rerouteTraveltime(string, bool) -> None Reroutes a vehicle. If currentTravelTimes is True (default) and the routing mode is still ROUTING_MODE_DEFAULT then the ROUTING_MODE_AGGREGATED_CUSTOM gets activated temporarily and used for rerouting. The various functions and options for customizing travel times are described at https://sumo.dlr.de/wiki/Simulation/Routing
When rerouteTraveltime has been called once with an aggregated routing mode, edge weight storage and update gets activated which might slow down the simulation.
1339 def rerouteEffort(self, vehID): 1340 """rerouteEffort(string) -> None 1341 Reroutes a vehicle according to the effort values. 1342 """ 1343 self._setCmd(tc.CMD_REROUTE_EFFORT, vehID, "t", 0)
rerouteEffort(string) -> None Reroutes a vehicle according to the effort values.
1345 def setSignals(self, vehID, signals): 1346 """setSignals(string, integer) -> None 1347 1348 Sets an integer encoding the state of the vehicle's signals. 1349 """ 1350 self._setCmd(tc.VAR_SIGNALS, vehID, "i", signals)
setSignals(string, integer) -> None
Sets an integer encoding the state of the vehicle's signals.
1352 def moveTo(self, vehID, laneID, pos, reason=tc.MOVE_AUTOMATIC): 1353 """moveTo(string, string, double, integer) -> None 1354 1355 Move a vehicle to a new position along its current route. 1356 """ 1357 self._setCmd(tc.VAR_MOVE_TO, vehID, "tsdi", 3, laneID, pos, reason)
moveTo(string, string, double, integer) -> None
Move a vehicle to a new position along its current route.
1359 def setSpeed(self, vehID, speed): 1360 """setSpeed(string, double) -> None 1361 1362 Sets the speed in m/s for the named vehicle within the last step. 1363 Calling with speed=-1 hands the vehicle control back to SUMO. 1364 """ 1365 self._setCmd(tc.VAR_SPEED, vehID, "d", speed)
setSpeed(string, double) -> None
Sets the speed in m/s for the named vehicle within the last step. Calling with speed=-1 hands the vehicle control back to SUMO.
1367 def setAcceleration(self, vehID, acceleration, duration): 1368 """setAcceleration(string, double, double) -> None 1369 1370 Sets the acceleration in m/s^2 for the named vehicle and the given duration. 1371 """ 1372 self._setCmd(tc.VAR_ACCELERATION, vehID, "tdd", 2, acceleration, duration)
setAcceleration(string, double, double) -> None
Sets the acceleration in m/s^2 for the named vehicle and the given duration.
1374 def setPreviousSpeed(self, vehID, speed, acceleration=tc.INVALID_DOUBLE_VALUE): 1375 """setPreviousSpeed(string, double, double) -> None 1376 1377 Sets the previous speed in m/s for the named vehicle wich will be used for 1378 calculations in the current step. Optionally, the acceleration for the 1379 previous step (in m/s^2) can be set as well. 1380 """ 1381 self._setCmd(tc.VAR_PREV_SPEED, vehID, "tdd", 2, speed, acceleration)
setPreviousSpeed(string, double, double) -> None
Sets the previous speed in m/s for the named vehicle wich will be used for calculations in the current step. Optionally, the acceleration for the previous step (in m/s^2) can be set as well.
1383 def setLine(self, vehID, line): 1384 """setLine(string, string) -> None 1385 1386 Sets the line information for this vehicle. 1387 """ 1388 self._setCmd(tc.VAR_LINE, vehID, "s", line)
setLine(string, string) -> None
Sets the line information for this vehicle.
1390 def setVia(self, vehID, edgeList): 1391 """ 1392 setVia(string, list) -> None 1393 1394 changes the via edges to the given edges list (to be used during 1395 subsequent rerouting calls). 1396 1397 Note: a single edgeId as argument is allowed as shorthand for a list of length 1 1398 """ 1399 if isinstance(edgeList, str): 1400 edgeList = [edgeList] 1401 self._setCmd(tc.VAR_VIA, vehID, "l", edgeList)
setVia(string, list) -> None
changes the via edges to the given edges list (to be used during subsequent rerouting calls).
Note: a single edgeId as argument is allowed as shorthand for a list of length 1
1403 def highlight(self, vehID, color=(255, 0, 0, 255), size=-1, alphaMax=-1, duration=-1, type=0): 1404 """ highlight(string, color, float, ubyte, float, ubyte) -> None 1405 Adds a circle of the given color tracking the vehicle. 1406 If a positive size [in m] is given the size of the highlight is chosen accordingly, 1407 otherwise the length of the vehicle is used as reference. 1408 If alphaMax and duration are positive, the circle fades in and out within the given duration, 1409 otherwise it permanently follows the vehicle. 1410 """ 1411 if type > 255: 1412 raise TraCIException("vehicle.highlight(): maximal value for type is 255") 1413 if alphaMax > 255: 1414 raise TraCIException("vehicle.highlight(): maximal value for alphaMax is 255") 1415 if alphaMax <= 0 and duration > 0: 1416 raise TraCIException("vehicle.highlight(): duration>0 requires alphaMax>0") 1417 if alphaMax > 0 and duration <= 0: 1418 raise TraCIException("vehicle.highlight(): alphaMax>0 requires duration>0") 1419 1420 if alphaMax > 0: 1421 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcdBdB", 5, color, size, alphaMax, duration, type) 1422 else: 1423 self._setCmd(tc.VAR_HIGHLIGHT, vehID, "tcd", 2, color, size)
highlight(string, color, float, ubyte, float, ubyte) -> None Adds a circle of the given color tracking the vehicle. If a positive size [in m] is given the size of the highlight is chosen accordingly, otherwise the length of the vehicle is used as reference. If alphaMax and duration are positive, the circle fades in and out within the given duration, otherwise it permanently follows the vehicle.
1425 @alias_param("laneChangeMode", "lcm") 1426 def setLaneChangeMode(self, vehID, laneChangeMode): 1427 """setLaneChangeMode(string, integer) -> None 1428 1429 Sets the vehicle's lane change mode as a bitset. 1430 """ 1431 self._setCmd(tc.VAR_LANECHANGE_MODE, vehID, "i", laneChangeMode)
setLaneChangeMode(string, integer) -> None
Sets the vehicle's lane change mode as a bitset.
1433 @alias_param("speedMode", "sm") 1434 def setSpeedMode(self, vehID, speedMode): 1435 """setSpeedMode(string, integer) -> None 1436 1437 Sets the vehicle's speed mode as a bitset. 1438 """ 1439 self._setCmd(tc.VAR_SPEEDSETMODE, vehID, "i", speedMode)
setSpeedMode(string, integer) -> None
Sets the vehicle's speed mode as a bitset.
1441 def addLegacy(self, vehID, routeID, depart=tc.DEPARTFLAG_NOW, pos=0, speed=0, 1442 lane=tc.DEPARTFLAG_LANE_FIRST_ALLOWED, typeID="DEFAULT_VEHTYPE"): 1443 """ 1444 Add a new vehicle (old style) 1445 """ 1446 if depart == tc.DEPARTFLAG_NOW: 1447 depart = "now" 1448 elif depart == tc.DEPARTFLAG_TRIGGERED: 1449 depart = "triggered" 1450 else: 1451 depart = str(depart) 1452 if pos < 0: 1453 print("Invalid departure position.") 1454 return 1455 if lane == tc.DEPARTFLAG_LANE_FIRST_ALLOWED: 1456 lane = "first" 1457 elif lane == tc.DEPARTFLAG_LANE_FREE: 1458 lane = "free" 1459 else: 1460 lane = str(lane) 1461 self.addFull(vehID, routeID, typeID, depart, lane, str(pos), str(speed))
Add a new vehicle (old style)
1463 def add(self, vehID, routeID, typeID="DEFAULT_VEHTYPE", depart="now", 1464 departLane="first", departPos="base", departSpeed="0", 1465 arrivalLane="current", arrivalPos="max", arrivalSpeed="current", 1466 fromTaz="", toTaz="", line="", personCapacity=0, personNumber=0, 1467 departPosLat="", arrivalPosLat="", speedFactor=-1, insertionChecks=""): 1468 """ 1469 Add a new vehicle (new style with all possible parameters) 1470 If routeID is "", the vehicle will be inserted on a random network edge 1471 if route consists of two disconnected edges, the vehicle will be treated 1472 like a <trip> and use the fastest route between the two edges. 1473 """ 1474 if depart is None: 1475 # legacy compatibility 1476 depart = str(self._connection.simulation.getTime()) 1477 withOptional = (departPosLat != "" or arrivalPosLat != "" 1478 or speedFactor != -1 or insertionChecks != "") 1479 if withOptional: 1480 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii" + "ss" + "d" + "s", 18, 1481 routeID, typeID, depart, departLane, departPos, departSpeed, 1482 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, 1483 personCapacity, personNumber, departPosLat, arrivalPosLat, 1484 speedFactor, insertionChecks) 1485 else: 1486 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii", 14, 1487 routeID, typeID, depart, departLane, departPos, departSpeed, 1488 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, 1489 personCapacity, personNumber)
Add a new vehicle (new style with all possible parameters)
If routeID is "", the vehicle will be inserted on a random network edge
if route consists of two disconnected edges, the vehicle will be treated
like a
1463 def add(self, vehID, routeID, typeID="DEFAULT_VEHTYPE", depart="now", 1464 departLane="first", departPos="base", departSpeed="0", 1465 arrivalLane="current", arrivalPos="max", arrivalSpeed="current", 1466 fromTaz="", toTaz="", line="", personCapacity=0, personNumber=0, 1467 departPosLat="", arrivalPosLat="", speedFactor=-1, insertionChecks=""): 1468 """ 1469 Add a new vehicle (new style with all possible parameters) 1470 If routeID is "", the vehicle will be inserted on a random network edge 1471 if route consists of two disconnected edges, the vehicle will be treated 1472 like a <trip> and use the fastest route between the two edges. 1473 """ 1474 if depart is None: 1475 # legacy compatibility 1476 depart = str(self._connection.simulation.getTime()) 1477 withOptional = (departPosLat != "" or arrivalPosLat != "" 1478 or speedFactor != -1 or insertionChecks != "") 1479 if withOptional: 1480 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii" + "ss" + "d" + "s", 18, 1481 routeID, typeID, depart, departLane, departPos, departSpeed, 1482 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, 1483 personCapacity, personNumber, departPosLat, arrivalPosLat, 1484 speedFactor, insertionChecks) 1485 else: 1486 self._setCmd(tc.ADD_FULL, vehID, "t" + (12 * "s") + "ii", 14, 1487 routeID, typeID, depart, departLane, departPos, departSpeed, 1488 arrivalLane, arrivalPos, arrivalSpeed, fromTaz, toTaz, line, 1489 personCapacity, personNumber)
Add a new vehicle (new style with all possible parameters)
If routeID is "", the vehicle will be inserted on a random network edge
if route consists of two disconnected edges, the vehicle will be treated
like a
1493 def dispatchTaxi(self, vehID, reservations): 1494 """dispatchTaxi(string, list(string)) -> None 1495 dispatches the taxi with the given id to service the given reservations. 1496 If only a single reservation is given, this implies pickup and drop-off 1497 If multiple reservations are given, each reservation id must occur twice 1498 (once for pickup and once for drop-off) and the list encodes ride 1499 sharing of passengers (in pickup and drop-off order) 1500 """ 1501 if isinstance(reservations, str): 1502 reservations = [reservations] 1503 self._setCmd(tc.CMD_TAXI_DISPATCH, vehID, "l", reservations)
dispatchTaxi(string, list(string)) -> None dispatches the taxi with the given id to service the given reservations. If only a single reservation is given, this implies pickup and drop-off If multiple reservations are given, each reservation id must occur twice (once for pickup and once for drop-off) and the list encodes ride sharing of passengers (in pickup and drop-off order)
1505 def remove(self, vehID, reason=tc.REMOVE_VAPORIZED): 1506 '''Remove vehicle with the given ID for the give reason. 1507 Reasons are defined in module constants and start with REMOVE_''' 1508 self._setCmd(tc.REMOVE, vehID, "b", reason)
Remove vehicle with the given ID for the give reason. Reasons are defined in module constants and start with REMOVE_
1510 @alias_param("laneIndex", "lane") 1511 def moveToXY(self, vehID, edgeID, laneIndex, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 1512 '''Place vehicle at the given x,y coordinates and force its angle to 1513 the given value (for drawing). 1514 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 1515 natural angle of the edge on which it is driving. 1516 If keepRoute is set to 1, the closest position 1517 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 1518 any edge in the network but its route then only consists of that edge. 1519 If keepRoute is set to 2 the vehicle has all the freedom of keepRoute=0 1520 but in addition to that may even move outside the road network. 1521 edgeID and lane are optional placement hints to resolve ambiguities. 1522 The command fails if no suitable target position is found within the 1523 distance given by matchThreshold. 1524 ''' 1525 self._setCmd(tc.MOVE_TO_XY, vehID, "tsidddbd", 7, edgeID, laneIndex, x, y, angle, keepRoute, matchThreshold)
Place vehicle at the given x,y coordinates and force its angle to the given value (for drawing). If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the natural angle of the edge on which it is driving. If keepRoute is set to 1, the closest position within the existing route is taken. If keepRoute is set to 0, the vehicle may move to any edge in the network but its route then only consists of that edge. If keepRoute is set to 2 the vehicle has all the freedom of keepRoute=0 but in addition to that may even move outside the road network. edgeID and lane are optional placement hints to resolve ambiguities. The command fails if no suitable target position is found within the distance given by matchThreshold.
1527 def addSubscriptionFilterLanes(self, lanes, noOpposite=False, downstreamDist=None, upstreamDist=None): 1528 """addSubscriptionFilterLanes(list(integer), bool, double, double) -> None 1529 1530 Adds a lane-filter to the last modified vehicle context subscription (call it just after subscribing). 1531 lanes is a list of relative lane indices (-1 -> right neighboring lane of the ego, 0 -> ego lane, etc.) 1532 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1533 downstreamDist and upstreamDist specify the range of the search for surrounding vehicles along the road net. 1534 """ 1535 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes) 1536 if noOpposite: 1537 self.addSubscriptionFilterNoOpposite() 1538 if downstreamDist is not None: 1539 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1540 if upstreamDist is not None: 1541 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
addSubscriptionFilterLanes(list(integer), bool, double, double) -> None
Adds a lane-filter to the last modified vehicle context subscription (call it just after subscribing). lanes is a list of relative lane indices (-1 -> right neighboring lane of the ego, 0 -> ego lane, etc.) noOpposite specifies whether vehicles on opposite direction lanes shall be returned downstreamDist and upstreamDist specify the range of the search for surrounding vehicles along the road net.
1543 def addSubscriptionFilterNoOpposite(self): 1544 """addSubscriptionFilterNoOpposite() -> None 1545 1546 Omits vehicles on other edges than the ego's for the last modified vehicle context subscription 1547 (call it just after subscribing). 1548 """ 1549 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_NOOPPOSITE)
addSubscriptionFilterNoOpposite() -> None
Omits vehicles on other edges than the ego's for the last modified vehicle context subscription (call it just after subscribing).
1551 def addSubscriptionFilterDownstreamDistance(self, dist): 1552 """addSubscriptionFilterDownstreamDist(float) -> None 1553 1554 Sets the downstream distance along the network for vehicles to be returned by the last modified 1555 vehicle context subscription (call it just after subscribing). 1556 """ 1557 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_DOWNSTREAM_DIST, dist)
addSubscriptionFilterDownstreamDist(float) -> None
Sets the downstream distance along the network for vehicles to be returned by the last modified vehicle context subscription (call it just after subscribing).
1559 def addSubscriptionFilterUpstreamDistance(self, dist): 1560 """addSubscriptionFilterUpstreamDist(float) -> None 1561 1562 Sets the upstream distance along the network for vehicles to be returned by the last modified 1563 vehicle context subscription (call it just after subscribing). 1564 """ 1565 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_UPSTREAM_DIST, dist)
addSubscriptionFilterUpstreamDist(float) -> None
Sets the upstream distance along the network for vehicles to be returned by the last modified vehicle context subscription (call it just after subscribing).
1567 def addSubscriptionFilterCFManeuver(self, downstreamDist=None, upstreamDist=None): 1568 """addSubscriptionFilterCFManeuver() -> None 1569 1570 Restricts vehicles returned by the last modified vehicle context subscription to leader and follower of the ego. 1571 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1572 """ 1573 self.addSubscriptionFilterLeadFollow([0]) 1574 if downstreamDist is not None: 1575 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1576 if upstreamDist is not None: 1577 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
addSubscriptionFilterCFManeuver() -> None
Restricts vehicles returned by the last modified vehicle context subscription to leader and follower of the ego. downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net.
1579 def addSubscriptionFilterLCManeuver(self, direction=None, noOpposite=False, downstreamDist=None, upstreamDist=None): 1580 """addSubscriptionFilterLCManeuver(int) -> None 1581 1582 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1583 and follower of the ego. 1584 direction - lane change direction (in {-1=right, 1=left}) 1585 noOpposite specifies whether vehicles on opposite direction lanes shall be returned 1586 downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. 1587 Combine with: distance filters; vClass/vType filter. 1588 """ 1589 if direction is None: 1590 # Using default: both directions 1591 lanes = [-1, 0, 1] 1592 elif not (direction == -1 or direction == 1): 1593 warnings.warn("Ignoring lane change subscription filter " + 1594 "with non-neighboring lane offset direction=%s." % direction) 1595 return 1596 else: 1597 lanes = [0, direction] 1598 self.addSubscriptionFilterLeadFollow(lanes) 1599 if noOpposite: 1600 self.addSubscriptionFilterNoOpposite() 1601 if downstreamDist is not None: 1602 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1603 if upstreamDist is not None: 1604 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
addSubscriptionFilterLCManeuver(int) -> None
Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader and follower of the ego. direction - lane change direction (in {-1=right, 1=left}) noOpposite specifies whether vehicles on opposite direction lanes shall be returned downstreamDist and upstreamDist specify the range of the search for leader and follower along the road net. Combine with: distance filters; vClass/vType filter.
1606 def addSubscriptionFilterLeadFollow(self, lanes): 1607 """addSubscriptionFilterLCManeuver(lanes) -> None 1608 1609 Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader 1610 and follower of the ego. 1611 Combine with: lanes-filter to restrict to one direction; distance filters; vClass/vType filter. 1612 """ 1613 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LEAD_FOLLOW) 1614 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LANES, lanes)
addSubscriptionFilterLCManeuver(lanes) -> None
Restricts vehicles returned by the last modified vehicle context subscription to neighbor and ego-lane leader and follower of the ego. Combine with: lanes-filter to restrict to one direction; distance filters; vClass/vType filter.
1616 def addSubscriptionFilterTurn(self, downstreamDist=None, foeDistToJunction=None): 1617 """addSubscriptionFilterTurn(double, double) -> None 1618 1619 Restricts vehicles returned by the last modified vehicle context subscription to foes on upcoming junctions 1620 """ 1621 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_TURN, foeDistToJunction) 1622 if downstreamDist is not None: 1623 self.addSubscriptionFilterDownstreamDistance(downstreamDist)
addSubscriptionFilterTurn(double, double) -> None
Restricts vehicles returned by the last modified vehicle context subscription to foes on upcoming junctions
1625 def addSubscriptionFilterVClass(self, vClasses): 1626 """addSubscriptionFilterVClass(list(String)) -> None 1627 1628 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given classes 1629 """ 1630 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VCLASS, vClasses)
addSubscriptionFilterVClass(list(String)) -> None
Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given classes
1632 def addSubscriptionFilterVType(self, vTypes): 1633 """addSubscriptionFilterVType(list(String)) -> None 1634 1635 Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given types 1636 """ 1637 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_VTYPE, vTypes)
addSubscriptionFilterVType(list(String)) -> None
Restricts vehicles returned by the last modified vehicle context subscription to vehicles of the given types
1639 def addSubscriptionFilterFieldOfVision(self, openingAngle): 1640 """addSubscriptionFilterFieldOfVision(float) -> None 1641 1642 Restricts vehicles returned by the last modified vehicle context subscription 1643 to vehicles within field of vision with given opening angle 1644 """ 1645 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_FIELD_OF_VISION, openingAngle)
addSubscriptionFilterFieldOfVision(float) -> None
Restricts vehicles returned by the last modified vehicle context subscription to vehicles within field of vision with given opening angle
1647 def addSubscriptionFilterLateralDistance(self, lateralDist, downstreamDist=None, upstreamDist=None): 1648 """addSubscriptionFilterLateralDist(double, double, double) -> None 1649 1650 Adds a lateral distance filter to the last modified vehicle context subscription 1651 (call it just after subscribing). 1652 downstreamDist and upstreamDist specify the longitudinal range of the search 1653 for surrounding vehicles along the ego vehicle's route. 1654 """ 1655 self._connection._addSubscriptionFilter(tc.FILTER_TYPE_LATERAL_DIST, lateralDist) 1656 if downstreamDist is not None: 1657 self.addSubscriptionFilterDownstreamDistance(downstreamDist) 1658 if upstreamDist is not None: 1659 self.addSubscriptionFilterUpstreamDistance(upstreamDist)
addSubscriptionFilterLateralDist(double, double, double) -> None
Adds a lateral distance filter to the last modified vehicle context subscription (call it just after subscribing). downstreamDist and upstreamDist specify the longitudinal range of the search for surrounding vehicles along the ego vehicle's route.
Inherited Members
- traci._vehicletype.VTypeDomain
- getLength
- getMaxSpeed
- getActionStepLength
- getSpeedFactor
- getSpeedDeviation
- getAccel
- getDecel
- getEmergencyDecel
- getApparentDecel
- getImperfection
- getTau
- getVehicleClass
- getEmissionClass
- getShapeClass
- getMinGap
- getWidth
- getHeight
- getMass
- getColor
- getMinGapLat
- getMaxSpeedLat
- getLateralAlignment
- getPersonCapacity
- getBoardingDuration
- getImpatience
- setImpatience
- setBoardingDuration
- setLength
- setMaxSpeed
- setVehicleClass
- setSpeedFactor
- setEmissionClass
- setShapeClass
- setWidth
- setHeight
- setMass
- setMinGap
- setAccel
- setDecel
- setEmergencyDecel
- setApparentDecel
- setImperfection
- setTau
- setColor
- setMinGapLat
- setMaxSpeedLat
- setLateralAlignment
- setActionStepLength
- traci.domain.Domain
- DOMAIN_ID
- getIDList
- getIDCount
- domainID
- subscribe
- unsubscribe
- getSubscriptionResults
- getAllSubscriptionResults
- subscribeContext
- unsubscribeContext
- getContextSubscriptionResults
- getAllContextSubscriptionResults
- getParameter
- getParameterWithKey
- subscribeParameterWithKey
- setParameter