traci._simulation
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 _simulation.py 15# @author Daniel Krajzewicz 16# @author Jakob Erdmann 17# @author Michael Behrisch 18# @date 2011-03-15 19 20from __future__ import absolute_import 21import warnings 22from . import constants as tc 23from .domain import Domain 24from .exceptions import FatalTraCIError, deprecated 25 26 27class Stage(object): 28 29 def __init__(self, 30 type=tc.INVALID_INT_VALUE, 31 vType="", 32 line="", 33 destStop="", 34 edges=[], 35 travelTime=tc.INVALID_DOUBLE_VALUE, 36 cost=tc.INVALID_DOUBLE_VALUE, 37 length=tc.INVALID_DOUBLE_VALUE, 38 intended="", 39 depart=tc.INVALID_DOUBLE_VALUE, 40 departPos=tc.INVALID_DOUBLE_VALUE, 41 arrivalPos=tc.INVALID_DOUBLE_VALUE, 42 description=""): 43 self.type = type 44 self.vType = vType 45 self.line = line 46 self.destStop = destStop 47 self.edges = edges 48 self.travelTime = travelTime 49 self.cost = cost 50 self.length = length 51 self.intended = intended 52 self.depart = depart 53 self.departPos = departPos 54 self.arrivalPos = arrivalPos 55 self.description = description 56 57 def __attr_repr__(self, attrname, default=""): 58 if getattr(self, attrname) == default: 59 return "" 60 else: 61 val = getattr(self, attrname) 62 if val == tc.INVALID_DOUBLE_VALUE: 63 val = "INVALID" 64 return "%s=%s" % (attrname, val) 65 66 def __repr__(self): 67 return "Stage(%s)" % ', '.join([v for v in [ 68 self.__attr_repr__("type"), 69 self.__attr_repr__("vType"), 70 self.__attr_repr__("line"), 71 self.__attr_repr__("destStop"), 72 self.__attr_repr__("edges"), 73 self.__attr_repr__("travelTime"), 74 self.__attr_repr__("cost"), 75 self.__attr_repr__("length"), 76 self.__attr_repr__("intended"), 77 self.__attr_repr__("depart"), 78 self.__attr_repr__("departPos"), 79 self.__attr_repr__("arrivalPos"), 80 self.__attr_repr__("description"), 81 ] if v != ""]) 82 83 def toXML(self, firstStage=True, isPerson=True, extra=[]): 84 """write stage as xml element. 85 If firstStage=False, the from-attribute is omitted since sumo derives it from the prior stage. 86 If extra is a list of (attrname, value) these will be added to the xml element 87 """ 88 if self.type == tc.STAGE_WAITING: 89 to = ' edge="%s" endPos="%.2f"' % (self.edges[-1], self.arrivalPos) 90 if self.destStop: 91 to = ' busStop="%s"' % self.destStop 92 other = '' 93 if self.travelTime >= 0: 94 other += ' duration="%s"' % self.travelTime 95 other += ''.join([' %s="%s"' % i for i in extra]) 96 return '<stop%s%s/>' % (to, other) 97 98 elif self.type == tc.STAGE_DRIVING: 99 fro = ' from="%s"' % self.edges[0] if firstStage else '' 100 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 101 if self.destStop: 102 to = ' busStop="%s"' % self.destStop 103 elem = "ride" if isPerson else "transport" 104 other = '' 105 if self.line: 106 other += ' lines="%s"' % self.line 107 if self.intended: 108 other += ' intended="%s"' % self.intended 109 if self.depart != tc.INVALID_DOUBLE_VALUE: 110 other += ' depart="%s"' % self.depart 111 other += ''.join([' %s="%s"' % i for i in extra]) 112 return '<%s%s%s%s/>' % (elem, fro, to, other) 113 114 elif self.type == tc.STAGE_WALKING: 115 to = ' arrivalPos="%.2f"' % self.arrivalPos 116 if self.destStop: 117 to = ' busStop="%s"' % self.destStop 118 edges = ' edges="%s"' % ' '.join(self.edges) 119 other = ''.join([' %s="%s"' % i for i in extra]) 120 return '<walk%s%s%s/>' % (edges, to, other) 121 122 elif self.type == tc.STAGE_TRIP: 123 fro = ' from="%s"' % self.edges[0] if firstStage else '' 124 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 125 if self.destStop: 126 to = ' busStop="%s"' % self.destStop 127 other = '' 128 if self.vType: 129 other += ' vTypes="%s"' % self.vType 130 other += ''.join([' %s="%s"' % i for i in extra]) 131 return '<personTrip%s%s%s/>' % (fro, to, other) 132 133 elif self.type == tc.STAGE_TRANSHIP: 134 fro = ' from="%s"' % self.edges[0] if firstStage else '' 135 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 136 if self.destStop: 137 to = ' busStop="%s"' % self.destStop 138 other = ''.join([' %s="%s"' % i for i in extra]) 139 return '<tranship%s%s%s/>' % (fro, to, other) 140 141 else: 142 # STAGE_ACCESS and STAGE_WAITING_FOR_DEPART are never read from xml 143 # print("unwritten stage: ", self.type) 144 return "" 145 146 147def _readStage(result): 148 # compound size and type 149 assert result.read("!i")[0] == 13 150 stageType = result.readTypedInt() 151 vType = result.readTypedString() 152 line = result.readTypedString() 153 destStop = result.readTypedString() 154 edges = result.readTypedStringList() 155 travelTime = result.readTypedDouble() 156 cost = result.readTypedDouble() 157 length = result.readTypedDouble() 158 intended = result.readTypedString() 159 depart = result.readTypedDouble() 160 departPos = result.readTypedDouble() 161 arrivalPos = result.readTypedDouble() 162 description = result.readTypedString() 163 return Stage(stageType, vType, line, destStop, edges, travelTime, cost, 164 length, intended, depart, departPos, arrivalPos, description) 165 166 167def _writeStage(stage): 168 format = "tisssldddsddds" 169 values = [13, stage.type, stage.vType, stage.line, stage.destStop, stage.edges, 170 stage.travelTime, stage.cost, stage.length, stage.intended, 171 stage.depart, stage.departPos, stage.arrivalPos, stage.description] 172 return format, values 173 174 175class Collision(object): 176 177 def __init__(self, collider, victim, colliderType, victimType, 178 colliderSpeed, victimSpeed, collisionType, lane, pos): 179 self.collider = collider 180 self.victim = victim 181 self.colliderType = colliderType 182 self.victimType = victimType 183 self.colliderSpeed = colliderSpeed 184 self.victimSpeed = victimSpeed 185 self.type = collisionType 186 self.lane = lane 187 self.pos = pos 188 189 def __attr_repr__(self, attrname, default=""): 190 if getattr(self, attrname) == default: 191 return "" 192 else: 193 val = getattr(self, attrname) 194 if val == tc.INVALID_DOUBLE_VALUE: 195 val = "INVALID" 196 return "%s=%s" % (attrname, val) 197 198 def __repr__(self): 199 return "Collision(%s)" % ', '.join([v for v in [ 200 self.__attr_repr__("collider"), 201 self.__attr_repr__("victim"), 202 self.__attr_repr__("colliderType"), 203 self.__attr_repr__("victimType"), 204 self.__attr_repr__("colliderSpeed"), 205 self.__attr_repr__("victimSpeed"), 206 self.__attr_repr__("type"), 207 self.__attr_repr__("lane"), 208 self.__attr_repr__("pos"), 209 ] if v != ""]) 210 211 212def _readCollisions(result): 213 result.read("!iB") # numCompounds, TYPE_INT 214 n = result.read("!i")[0] 215 values = [] 216 for _ in range(n): 217 collider = result.readTypedString() 218 victim = result.readTypedString() 219 colliderType = result.readTypedString() 220 victimType = result.readTypedString() 221 colliderSpeed = result.readTypedDouble() 222 victimSpeed = result.readTypedDouble() 223 collisionType = result.readTypedString() 224 lane = result.readTypedString() 225 pos = result.readTypedDouble() 226 values.append(Collision(collider, victim, colliderType, victimType, 227 colliderSpeed, victimSpeed, collisionType, lane, pos)) 228 229 return tuple(values) 230 231 232_RETURN_VALUE_FUNC = { 233 tc.FIND_ROUTE: _readStage, 234 tc.VAR_COLLISIONS: _readCollisions 235} 236 237 238class SimulationDomain(Domain): 239 240 Stage = Stage 241 242 def __init__(self): 243 Domain.__init__(self, "simulation", tc.CMD_GET_SIM_VARIABLE, tc.CMD_SET_SIM_VARIABLE, 244 tc.CMD_SUBSCRIBE_SIM_VARIABLE, tc.RESPONSE_SUBSCRIBE_SIM_VARIABLE, 245 tc.CMD_SUBSCRIBE_SIM_CONTEXT, tc.RESPONSE_SUBSCRIBE_SIM_CONTEXT, 246 _RETURN_VALUE_FUNC) 247 248 @staticmethod 249 def walkingStage(edges, arrivalPos, destStop="", description=""): 250 return Stage(2, "", "", destStop, edges, 0, 0, 0, "", 0, 0, arrivalPos, description) 251 252 def getTime(self): 253 """getTime() -> double 254 255 Returns the current simulation time in s. 256 """ 257 return self._getUniversal(tc.VAR_TIME) 258 259 def getEndTime(self): 260 """getEndTime() -> double 261 262 Returns the configured end time of the simulation in s or -1 263 """ 264 return self._getUniversal(tc.VAR_END) 265 266 def step(self, time=0.): 267 """step(double) -> None 268 Make a simulation step and simulate up to the given sim time (in seconds). 269 If the given value is 0 or absent, exactly one step is performed. 270 Values smaller than or equal to the current sim time result in no action. 271 """ 272 if self._connection is None: 273 raise FatalTraCIError("Not connected.") 274 self._connection.simulationStep(time) 275 276 def executeMove(self): 277 """executeMove() -> None 278 Make "half" a simulation step. 279 """ 280 if self._connection is None: 281 raise FatalTraCIError("Not connected.") 282 self._connection._sendCmd(tc.CMD_EXECUTEMOVE, None, None) 283 284 def getCurrentTime(self): 285 """getCurrentTime() -> integer 286 287 Returns the current simulation time in ms. 288 """ 289 warnings.warn("getCurrentTime is deprecated, please use getTime which returns floating point seconds", 290 stacklevel=2) 291 return self._getUniversal(tc.VAR_TIME_STEP) 292 293 def getLoadedNumber(self): 294 """getLoadedNumber() -> integer 295 296 Returns the number of vehicles which were loaded in this time step. 297 """ 298 return self._getUniversal(tc.VAR_LOADED_VEHICLES_NUMBER) 299 300 def getLoadedIDList(self): 301 """getLoadedIDList() -> tuple(string) 302 303 Returns a tuple of ids of vehicles which were loaded in this time step. 304 """ 305 return self._getUniversal(tc.VAR_LOADED_VEHICLES_IDS) 306 307 def getDepartedNumber(self): 308 """getDepartedNumber() -> integer 309 310 Returns the number of vehicles which departed (were inserted into the road network) in this time step. 311 """ 312 return self._getUniversal(tc.VAR_DEPARTED_VEHICLES_NUMBER) 313 314 def getDepartedIDList(self): 315 """getDepartedIDList() -> tuple(string) 316 317 Returns a tuple of ids of vehicles which departed (were inserted into the road network) in this time step. 318 """ 319 return self._getUniversal(tc.VAR_DEPARTED_VEHICLES_IDS) 320 321 def getArrivedNumber(self): 322 """getArrivedNumber() -> integer 323 324 Returns the number of vehicles which arrived (have reached their destination and are removed from the road 325 network) in this time step. 326 """ 327 return self._getUniversal(tc.VAR_ARRIVED_VEHICLES_NUMBER) 328 329 def getArrivedIDList(self): 330 """getArrivedIDList() -> tuple(string) 331 332 Returns a tuple of ids of vehicles which arrived (have reached their destination and are removed from the road 333 network) in this time step. 334 """ 335 return self._getUniversal(tc.VAR_ARRIVED_VEHICLES_IDS) 336 337 def getDepartedPersonNumber(self): 338 """getDepartedPersonNumber() -> integer 339 340 Returns the number of persons which departed (were inserted into the road network) in this time step. 341 """ 342 return self._getUniversal(tc.VAR_DEPARTED_PERSONS_NUMBER) 343 344 def getDepartedPersonIDList(self): 345 """getDepartedPersonIDList() -> tuple(string) 346 347 Returns a tuple of ids of persons which departed (were inserted into the road network) in this time step. 348 """ 349 return self._getUniversal(tc.VAR_DEPARTED_PERSONS_IDS) 350 351 def getArrivedPersonNumber(self): 352 """getArrivedPersonNumber() -> integer 353 354 Returns the number of persons which arrived (have reached their destination and are removed from the road 355 network) in this time step. 356 """ 357 return self._getUniversal(tc.VAR_ARRIVED_PERSONS_NUMBER) 358 359 def getArrivedPersonIDList(self): 360 """getArrivedPersonIDList() -> tuple(string) 361 362 Returns a tuple of ids of persons which arrived (have reached their destination and are removed from the road 363 network) in this time step. 364 """ 365 return self._getUniversal(tc.VAR_ARRIVED_PERSONS_IDS) 366 367 def getParkingStartingVehiclesNumber(self): 368 """getParkingStartingVehiclesNumber() -> integer 369 370 . 371 """ 372 return self._getUniversal(tc.VAR_PARKING_STARTING_VEHICLES_NUMBER) 373 374 def getParkingStartingVehiclesIDList(self): 375 """getParkingStartingVehiclesIDList() -> tuple(string) 376 377 . 378 """ 379 return self._getUniversal(tc.VAR_PARKING_STARTING_VEHICLES_IDS) 380 381 def getParkingEndingVehiclesNumber(self): 382 """getParkingEndingVehiclesNumber() -> integer 383 384 . 385 """ 386 return self._getUniversal(tc.VAR_PARKING_ENDING_VEHICLES_NUMBER) 387 388 def getParkingEndingVehiclesIDList(self): 389 """getParkingEndingVehiclesIDList() -> tuple(string) 390 391 . 392 """ 393 return self._getUniversal(tc.VAR_PARKING_ENDING_VEHICLES_IDS) 394 395 def getStopStartingVehiclesNumber(self): 396 """getStopStartingVehiclesNumber() -> integer 397 398 . 399 """ 400 return self._getUniversal(tc.VAR_STOP_STARTING_VEHICLES_NUMBER) 401 402 def getStopStartingVehiclesIDList(self): 403 """getStopStartingVehiclesIDList() -> tuple(string) 404 405 . 406 """ 407 return self._getUniversal(tc.VAR_STOP_STARTING_VEHICLES_IDS) 408 409 def getStopEndingVehiclesNumber(self): 410 """getStopEndingVehiclesNumber() -> integer 411 412 . 413 """ 414 return self._getUniversal(tc.VAR_STOP_ENDING_VEHICLES_NUMBER) 415 416 def getStopEndingVehiclesIDList(self): 417 """getStopEndingVehiclesIDList() -> tuple(string) 418 419 . 420 """ 421 return self._getUniversal(tc.VAR_STOP_ENDING_VEHICLES_IDS) 422 423 def getCollidingVehiclesNumber(self): 424 """getCollidingVehiclesNumber() -> integer 425 Return number of vehicles involved in a collision (typically 2 per 426 collision). 427 """ 428 return self._getUniversal(tc.VAR_COLLIDING_VEHICLES_NUMBER) 429 430 def getCollidingVehiclesIDList(self): 431 """getCollidingVehiclesIDList() -> tuple(string) 432 Return Ids of vehicles involved in a collision (typically 2 per 433 collision). 434 """ 435 return self._getUniversal(tc.VAR_COLLIDING_VEHICLES_IDS) 436 437 def getEmergencyStoppingVehiclesNumber(self): 438 """getEmergencyStoppingVehiclesNumber() -> integer 439 Return number of vehicles that performed an emergency stop in the last step 440 """ 441 return self._getUniversal(tc.VAR_EMERGENCYSTOPPING_VEHICLES_NUMBER) 442 443 def getEmergencyStoppingVehiclesIDList(self): 444 """getEmergencyStoppingVehiclesIDList() -> tuple(string) 445 Return Ids of vehicles that peformed an emergency stop in the last step 446 """ 447 return self._getUniversal(tc.VAR_EMERGENCYSTOPPING_VEHICLES_IDS) 448 449 def getMinExpectedNumber(self): 450 """getMinExpectedNumber() -> integer 451 Returns the number of all active vehicles and persons which are in the net plus the 452 ones still waiting to start. Vehicles and persons currently stopped with a 453 'trigger' are excluded from this number (if only triggered objects 454 remain, the trigger condition cannot be fulfilled and all objects remain 455 stopped without user intervention). 456 The returned number may also be smaller than 457 the actual number of vehicles still to come because of delayed 458 route file parsing. If the number is 0 however, it is 459 guaranteed that all route files have been parsed completely. 460 """ 461 return self._getUniversal(tc.VAR_MIN_EXPECTED_VEHICLES) 462 463 @deprecated("busstop.getIDList") 464 def getBusStopIDList(self): 465 return self._getUniversal(tc.VAR_BUS_STOP_ID_LIST) 466 467 @deprecated("busstop.getPersonCount") 468 def getBusStopWaiting(self, stopID): 469 """getBusStopWaiting() -> integer 470 Get the total number of waiting persons at the named bus stop. 471 """ 472 return self._getUniversal(tc.VAR_BUS_STOP_WAITING, stopID) 473 474 @deprecated("busstop.getPersonIDs") 475 def getBusStopWaitingIDList(self, stopID): 476 """getBusStopWaiting() -> tuple(string) 477 Get the IDs of waiting persons at the named bus stop. 478 """ 479 return self._getUniversal(tc.VAR_BUS_STOP_WAITING_IDS, stopID) 480 481 def getStartingTeleportNumber(self): 482 """getStartingTeleportNumber() -> integer 483 484 Returns the number of vehicles which started to teleport in this time step. 485 """ 486 return self._getUniversal(tc.VAR_TELEPORT_STARTING_VEHICLES_NUMBER) 487 488 def getStartingTeleportIDList(self): 489 """getStartingTeleportIDList() -> tuple(string) 490 491 Returns a tuple of ids of vehicles which started to teleport in this time step. 492 """ 493 return self._getUniversal(tc.VAR_TELEPORT_STARTING_VEHICLES_IDS) 494 495 def getEndingTeleportNumber(self): 496 """getEndingTeleportNumber() -> integer 497 498 Returns the number of vehicles which ended to be teleported in this time step. 499 """ 500 return self._getUniversal(tc.VAR_TELEPORT_ENDING_VEHICLES_NUMBER) 501 502 def getEndingTeleportIDList(self): 503 """getEndingTeleportIDList() -> tuple(string) 504 505 Returns a tuple of ids of vehicles which ended to be teleported in this time step. 506 """ 507 return self._getUniversal(tc.VAR_TELEPORT_ENDING_VEHICLES_IDS) 508 509 def getCollisions(self): 510 """getCollisions() -> tuple(Collision) 511 Returns a tuple of collision objects 512 """ 513 return self._getUniversal(tc.VAR_COLLISIONS) 514 515 def getPendingVehicles(self): 516 """getPendingVehicles() -> tuple(string) 517 Returns a tuple of all vehicle ids waiting for insertion (with depart delay) 518 """ 519 return self._getUniversal(tc.VAR_PENDING_VEHICLES) 520 521 def getScale(self): 522 """getScale() -> double 523 524 Returns the traffic scaling factor 525 """ 526 return self._getUniversal(tc.VAR_SCALE) 527 528 def getOption(self, option): 529 """getOption(string) -> string 530 531 Returns the value of the given SUMO option 532 """ 533 return self._getUniversal(tc.VAR_OPTION, option) 534 535 def getDeltaT(self): 536 """getDeltaT() -> double 537 Returns the length of one simulation step in seconds 538 """ 539 return self._getUniversal(tc.VAR_DELTA_T) 540 541 def getNetBoundary(self): 542 """getNetBoundary() -> ((double, double), (double, double)) 543 544 The boundary box of the simulation network. 545 """ 546 return self._getUniversal(tc.VAR_NET_BOUNDING_BOX) 547 548 def convert2D(self, edgeID, pos, laneIndex=0, toGeo=False): 549 posType = tc.POSITION_2D 550 if toGeo: 551 posType = tc.POSITION_LON_LAT 552 return self._getUniversal(tc.POSITION_CONVERSION, "", "trB", 2, (edgeID, pos, laneIndex), posType) 553 554 def convert3D(self, edgeID, pos, laneIndex=0, toGeo=False): 555 posType = tc.POSITION_3D 556 if toGeo: 557 posType = tc.POSITION_LON_LAT_ALT 558 return self._getUniversal(tc.POSITION_CONVERSION, "", "trB", 2, (edgeID, pos, laneIndex), posType) 559 560 def convertRoad(self, x, y, isGeo=False, vClass="ignoring"): 561 format = "toBs" 562 if isGeo: 563 format = "tgBs" 564 result = self._getCmd(tc.POSITION_CONVERSION, "", format, 3, (x, y), tc.POSITION_ROADMAP, vClass) 565 result.read("!B") 566 return result.readString(), result.readDouble(), result.read("!B")[0] 567 568 def convertGeo(self, x, y, fromGeo=False): 569 format = "toB" 570 toType = tc.POSITION_LON_LAT 571 if fromGeo: 572 format = "tgB" 573 toType = tc.POSITION_2D 574 return self._getUniversal(tc.POSITION_CONVERSION, "", format, 2, (x, y), toType) 575 576 def getDistance2D(self, x1, y1, x2, y2, isGeo=False, isDriving=False): 577 """getDistance2D(double, double, double, double, boolean, boolean) -> double 578 579 Returns the distance between the two coordinate pairs (x1,y1) and (x2,y2) 580 581 If isGeo=True, coordinates are interpreted as longitude and latitude rather 582 than cartesian coordinates in meters. 583 584 If isDriving=True, the coordinates are mapped onto the road network and the 585 length of the shortest route in the network is returned. Otherwise, the 586 straight-line distance is returned. 587 """ 588 format = "tggu" if isGeo else "toou" 589 distType = tc.REQUEST_AIRDIST 590 if isDriving: 591 distType = tc.REQUEST_DRIVINGDIST 592 return self._getUniversal(tc.DISTANCE_REQUEST, "", format, 3, (x1, y1), (x2, y2), distType) 593 594 def getDistanceRoad(self, edgeID1, pos1, edgeID2, pos2, isDriving=False): 595 """getDistanceRoad(string, double, string, double, boolean) -> double 596 597 Reads two positions on the road network and an indicator whether the air or the driving distance shall be 598 computed. Returns the according distance. 599 """ 600 distType = tc.REQUEST_AIRDIST 601 if isDriving: 602 distType = tc.REQUEST_DRIVINGDIST 603 return self._getUniversal(tc.DISTANCE_REQUEST, "", "trru", 3, 604 (edgeID1, pos1, 0), (edgeID2, pos2, 0), distType) 605 606 def findRoute(self, fromEdge, toEdge, vType="", depart=-1., routingMode=0, 607 departPos=0., arrivalPos=tc.INVALID_DOUBLE_VALUE): 608 """findRoute(string, string, string, double, int, double, double) -> Stage 609 Computes the fastest route between the given edges for the given vehicle 610 type (defaults to DEFAULT_VEHTYPE) 611 Returns a Stage object that holds the edge list and the travel time 612 When the depart time is not set, the travel times at the current time 613 will be used. The routing mode may be ROUTING_MODE_DEFAULT (loaded or 614 default speeds) and ROUTING_MODE_AGGREGATED (averaged historical speeds) 615 """ 616 return self._getUniversal(tc.FIND_ROUTE, "", "tsssdidd", 7, fromEdge, toEdge, vType, depart, 617 routingMode, departPos, arrivalPos) 618 619 def findIntermodalRoute(self, fromEdge, toEdge, modes="", depart=-1., routingMode=0, speed=-1., 620 walkFactor=-1., departPos=0., arrivalPos=tc.INVALID_DOUBLE_VALUE, departPosLat=0., 621 pType="", vType="", destStop=""): 622 """findIntermodalRoute(string, string, string, double, int, double, 623 double, double, double, double, string, string, string) -> tuple(Stage) 624 Computes the fastest intermoal route between the given edges for the 625 given combination of transport modes (i.e. "car public" may result in 626 driving to the train station and then riding the train). 627 Returns a tuple of Stage objects that correspond to the sequence of walks 628 and rides to reach the destination. 629 When the depart time is not set, the travel times at the current time will be used. 630 The routing mode may be ROUTING_MODE_DEFAULT (loaded or 631 default speeds) and ROUTING_MODE_AGGREGATED (averaged historical speeds) 632 pType defines the pedestrian type (for walking speed) and defaults to 633 DEFAULT_PEDTYPE. 634 walkFactor is a multiplier for the walking speed to 635 account for delays due to intersections and other traffic when 636 determining the feasibility of using a particular public transport 637 vehicle. 638 vType is an optional vehicle type to use for private car routing. 639 destStop can be used as an alternative to 'toEdge' to define the edge 640 and position of the specified public transport stop as the destination 641 """ 642 answer = self._getCmd(tc.FIND_INTERMODAL_ROUTE, "", "tsssdidddddsss", 13, 643 fromEdge, toEdge, modes, depart, routingMode, speed, walkFactor, 644 departPos, arrivalPos, departPosLat, pType, vType, destStop) 645 answer.read("!B") # Type 646 result = [] 647 for _ in range(answer.readInt()): 648 answer.read("!B") # Type 649 result.append(_readStage(answer)) 650 return tuple(result) 651 652 def setScale(self, value): 653 """setScale(value) -> None 654 655 Sets the traffic scaling factor 656 """ 657 self._setCmd(tc.VAR_SCALE, "", "d", value) 658 659 def clearPending(self, routeID=""): 660 self._setCmd(tc.CMD_CLEAR_PENDING_VEHICLES, "", "s", routeID) 661 662 def saveState(self, fileName): 663 self._setCmd(tc.CMD_SAVE_SIMSTATE, "", "s", fileName) 664 665 def loadState(self, fileName): 666 self._setCmd(tc.CMD_LOAD_SIMSTATE, "", "s", fileName) 667 668 def writeMessage(self, msg): 669 self._setCmd(tc.CMD_MESSAGE, "", "s", msg) 670 671 def subscribe(self, varIDs=(tc.VAR_DEPARTED_VEHICLES_IDS,), begin=0, end=2**31 - 1, parameters=None): 672 """subscribe(list(integer), double, double, map) -> None 673 674 Subscribe to one or more simulation values for the given interval. 675 """ 676 Domain.subscribe(self, "", varIDs, begin, end, parameters) 677 678 def getSubscriptionResults(self): 679 """getSubscriptionResults() -> dict(integer: <value_type>) 680 681 Returns the subscription results for the last time step. 682 It is not possible to retrieve older subscription results than the ones 683 from the last time step. 684 """ 685 return Domain.getSubscriptionResults(self, "")
28class Stage(object): 29 30 def __init__(self, 31 type=tc.INVALID_INT_VALUE, 32 vType="", 33 line="", 34 destStop="", 35 edges=[], 36 travelTime=tc.INVALID_DOUBLE_VALUE, 37 cost=tc.INVALID_DOUBLE_VALUE, 38 length=tc.INVALID_DOUBLE_VALUE, 39 intended="", 40 depart=tc.INVALID_DOUBLE_VALUE, 41 departPos=tc.INVALID_DOUBLE_VALUE, 42 arrivalPos=tc.INVALID_DOUBLE_VALUE, 43 description=""): 44 self.type = type 45 self.vType = vType 46 self.line = line 47 self.destStop = destStop 48 self.edges = edges 49 self.travelTime = travelTime 50 self.cost = cost 51 self.length = length 52 self.intended = intended 53 self.depart = depart 54 self.departPos = departPos 55 self.arrivalPos = arrivalPos 56 self.description = description 57 58 def __attr_repr__(self, attrname, default=""): 59 if getattr(self, attrname) == default: 60 return "" 61 else: 62 val = getattr(self, attrname) 63 if val == tc.INVALID_DOUBLE_VALUE: 64 val = "INVALID" 65 return "%s=%s" % (attrname, val) 66 67 def __repr__(self): 68 return "Stage(%s)" % ', '.join([v for v in [ 69 self.__attr_repr__("type"), 70 self.__attr_repr__("vType"), 71 self.__attr_repr__("line"), 72 self.__attr_repr__("destStop"), 73 self.__attr_repr__("edges"), 74 self.__attr_repr__("travelTime"), 75 self.__attr_repr__("cost"), 76 self.__attr_repr__("length"), 77 self.__attr_repr__("intended"), 78 self.__attr_repr__("depart"), 79 self.__attr_repr__("departPos"), 80 self.__attr_repr__("arrivalPos"), 81 self.__attr_repr__("description"), 82 ] if v != ""]) 83 84 def toXML(self, firstStage=True, isPerson=True, extra=[]): 85 """write stage as xml element. 86 If firstStage=False, the from-attribute is omitted since sumo derives it from the prior stage. 87 If extra is a list of (attrname, value) these will be added to the xml element 88 """ 89 if self.type == tc.STAGE_WAITING: 90 to = ' edge="%s" endPos="%.2f"' % (self.edges[-1], self.arrivalPos) 91 if self.destStop: 92 to = ' busStop="%s"' % self.destStop 93 other = '' 94 if self.travelTime >= 0: 95 other += ' duration="%s"' % self.travelTime 96 other += ''.join([' %s="%s"' % i for i in extra]) 97 return '<stop%s%s/>' % (to, other) 98 99 elif self.type == tc.STAGE_DRIVING: 100 fro = ' from="%s"' % self.edges[0] if firstStage else '' 101 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 102 if self.destStop: 103 to = ' busStop="%s"' % self.destStop 104 elem = "ride" if isPerson else "transport" 105 other = '' 106 if self.line: 107 other += ' lines="%s"' % self.line 108 if self.intended: 109 other += ' intended="%s"' % self.intended 110 if self.depart != tc.INVALID_DOUBLE_VALUE: 111 other += ' depart="%s"' % self.depart 112 other += ''.join([' %s="%s"' % i for i in extra]) 113 return '<%s%s%s%s/>' % (elem, fro, to, other) 114 115 elif self.type == tc.STAGE_WALKING: 116 to = ' arrivalPos="%.2f"' % self.arrivalPos 117 if self.destStop: 118 to = ' busStop="%s"' % self.destStop 119 edges = ' edges="%s"' % ' '.join(self.edges) 120 other = ''.join([' %s="%s"' % i for i in extra]) 121 return '<walk%s%s%s/>' % (edges, to, other) 122 123 elif self.type == tc.STAGE_TRIP: 124 fro = ' from="%s"' % self.edges[0] if firstStage else '' 125 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 126 if self.destStop: 127 to = ' busStop="%s"' % self.destStop 128 other = '' 129 if self.vType: 130 other += ' vTypes="%s"' % self.vType 131 other += ''.join([' %s="%s"' % i for i in extra]) 132 return '<personTrip%s%s%s/>' % (fro, to, other) 133 134 elif self.type == tc.STAGE_TRANSHIP: 135 fro = ' from="%s"' % self.edges[0] if firstStage else '' 136 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 137 if self.destStop: 138 to = ' busStop="%s"' % self.destStop 139 other = ''.join([' %s="%s"' % i for i in extra]) 140 return '<tranship%s%s%s/>' % (fro, to, other) 141 142 else: 143 # STAGE_ACCESS and STAGE_WAITING_FOR_DEPART are never read from xml 144 # print("unwritten stage: ", self.type) 145 return ""
30 def __init__(self, 31 type=tc.INVALID_INT_VALUE, 32 vType="", 33 line="", 34 destStop="", 35 edges=[], 36 travelTime=tc.INVALID_DOUBLE_VALUE, 37 cost=tc.INVALID_DOUBLE_VALUE, 38 length=tc.INVALID_DOUBLE_VALUE, 39 intended="", 40 depart=tc.INVALID_DOUBLE_VALUE, 41 departPos=tc.INVALID_DOUBLE_VALUE, 42 arrivalPos=tc.INVALID_DOUBLE_VALUE, 43 description=""): 44 self.type = type 45 self.vType = vType 46 self.line = line 47 self.destStop = destStop 48 self.edges = edges 49 self.travelTime = travelTime 50 self.cost = cost 51 self.length = length 52 self.intended = intended 53 self.depart = depart 54 self.departPos = departPos 55 self.arrivalPos = arrivalPos 56 self.description = description
84 def toXML(self, firstStage=True, isPerson=True, extra=[]): 85 """write stage as xml element. 86 If firstStage=False, the from-attribute is omitted since sumo derives it from the prior stage. 87 If extra is a list of (attrname, value) these will be added to the xml element 88 """ 89 if self.type == tc.STAGE_WAITING: 90 to = ' edge="%s" endPos="%.2f"' % (self.edges[-1], self.arrivalPos) 91 if self.destStop: 92 to = ' busStop="%s"' % self.destStop 93 other = '' 94 if self.travelTime >= 0: 95 other += ' duration="%s"' % self.travelTime 96 other += ''.join([' %s="%s"' % i for i in extra]) 97 return '<stop%s%s/>' % (to, other) 98 99 elif self.type == tc.STAGE_DRIVING: 100 fro = ' from="%s"' % self.edges[0] if firstStage else '' 101 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 102 if self.destStop: 103 to = ' busStop="%s"' % self.destStop 104 elem = "ride" if isPerson else "transport" 105 other = '' 106 if self.line: 107 other += ' lines="%s"' % self.line 108 if self.intended: 109 other += ' intended="%s"' % self.intended 110 if self.depart != tc.INVALID_DOUBLE_VALUE: 111 other += ' depart="%s"' % self.depart 112 other += ''.join([' %s="%s"' % i for i in extra]) 113 return '<%s%s%s%s/>' % (elem, fro, to, other) 114 115 elif self.type == tc.STAGE_WALKING: 116 to = ' arrivalPos="%.2f"' % self.arrivalPos 117 if self.destStop: 118 to = ' busStop="%s"' % self.destStop 119 edges = ' edges="%s"' % ' '.join(self.edges) 120 other = ''.join([' %s="%s"' % i for i in extra]) 121 return '<walk%s%s%s/>' % (edges, to, other) 122 123 elif self.type == tc.STAGE_TRIP: 124 fro = ' from="%s"' % self.edges[0] if firstStage else '' 125 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 126 if self.destStop: 127 to = ' busStop="%s"' % self.destStop 128 other = '' 129 if self.vType: 130 other += ' vTypes="%s"' % self.vType 131 other += ''.join([' %s="%s"' % i for i in extra]) 132 return '<personTrip%s%s%s/>' % (fro, to, other) 133 134 elif self.type == tc.STAGE_TRANSHIP: 135 fro = ' from="%s"' % self.edges[0] if firstStage else '' 136 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 137 if self.destStop: 138 to = ' busStop="%s"' % self.destStop 139 other = ''.join([' %s="%s"' % i for i in extra]) 140 return '<tranship%s%s%s/>' % (fro, to, other) 141 142 else: 143 # STAGE_ACCESS and STAGE_WAITING_FOR_DEPART are never read from xml 144 # print("unwritten stage: ", self.type) 145 return ""
write stage as xml element. If firstStage=False, the from-attribute is omitted since sumo derives it from the prior stage. If extra is a list of (attrname, value) these will be added to the xml element
176class Collision(object): 177 178 def __init__(self, collider, victim, colliderType, victimType, 179 colliderSpeed, victimSpeed, collisionType, lane, pos): 180 self.collider = collider 181 self.victim = victim 182 self.colliderType = colliderType 183 self.victimType = victimType 184 self.colliderSpeed = colliderSpeed 185 self.victimSpeed = victimSpeed 186 self.type = collisionType 187 self.lane = lane 188 self.pos = pos 189 190 def __attr_repr__(self, attrname, default=""): 191 if getattr(self, attrname) == default: 192 return "" 193 else: 194 val = getattr(self, attrname) 195 if val == tc.INVALID_DOUBLE_VALUE: 196 val = "INVALID" 197 return "%s=%s" % (attrname, val) 198 199 def __repr__(self): 200 return "Collision(%s)" % ', '.join([v for v in [ 201 self.__attr_repr__("collider"), 202 self.__attr_repr__("victim"), 203 self.__attr_repr__("colliderType"), 204 self.__attr_repr__("victimType"), 205 self.__attr_repr__("colliderSpeed"), 206 self.__attr_repr__("victimSpeed"), 207 self.__attr_repr__("type"), 208 self.__attr_repr__("lane"), 209 self.__attr_repr__("pos"), 210 ] if v != ""])
178 def __init__(self, collider, victim, colliderType, victimType, 179 colliderSpeed, victimSpeed, collisionType, lane, pos): 180 self.collider = collider 181 self.victim = victim 182 self.colliderType = colliderType 183 self.victimType = victimType 184 self.colliderSpeed = colliderSpeed 185 self.victimSpeed = victimSpeed 186 self.type = collisionType 187 self.lane = lane 188 self.pos = pos
239class SimulationDomain(Domain): 240 241 Stage = Stage 242 243 def __init__(self): 244 Domain.__init__(self, "simulation", tc.CMD_GET_SIM_VARIABLE, tc.CMD_SET_SIM_VARIABLE, 245 tc.CMD_SUBSCRIBE_SIM_VARIABLE, tc.RESPONSE_SUBSCRIBE_SIM_VARIABLE, 246 tc.CMD_SUBSCRIBE_SIM_CONTEXT, tc.RESPONSE_SUBSCRIBE_SIM_CONTEXT, 247 _RETURN_VALUE_FUNC) 248 249 @staticmethod 250 def walkingStage(edges, arrivalPos, destStop="", description=""): 251 return Stage(2, "", "", destStop, edges, 0, 0, 0, "", 0, 0, arrivalPos, description) 252 253 def getTime(self): 254 """getTime() -> double 255 256 Returns the current simulation time in s. 257 """ 258 return self._getUniversal(tc.VAR_TIME) 259 260 def getEndTime(self): 261 """getEndTime() -> double 262 263 Returns the configured end time of the simulation in s or -1 264 """ 265 return self._getUniversal(tc.VAR_END) 266 267 def step(self, time=0.): 268 """step(double) -> None 269 Make a simulation step and simulate up to the given sim time (in seconds). 270 If the given value is 0 or absent, exactly one step is performed. 271 Values smaller than or equal to the current sim time result in no action. 272 """ 273 if self._connection is None: 274 raise FatalTraCIError("Not connected.") 275 self._connection.simulationStep(time) 276 277 def executeMove(self): 278 """executeMove() -> None 279 Make "half" a simulation step. 280 """ 281 if self._connection is None: 282 raise FatalTraCIError("Not connected.") 283 self._connection._sendCmd(tc.CMD_EXECUTEMOVE, None, None) 284 285 def getCurrentTime(self): 286 """getCurrentTime() -> integer 287 288 Returns the current simulation time in ms. 289 """ 290 warnings.warn("getCurrentTime is deprecated, please use getTime which returns floating point seconds", 291 stacklevel=2) 292 return self._getUniversal(tc.VAR_TIME_STEP) 293 294 def getLoadedNumber(self): 295 """getLoadedNumber() -> integer 296 297 Returns the number of vehicles which were loaded in this time step. 298 """ 299 return self._getUniversal(tc.VAR_LOADED_VEHICLES_NUMBER) 300 301 def getLoadedIDList(self): 302 """getLoadedIDList() -> tuple(string) 303 304 Returns a tuple of ids of vehicles which were loaded in this time step. 305 """ 306 return self._getUniversal(tc.VAR_LOADED_VEHICLES_IDS) 307 308 def getDepartedNumber(self): 309 """getDepartedNumber() -> integer 310 311 Returns the number of vehicles which departed (were inserted into the road network) in this time step. 312 """ 313 return self._getUniversal(tc.VAR_DEPARTED_VEHICLES_NUMBER) 314 315 def getDepartedIDList(self): 316 """getDepartedIDList() -> tuple(string) 317 318 Returns a tuple of ids of vehicles which departed (were inserted into the road network) in this time step. 319 """ 320 return self._getUniversal(tc.VAR_DEPARTED_VEHICLES_IDS) 321 322 def getArrivedNumber(self): 323 """getArrivedNumber() -> integer 324 325 Returns the number of vehicles which arrived (have reached their destination and are removed from the road 326 network) in this time step. 327 """ 328 return self._getUniversal(tc.VAR_ARRIVED_VEHICLES_NUMBER) 329 330 def getArrivedIDList(self): 331 """getArrivedIDList() -> tuple(string) 332 333 Returns a tuple of ids of vehicles which arrived (have reached their destination and are removed from the road 334 network) in this time step. 335 """ 336 return self._getUniversal(tc.VAR_ARRIVED_VEHICLES_IDS) 337 338 def getDepartedPersonNumber(self): 339 """getDepartedPersonNumber() -> integer 340 341 Returns the number of persons which departed (were inserted into the road network) in this time step. 342 """ 343 return self._getUniversal(tc.VAR_DEPARTED_PERSONS_NUMBER) 344 345 def getDepartedPersonIDList(self): 346 """getDepartedPersonIDList() -> tuple(string) 347 348 Returns a tuple of ids of persons which departed (were inserted into the road network) in this time step. 349 """ 350 return self._getUniversal(tc.VAR_DEPARTED_PERSONS_IDS) 351 352 def getArrivedPersonNumber(self): 353 """getArrivedPersonNumber() -> integer 354 355 Returns the number of persons which arrived (have reached their destination and are removed from the road 356 network) in this time step. 357 """ 358 return self._getUniversal(tc.VAR_ARRIVED_PERSONS_NUMBER) 359 360 def getArrivedPersonIDList(self): 361 """getArrivedPersonIDList() -> tuple(string) 362 363 Returns a tuple of ids of persons which arrived (have reached their destination and are removed from the road 364 network) in this time step. 365 """ 366 return self._getUniversal(tc.VAR_ARRIVED_PERSONS_IDS) 367 368 def getParkingStartingVehiclesNumber(self): 369 """getParkingStartingVehiclesNumber() -> integer 370 371 . 372 """ 373 return self._getUniversal(tc.VAR_PARKING_STARTING_VEHICLES_NUMBER) 374 375 def getParkingStartingVehiclesIDList(self): 376 """getParkingStartingVehiclesIDList() -> tuple(string) 377 378 . 379 """ 380 return self._getUniversal(tc.VAR_PARKING_STARTING_VEHICLES_IDS) 381 382 def getParkingEndingVehiclesNumber(self): 383 """getParkingEndingVehiclesNumber() -> integer 384 385 . 386 """ 387 return self._getUniversal(tc.VAR_PARKING_ENDING_VEHICLES_NUMBER) 388 389 def getParkingEndingVehiclesIDList(self): 390 """getParkingEndingVehiclesIDList() -> tuple(string) 391 392 . 393 """ 394 return self._getUniversal(tc.VAR_PARKING_ENDING_VEHICLES_IDS) 395 396 def getStopStartingVehiclesNumber(self): 397 """getStopStartingVehiclesNumber() -> integer 398 399 . 400 """ 401 return self._getUniversal(tc.VAR_STOP_STARTING_VEHICLES_NUMBER) 402 403 def getStopStartingVehiclesIDList(self): 404 """getStopStartingVehiclesIDList() -> tuple(string) 405 406 . 407 """ 408 return self._getUniversal(tc.VAR_STOP_STARTING_VEHICLES_IDS) 409 410 def getStopEndingVehiclesNumber(self): 411 """getStopEndingVehiclesNumber() -> integer 412 413 . 414 """ 415 return self._getUniversal(tc.VAR_STOP_ENDING_VEHICLES_NUMBER) 416 417 def getStopEndingVehiclesIDList(self): 418 """getStopEndingVehiclesIDList() -> tuple(string) 419 420 . 421 """ 422 return self._getUniversal(tc.VAR_STOP_ENDING_VEHICLES_IDS) 423 424 def getCollidingVehiclesNumber(self): 425 """getCollidingVehiclesNumber() -> integer 426 Return number of vehicles involved in a collision (typically 2 per 427 collision). 428 """ 429 return self._getUniversal(tc.VAR_COLLIDING_VEHICLES_NUMBER) 430 431 def getCollidingVehiclesIDList(self): 432 """getCollidingVehiclesIDList() -> tuple(string) 433 Return Ids of vehicles involved in a collision (typically 2 per 434 collision). 435 """ 436 return self._getUniversal(tc.VAR_COLLIDING_VEHICLES_IDS) 437 438 def getEmergencyStoppingVehiclesNumber(self): 439 """getEmergencyStoppingVehiclesNumber() -> integer 440 Return number of vehicles that performed an emergency stop in the last step 441 """ 442 return self._getUniversal(tc.VAR_EMERGENCYSTOPPING_VEHICLES_NUMBER) 443 444 def getEmergencyStoppingVehiclesIDList(self): 445 """getEmergencyStoppingVehiclesIDList() -> tuple(string) 446 Return Ids of vehicles that peformed an emergency stop in the last step 447 """ 448 return self._getUniversal(tc.VAR_EMERGENCYSTOPPING_VEHICLES_IDS) 449 450 def getMinExpectedNumber(self): 451 """getMinExpectedNumber() -> integer 452 Returns the number of all active vehicles and persons which are in the net plus the 453 ones still waiting to start. Vehicles and persons currently stopped with a 454 'trigger' are excluded from this number (if only triggered objects 455 remain, the trigger condition cannot be fulfilled and all objects remain 456 stopped without user intervention). 457 The returned number may also be smaller than 458 the actual number of vehicles still to come because of delayed 459 route file parsing. If the number is 0 however, it is 460 guaranteed that all route files have been parsed completely. 461 """ 462 return self._getUniversal(tc.VAR_MIN_EXPECTED_VEHICLES) 463 464 @deprecated("busstop.getIDList") 465 def getBusStopIDList(self): 466 return self._getUniversal(tc.VAR_BUS_STOP_ID_LIST) 467 468 @deprecated("busstop.getPersonCount") 469 def getBusStopWaiting(self, stopID): 470 """getBusStopWaiting() -> integer 471 Get the total number of waiting persons at the named bus stop. 472 """ 473 return self._getUniversal(tc.VAR_BUS_STOP_WAITING, stopID) 474 475 @deprecated("busstop.getPersonIDs") 476 def getBusStopWaitingIDList(self, stopID): 477 """getBusStopWaiting() -> tuple(string) 478 Get the IDs of waiting persons at the named bus stop. 479 """ 480 return self._getUniversal(tc.VAR_BUS_STOP_WAITING_IDS, stopID) 481 482 def getStartingTeleportNumber(self): 483 """getStartingTeleportNumber() -> integer 484 485 Returns the number of vehicles which started to teleport in this time step. 486 """ 487 return self._getUniversal(tc.VAR_TELEPORT_STARTING_VEHICLES_NUMBER) 488 489 def getStartingTeleportIDList(self): 490 """getStartingTeleportIDList() -> tuple(string) 491 492 Returns a tuple of ids of vehicles which started to teleport in this time step. 493 """ 494 return self._getUniversal(tc.VAR_TELEPORT_STARTING_VEHICLES_IDS) 495 496 def getEndingTeleportNumber(self): 497 """getEndingTeleportNumber() -> integer 498 499 Returns the number of vehicles which ended to be teleported in this time step. 500 """ 501 return self._getUniversal(tc.VAR_TELEPORT_ENDING_VEHICLES_NUMBER) 502 503 def getEndingTeleportIDList(self): 504 """getEndingTeleportIDList() -> tuple(string) 505 506 Returns a tuple of ids of vehicles which ended to be teleported in this time step. 507 """ 508 return self._getUniversal(tc.VAR_TELEPORT_ENDING_VEHICLES_IDS) 509 510 def getCollisions(self): 511 """getCollisions() -> tuple(Collision) 512 Returns a tuple of collision objects 513 """ 514 return self._getUniversal(tc.VAR_COLLISIONS) 515 516 def getPendingVehicles(self): 517 """getPendingVehicles() -> tuple(string) 518 Returns a tuple of all vehicle ids waiting for insertion (with depart delay) 519 """ 520 return self._getUniversal(tc.VAR_PENDING_VEHICLES) 521 522 def getScale(self): 523 """getScale() -> double 524 525 Returns the traffic scaling factor 526 """ 527 return self._getUniversal(tc.VAR_SCALE) 528 529 def getOption(self, option): 530 """getOption(string) -> string 531 532 Returns the value of the given SUMO option 533 """ 534 return self._getUniversal(tc.VAR_OPTION, option) 535 536 def getDeltaT(self): 537 """getDeltaT() -> double 538 Returns the length of one simulation step in seconds 539 """ 540 return self._getUniversal(tc.VAR_DELTA_T) 541 542 def getNetBoundary(self): 543 """getNetBoundary() -> ((double, double), (double, double)) 544 545 The boundary box of the simulation network. 546 """ 547 return self._getUniversal(tc.VAR_NET_BOUNDING_BOX) 548 549 def convert2D(self, edgeID, pos, laneIndex=0, toGeo=False): 550 posType = tc.POSITION_2D 551 if toGeo: 552 posType = tc.POSITION_LON_LAT 553 return self._getUniversal(tc.POSITION_CONVERSION, "", "trB", 2, (edgeID, pos, laneIndex), posType) 554 555 def convert3D(self, edgeID, pos, laneIndex=0, toGeo=False): 556 posType = tc.POSITION_3D 557 if toGeo: 558 posType = tc.POSITION_LON_LAT_ALT 559 return self._getUniversal(tc.POSITION_CONVERSION, "", "trB", 2, (edgeID, pos, laneIndex), posType) 560 561 def convertRoad(self, x, y, isGeo=False, vClass="ignoring"): 562 format = "toBs" 563 if isGeo: 564 format = "tgBs" 565 result = self._getCmd(tc.POSITION_CONVERSION, "", format, 3, (x, y), tc.POSITION_ROADMAP, vClass) 566 result.read("!B") 567 return result.readString(), result.readDouble(), result.read("!B")[0] 568 569 def convertGeo(self, x, y, fromGeo=False): 570 format = "toB" 571 toType = tc.POSITION_LON_LAT 572 if fromGeo: 573 format = "tgB" 574 toType = tc.POSITION_2D 575 return self._getUniversal(tc.POSITION_CONVERSION, "", format, 2, (x, y), toType) 576 577 def getDistance2D(self, x1, y1, x2, y2, isGeo=False, isDriving=False): 578 """getDistance2D(double, double, double, double, boolean, boolean) -> double 579 580 Returns the distance between the two coordinate pairs (x1,y1) and (x2,y2) 581 582 If isGeo=True, coordinates are interpreted as longitude and latitude rather 583 than cartesian coordinates in meters. 584 585 If isDriving=True, the coordinates are mapped onto the road network and the 586 length of the shortest route in the network is returned. Otherwise, the 587 straight-line distance is returned. 588 """ 589 format = "tggu" if isGeo else "toou" 590 distType = tc.REQUEST_AIRDIST 591 if isDriving: 592 distType = tc.REQUEST_DRIVINGDIST 593 return self._getUniversal(tc.DISTANCE_REQUEST, "", format, 3, (x1, y1), (x2, y2), distType) 594 595 def getDistanceRoad(self, edgeID1, pos1, edgeID2, pos2, isDriving=False): 596 """getDistanceRoad(string, double, string, double, boolean) -> double 597 598 Reads two positions on the road network and an indicator whether the air or the driving distance shall be 599 computed. Returns the according distance. 600 """ 601 distType = tc.REQUEST_AIRDIST 602 if isDriving: 603 distType = tc.REQUEST_DRIVINGDIST 604 return self._getUniversal(tc.DISTANCE_REQUEST, "", "trru", 3, 605 (edgeID1, pos1, 0), (edgeID2, pos2, 0), distType) 606 607 def findRoute(self, fromEdge, toEdge, vType="", depart=-1., routingMode=0, 608 departPos=0., arrivalPos=tc.INVALID_DOUBLE_VALUE): 609 """findRoute(string, string, string, double, int, double, double) -> Stage 610 Computes the fastest route between the given edges for the given vehicle 611 type (defaults to DEFAULT_VEHTYPE) 612 Returns a Stage object that holds the edge list and the travel time 613 When the depart time is not set, the travel times at the current time 614 will be used. The routing mode may be ROUTING_MODE_DEFAULT (loaded or 615 default speeds) and ROUTING_MODE_AGGREGATED (averaged historical speeds) 616 """ 617 return self._getUniversal(tc.FIND_ROUTE, "", "tsssdidd", 7, fromEdge, toEdge, vType, depart, 618 routingMode, departPos, arrivalPos) 619 620 def findIntermodalRoute(self, fromEdge, toEdge, modes="", depart=-1., routingMode=0, speed=-1., 621 walkFactor=-1., departPos=0., arrivalPos=tc.INVALID_DOUBLE_VALUE, departPosLat=0., 622 pType="", vType="", destStop=""): 623 """findIntermodalRoute(string, string, string, double, int, double, 624 double, double, double, double, string, string, string) -> tuple(Stage) 625 Computes the fastest intermoal route between the given edges for the 626 given combination of transport modes (i.e. "car public" may result in 627 driving to the train station and then riding the train). 628 Returns a tuple of Stage objects that correspond to the sequence of walks 629 and rides to reach the destination. 630 When the depart time is not set, the travel times at the current time will be used. 631 The routing mode may be ROUTING_MODE_DEFAULT (loaded or 632 default speeds) and ROUTING_MODE_AGGREGATED (averaged historical speeds) 633 pType defines the pedestrian type (for walking speed) and defaults to 634 DEFAULT_PEDTYPE. 635 walkFactor is a multiplier for the walking speed to 636 account for delays due to intersections and other traffic when 637 determining the feasibility of using a particular public transport 638 vehicle. 639 vType is an optional vehicle type to use for private car routing. 640 destStop can be used as an alternative to 'toEdge' to define the edge 641 and position of the specified public transport stop as the destination 642 """ 643 answer = self._getCmd(tc.FIND_INTERMODAL_ROUTE, "", "tsssdidddddsss", 13, 644 fromEdge, toEdge, modes, depart, routingMode, speed, walkFactor, 645 departPos, arrivalPos, departPosLat, pType, vType, destStop) 646 answer.read("!B") # Type 647 result = [] 648 for _ in range(answer.readInt()): 649 answer.read("!B") # Type 650 result.append(_readStage(answer)) 651 return tuple(result) 652 653 def setScale(self, value): 654 """setScale(value) -> None 655 656 Sets the traffic scaling factor 657 """ 658 self._setCmd(tc.VAR_SCALE, "", "d", value) 659 660 def clearPending(self, routeID=""): 661 self._setCmd(tc.CMD_CLEAR_PENDING_VEHICLES, "", "s", routeID) 662 663 def saveState(self, fileName): 664 self._setCmd(tc.CMD_SAVE_SIMSTATE, "", "s", fileName) 665 666 def loadState(self, fileName): 667 self._setCmd(tc.CMD_LOAD_SIMSTATE, "", "s", fileName) 668 669 def writeMessage(self, msg): 670 self._setCmd(tc.CMD_MESSAGE, "", "s", msg) 671 672 def subscribe(self, varIDs=(tc.VAR_DEPARTED_VEHICLES_IDS,), begin=0, end=2**31 - 1, parameters=None): 673 """subscribe(list(integer), double, double, map) -> None 674 675 Subscribe to one or more simulation values for the given interval. 676 """ 677 Domain.subscribe(self, "", varIDs, begin, end, parameters) 678 679 def getSubscriptionResults(self): 680 """getSubscriptionResults() -> dict(integer: <value_type>) 681 682 Returns the subscription results for the last time step. 683 It is not possible to retrieve older subscription results than the ones 684 from the last time step. 685 """ 686 return Domain.getSubscriptionResults(self, "")
253 def getTime(self): 254 """getTime() -> double 255 256 Returns the current simulation time in s. 257 """ 258 return self._getUniversal(tc.VAR_TIME)
getTime() -> double
Returns the current simulation time in s.
260 def getEndTime(self): 261 """getEndTime() -> double 262 263 Returns the configured end time of the simulation in s or -1 264 """ 265 return self._getUniversal(tc.VAR_END)
getEndTime() -> double
Returns the configured end time of the simulation in s or -1
267 def step(self, time=0.): 268 """step(double) -> None 269 Make a simulation step and simulate up to the given sim time (in seconds). 270 If the given value is 0 or absent, exactly one step is performed. 271 Values smaller than or equal to the current sim time result in no action. 272 """ 273 if self._connection is None: 274 raise FatalTraCIError("Not connected.") 275 self._connection.simulationStep(time)
step(double) -> None Make a simulation step and simulate up to the given sim time (in seconds). If the given value is 0 or absent, exactly one step is performed. Values smaller than or equal to the current sim time result in no action.
277 def executeMove(self): 278 """executeMove() -> None 279 Make "half" a simulation step. 280 """ 281 if self._connection is None: 282 raise FatalTraCIError("Not connected.") 283 self._connection._sendCmd(tc.CMD_EXECUTEMOVE, None, None)
executeMove() -> None Make "half" a simulation step.
285 def getCurrentTime(self): 286 """getCurrentTime() -> integer 287 288 Returns the current simulation time in ms. 289 """ 290 warnings.warn("getCurrentTime is deprecated, please use getTime which returns floating point seconds", 291 stacklevel=2) 292 return self._getUniversal(tc.VAR_TIME_STEP)
getCurrentTime() -> integer
Returns the current simulation time in ms.
294 def getLoadedNumber(self): 295 """getLoadedNumber() -> integer 296 297 Returns the number of vehicles which were loaded in this time step. 298 """ 299 return self._getUniversal(tc.VAR_LOADED_VEHICLES_NUMBER)
getLoadedNumber() -> integer
Returns the number of vehicles which were loaded in this time step.
301 def getLoadedIDList(self): 302 """getLoadedIDList() -> tuple(string) 303 304 Returns a tuple of ids of vehicles which were loaded in this time step. 305 """ 306 return self._getUniversal(tc.VAR_LOADED_VEHICLES_IDS)
getLoadedIDList() -> tuple(string)
Returns a tuple of ids of vehicles which were loaded in this time step.
308 def getDepartedNumber(self): 309 """getDepartedNumber() -> integer 310 311 Returns the number of vehicles which departed (were inserted into the road network) in this time step. 312 """ 313 return self._getUniversal(tc.VAR_DEPARTED_VEHICLES_NUMBER)
getDepartedNumber() -> integer
Returns the number of vehicles which departed (were inserted into the road network) in this time step.
315 def getDepartedIDList(self): 316 """getDepartedIDList() -> tuple(string) 317 318 Returns a tuple of ids of vehicles which departed (were inserted into the road network) in this time step. 319 """ 320 return self._getUniversal(tc.VAR_DEPARTED_VEHICLES_IDS)
getDepartedIDList() -> tuple(string)
Returns a tuple of ids of vehicles which departed (were inserted into the road network) in this time step.
322 def getArrivedNumber(self): 323 """getArrivedNumber() -> integer 324 325 Returns the number of vehicles which arrived (have reached their destination and are removed from the road 326 network) in this time step. 327 """ 328 return self._getUniversal(tc.VAR_ARRIVED_VEHICLES_NUMBER)
getArrivedNumber() -> integer
Returns the number of vehicles which arrived (have reached their destination and are removed from the road network) in this time step.
330 def getArrivedIDList(self): 331 """getArrivedIDList() -> tuple(string) 332 333 Returns a tuple of ids of vehicles which arrived (have reached their destination and are removed from the road 334 network) in this time step. 335 """ 336 return self._getUniversal(tc.VAR_ARRIVED_VEHICLES_IDS)
getArrivedIDList() -> tuple(string)
Returns a tuple of ids of vehicles which arrived (have reached their destination and are removed from the road network) in this time step.
338 def getDepartedPersonNumber(self): 339 """getDepartedPersonNumber() -> integer 340 341 Returns the number of persons which departed (were inserted into the road network) in this time step. 342 """ 343 return self._getUniversal(tc.VAR_DEPARTED_PERSONS_NUMBER)
getDepartedPersonNumber() -> integer
Returns the number of persons which departed (were inserted into the road network) in this time step.
345 def getDepartedPersonIDList(self): 346 """getDepartedPersonIDList() -> tuple(string) 347 348 Returns a tuple of ids of persons which departed (were inserted into the road network) in this time step. 349 """ 350 return self._getUniversal(tc.VAR_DEPARTED_PERSONS_IDS)
getDepartedPersonIDList() -> tuple(string)
Returns a tuple of ids of persons which departed (were inserted into the road network) in this time step.
352 def getArrivedPersonNumber(self): 353 """getArrivedPersonNumber() -> integer 354 355 Returns the number of persons which arrived (have reached their destination and are removed from the road 356 network) in this time step. 357 """ 358 return self._getUniversal(tc.VAR_ARRIVED_PERSONS_NUMBER)
getArrivedPersonNumber() -> integer
Returns the number of persons which arrived (have reached their destination and are removed from the road network) in this time step.
360 def getArrivedPersonIDList(self): 361 """getArrivedPersonIDList() -> tuple(string) 362 363 Returns a tuple of ids of persons which arrived (have reached their destination and are removed from the road 364 network) in this time step. 365 """ 366 return self._getUniversal(tc.VAR_ARRIVED_PERSONS_IDS)
getArrivedPersonIDList() -> tuple(string)
Returns a tuple of ids of persons which arrived (have reached their destination and are removed from the road network) in this time step.
368 def getParkingStartingVehiclesNumber(self): 369 """getParkingStartingVehiclesNumber() -> integer 370 371 . 372 """ 373 return self._getUniversal(tc.VAR_PARKING_STARTING_VEHICLES_NUMBER)
getParkingStartingVehiclesNumber() -> integer
.
375 def getParkingStartingVehiclesIDList(self): 376 """getParkingStartingVehiclesIDList() -> tuple(string) 377 378 . 379 """ 380 return self._getUniversal(tc.VAR_PARKING_STARTING_VEHICLES_IDS)
getParkingStartingVehiclesIDList() -> tuple(string)
.
382 def getParkingEndingVehiclesNumber(self): 383 """getParkingEndingVehiclesNumber() -> integer 384 385 . 386 """ 387 return self._getUniversal(tc.VAR_PARKING_ENDING_VEHICLES_NUMBER)
getParkingEndingVehiclesNumber() -> integer
.
389 def getParkingEndingVehiclesIDList(self): 390 """getParkingEndingVehiclesIDList() -> tuple(string) 391 392 . 393 """ 394 return self._getUniversal(tc.VAR_PARKING_ENDING_VEHICLES_IDS)
getParkingEndingVehiclesIDList() -> tuple(string)
.
396 def getStopStartingVehiclesNumber(self): 397 """getStopStartingVehiclesNumber() -> integer 398 399 . 400 """ 401 return self._getUniversal(tc.VAR_STOP_STARTING_VEHICLES_NUMBER)
getStopStartingVehiclesNumber() -> integer
.
403 def getStopStartingVehiclesIDList(self): 404 """getStopStartingVehiclesIDList() -> tuple(string) 405 406 . 407 """ 408 return self._getUniversal(tc.VAR_STOP_STARTING_VEHICLES_IDS)
getStopStartingVehiclesIDList() -> tuple(string)
.
410 def getStopEndingVehiclesNumber(self): 411 """getStopEndingVehiclesNumber() -> integer 412 413 . 414 """ 415 return self._getUniversal(tc.VAR_STOP_ENDING_VEHICLES_NUMBER)
getStopEndingVehiclesNumber() -> integer
.
417 def getStopEndingVehiclesIDList(self): 418 """getStopEndingVehiclesIDList() -> tuple(string) 419 420 . 421 """ 422 return self._getUniversal(tc.VAR_STOP_ENDING_VEHICLES_IDS)
getStopEndingVehiclesIDList() -> tuple(string)
.
424 def getCollidingVehiclesNumber(self): 425 """getCollidingVehiclesNumber() -> integer 426 Return number of vehicles involved in a collision (typically 2 per 427 collision). 428 """ 429 return self._getUniversal(tc.VAR_COLLIDING_VEHICLES_NUMBER)
getCollidingVehiclesNumber() -> integer Return number of vehicles involved in a collision (typically 2 per collision).
431 def getCollidingVehiclesIDList(self): 432 """getCollidingVehiclesIDList() -> tuple(string) 433 Return Ids of vehicles involved in a collision (typically 2 per 434 collision). 435 """ 436 return self._getUniversal(tc.VAR_COLLIDING_VEHICLES_IDS)
getCollidingVehiclesIDList() -> tuple(string) Return Ids of vehicles involved in a collision (typically 2 per collision).
438 def getEmergencyStoppingVehiclesNumber(self): 439 """getEmergencyStoppingVehiclesNumber() -> integer 440 Return number of vehicles that performed an emergency stop in the last step 441 """ 442 return self._getUniversal(tc.VAR_EMERGENCYSTOPPING_VEHICLES_NUMBER)
getEmergencyStoppingVehiclesNumber() -> integer Return number of vehicles that performed an emergency stop in the last step
444 def getEmergencyStoppingVehiclesIDList(self): 445 """getEmergencyStoppingVehiclesIDList() -> tuple(string) 446 Return Ids of vehicles that peformed an emergency stop in the last step 447 """ 448 return self._getUniversal(tc.VAR_EMERGENCYSTOPPING_VEHICLES_IDS)
getEmergencyStoppingVehiclesIDList() -> tuple(string) Return Ids of vehicles that peformed an emergency stop in the last step
450 def getMinExpectedNumber(self): 451 """getMinExpectedNumber() -> integer 452 Returns the number of all active vehicles and persons which are in the net plus the 453 ones still waiting to start. Vehicles and persons currently stopped with a 454 'trigger' are excluded from this number (if only triggered objects 455 remain, the trigger condition cannot be fulfilled and all objects remain 456 stopped without user intervention). 457 The returned number may also be smaller than 458 the actual number of vehicles still to come because of delayed 459 route file parsing. If the number is 0 however, it is 460 guaranteed that all route files have been parsed completely. 461 """ 462 return self._getUniversal(tc.VAR_MIN_EXPECTED_VEHICLES)
getMinExpectedNumber() -> integer Returns the number of all active vehicles and persons which are in the net plus the ones still waiting to start. Vehicles and persons currently stopped with a 'trigger' are excluded from this number (if only triggered objects remain, the trigger condition cannot be fulfilled and all objects remain stopped without user intervention). The returned number may also be smaller than the actual number of vehicles still to come because of delayed route file parsing. If the number is 0 however, it is guaranteed that all route files have been parsed completely.
468 @deprecated("busstop.getPersonCount") 469 def getBusStopWaiting(self, stopID): 470 """getBusStopWaiting() -> integer 471 Get the total number of waiting persons at the named bus stop. 472 """ 473 return self._getUniversal(tc.VAR_BUS_STOP_WAITING, stopID)
getBusStopWaiting() -> integer Get the total number of waiting persons at the named bus stop.
475 @deprecated("busstop.getPersonIDs") 476 def getBusStopWaitingIDList(self, stopID): 477 """getBusStopWaiting() -> tuple(string) 478 Get the IDs of waiting persons at the named bus stop. 479 """ 480 return self._getUniversal(tc.VAR_BUS_STOP_WAITING_IDS, stopID)
getBusStopWaiting() -> tuple(string) Get the IDs of waiting persons at the named bus stop.
482 def getStartingTeleportNumber(self): 483 """getStartingTeleportNumber() -> integer 484 485 Returns the number of vehicles which started to teleport in this time step. 486 """ 487 return self._getUniversal(tc.VAR_TELEPORT_STARTING_VEHICLES_NUMBER)
getStartingTeleportNumber() -> integer
Returns the number of vehicles which started to teleport in this time step.
489 def getStartingTeleportIDList(self): 490 """getStartingTeleportIDList() -> tuple(string) 491 492 Returns a tuple of ids of vehicles which started to teleport in this time step. 493 """ 494 return self._getUniversal(tc.VAR_TELEPORT_STARTING_VEHICLES_IDS)
getStartingTeleportIDList() -> tuple(string)
Returns a tuple of ids of vehicles which started to teleport in this time step.
496 def getEndingTeleportNumber(self): 497 """getEndingTeleportNumber() -> integer 498 499 Returns the number of vehicles which ended to be teleported in this time step. 500 """ 501 return self._getUniversal(tc.VAR_TELEPORT_ENDING_VEHICLES_NUMBER)
getEndingTeleportNumber() -> integer
Returns the number of vehicles which ended to be teleported in this time step.
503 def getEndingTeleportIDList(self): 504 """getEndingTeleportIDList() -> tuple(string) 505 506 Returns a tuple of ids of vehicles which ended to be teleported in this time step. 507 """ 508 return self._getUniversal(tc.VAR_TELEPORT_ENDING_VEHICLES_IDS)
getEndingTeleportIDList() -> tuple(string)
Returns a tuple of ids of vehicles which ended to be teleported in this time step.
510 def getCollisions(self): 511 """getCollisions() -> tuple(Collision) 512 Returns a tuple of collision objects 513 """ 514 return self._getUniversal(tc.VAR_COLLISIONS)
getCollisions() -> tuple(Collision) Returns a tuple of collision objects
516 def getPendingVehicles(self): 517 """getPendingVehicles() -> tuple(string) 518 Returns a tuple of all vehicle ids waiting for insertion (with depart delay) 519 """ 520 return self._getUniversal(tc.VAR_PENDING_VEHICLES)
getPendingVehicles() -> tuple(string) Returns a tuple of all vehicle ids waiting for insertion (with depart delay)
522 def getScale(self): 523 """getScale() -> double 524 525 Returns the traffic scaling factor 526 """ 527 return self._getUniversal(tc.VAR_SCALE)
getScale() -> double
Returns the traffic scaling factor
529 def getOption(self, option): 530 """getOption(string) -> string 531 532 Returns the value of the given SUMO option 533 """ 534 return self._getUniversal(tc.VAR_OPTION, option)
getOption(string) -> string
Returns the value of the given SUMO option
536 def getDeltaT(self): 537 """getDeltaT() -> double 538 Returns the length of one simulation step in seconds 539 """ 540 return self._getUniversal(tc.VAR_DELTA_T)
getDeltaT() -> double Returns the length of one simulation step in seconds
542 def getNetBoundary(self): 543 """getNetBoundary() -> ((double, double), (double, double)) 544 545 The boundary box of the simulation network. 546 """ 547 return self._getUniversal(tc.VAR_NET_BOUNDING_BOX)
getNetBoundary() -> ((double, double), (double, double))
The boundary box of the simulation network.
561 def convertRoad(self, x, y, isGeo=False, vClass="ignoring"): 562 format = "toBs" 563 if isGeo: 564 format = "tgBs" 565 result = self._getCmd(tc.POSITION_CONVERSION, "", format, 3, (x, y), tc.POSITION_ROADMAP, vClass) 566 result.read("!B") 567 return result.readString(), result.readDouble(), result.read("!B")[0]
577 def getDistance2D(self, x1, y1, x2, y2, isGeo=False, isDriving=False): 578 """getDistance2D(double, double, double, double, boolean, boolean) -> double 579 580 Returns the distance between the two coordinate pairs (x1,y1) and (x2,y2) 581 582 If isGeo=True, coordinates are interpreted as longitude and latitude rather 583 than cartesian coordinates in meters. 584 585 If isDriving=True, the coordinates are mapped onto the road network and the 586 length of the shortest route in the network is returned. Otherwise, the 587 straight-line distance is returned. 588 """ 589 format = "tggu" if isGeo else "toou" 590 distType = tc.REQUEST_AIRDIST 591 if isDriving: 592 distType = tc.REQUEST_DRIVINGDIST 593 return self._getUniversal(tc.DISTANCE_REQUEST, "", format, 3, (x1, y1), (x2, y2), distType)
getDistance2D(double, double, double, double, boolean, boolean) -> double
Returns the distance between the two coordinate pairs (x1,y1) and (x2,y2)
If isGeo=True, coordinates are interpreted as longitude and latitude rather than cartesian coordinates in meters.
If isDriving=True, the coordinates are mapped onto the road network and the length of the shortest route in the network is returned. Otherwise, the straight-line distance is returned.
595 def getDistanceRoad(self, edgeID1, pos1, edgeID2, pos2, isDriving=False): 596 """getDistanceRoad(string, double, string, double, boolean) -> double 597 598 Reads two positions on the road network and an indicator whether the air or the driving distance shall be 599 computed. Returns the according distance. 600 """ 601 distType = tc.REQUEST_AIRDIST 602 if isDriving: 603 distType = tc.REQUEST_DRIVINGDIST 604 return self._getUniversal(tc.DISTANCE_REQUEST, "", "trru", 3, 605 (edgeID1, pos1, 0), (edgeID2, pos2, 0), distType)
getDistanceRoad(string, double, string, double, boolean) -> double
Reads two positions on the road network and an indicator whether the air or the driving distance shall be computed. Returns the according distance.
607 def findRoute(self, fromEdge, toEdge, vType="", depart=-1., routingMode=0, 608 departPos=0., arrivalPos=tc.INVALID_DOUBLE_VALUE): 609 """findRoute(string, string, string, double, int, double, double) -> Stage 610 Computes the fastest route between the given edges for the given vehicle 611 type (defaults to DEFAULT_VEHTYPE) 612 Returns a Stage object that holds the edge list and the travel time 613 When the depart time is not set, the travel times at the current time 614 will be used. The routing mode may be ROUTING_MODE_DEFAULT (loaded or 615 default speeds) and ROUTING_MODE_AGGREGATED (averaged historical speeds) 616 """ 617 return self._getUniversal(tc.FIND_ROUTE, "", "tsssdidd", 7, fromEdge, toEdge, vType, depart, 618 routingMode, departPos, arrivalPos)
findRoute(string, string, string, double, int, double, double) -> Stage Computes the fastest route between the given edges for the given vehicle type (defaults to DEFAULT_VEHTYPE) Returns a Stage object that holds the edge list and the travel time When the depart time is not set, the travel times at the current time will be used. The routing mode may be ROUTING_MODE_DEFAULT (loaded or default speeds) and ROUTING_MODE_AGGREGATED (averaged historical speeds)
620 def findIntermodalRoute(self, fromEdge, toEdge, modes="", depart=-1., routingMode=0, speed=-1., 621 walkFactor=-1., departPos=0., arrivalPos=tc.INVALID_DOUBLE_VALUE, departPosLat=0., 622 pType="", vType="", destStop=""): 623 """findIntermodalRoute(string, string, string, double, int, double, 624 double, double, double, double, string, string, string) -> tuple(Stage) 625 Computes the fastest intermoal route between the given edges for the 626 given combination of transport modes (i.e. "car public" may result in 627 driving to the train station and then riding the train). 628 Returns a tuple of Stage objects that correspond to the sequence of walks 629 and rides to reach the destination. 630 When the depart time is not set, the travel times at the current time will be used. 631 The routing mode may be ROUTING_MODE_DEFAULT (loaded or 632 default speeds) and ROUTING_MODE_AGGREGATED (averaged historical speeds) 633 pType defines the pedestrian type (for walking speed) and defaults to 634 DEFAULT_PEDTYPE. 635 walkFactor is a multiplier for the walking speed to 636 account for delays due to intersections and other traffic when 637 determining the feasibility of using a particular public transport 638 vehicle. 639 vType is an optional vehicle type to use for private car routing. 640 destStop can be used as an alternative to 'toEdge' to define the edge 641 and position of the specified public transport stop as the destination 642 """ 643 answer = self._getCmd(tc.FIND_INTERMODAL_ROUTE, "", "tsssdidddddsss", 13, 644 fromEdge, toEdge, modes, depart, routingMode, speed, walkFactor, 645 departPos, arrivalPos, departPosLat, pType, vType, destStop) 646 answer.read("!B") # Type 647 result = [] 648 for _ in range(answer.readInt()): 649 answer.read("!B") # Type 650 result.append(_readStage(answer)) 651 return tuple(result)
findIntermodalRoute(string, string, string, double, int, double, double, double, double, double, string, string, string) -> tuple(Stage) Computes the fastest intermoal route between the given edges for the given combination of transport modes (i.e. "car public" may result in driving to the train station and then riding the train). Returns a tuple of Stage objects that correspond to the sequence of walks and rides to reach the destination. When the depart time is not set, the travel times at the current time will be used. The routing mode may be ROUTING_MODE_DEFAULT (loaded or default speeds) and ROUTING_MODE_AGGREGATED (averaged historical speeds) pType defines the pedestrian type (for walking speed) and defaults to DEFAULT_PEDTYPE. walkFactor is a multiplier for the walking speed to account for delays due to intersections and other traffic when determining the feasibility of using a particular public transport vehicle. vType is an optional vehicle type to use for private car routing. destStop can be used as an alternative to 'toEdge' to define the edge and position of the specified public transport stop as the destination
653 def setScale(self, value): 654 """setScale(value) -> None 655 656 Sets the traffic scaling factor 657 """ 658 self._setCmd(tc.VAR_SCALE, "", "d", value)
setScale(value) -> None
Sets the traffic scaling factor
672 def subscribe(self, varIDs=(tc.VAR_DEPARTED_VEHICLES_IDS,), begin=0, end=2**31 - 1, parameters=None): 673 """subscribe(list(integer), double, double, map) -> None 674 675 Subscribe to one or more simulation values for the given interval. 676 """ 677 Domain.subscribe(self, "", varIDs, begin, end, parameters)
subscribe(list(integer), double, double, map) -> None
Subscribe to one or more simulation values for the given interval.
679 def getSubscriptionResults(self): 680 """getSubscriptionResults() -> dict(integer: <value_type>) 681 682 Returns the subscription results for the last time step. 683 It is not possible to retrieve older subscription results than the ones 684 from the last time step. 685 """ 686 return Domain.getSubscriptionResults(self, "")
getSubscriptionResults() -> dict(integer:
Returns the subscription results for the last time step. It is not possible to retrieve older subscription results than the ones from the last time step.
28class Stage(object): 29 30 def __init__(self, 31 type=tc.INVALID_INT_VALUE, 32 vType="", 33 line="", 34 destStop="", 35 edges=[], 36 travelTime=tc.INVALID_DOUBLE_VALUE, 37 cost=tc.INVALID_DOUBLE_VALUE, 38 length=tc.INVALID_DOUBLE_VALUE, 39 intended="", 40 depart=tc.INVALID_DOUBLE_VALUE, 41 departPos=tc.INVALID_DOUBLE_VALUE, 42 arrivalPos=tc.INVALID_DOUBLE_VALUE, 43 description=""): 44 self.type = type 45 self.vType = vType 46 self.line = line 47 self.destStop = destStop 48 self.edges = edges 49 self.travelTime = travelTime 50 self.cost = cost 51 self.length = length 52 self.intended = intended 53 self.depart = depart 54 self.departPos = departPos 55 self.arrivalPos = arrivalPos 56 self.description = description 57 58 def __attr_repr__(self, attrname, default=""): 59 if getattr(self, attrname) == default: 60 return "" 61 else: 62 val = getattr(self, attrname) 63 if val == tc.INVALID_DOUBLE_VALUE: 64 val = "INVALID" 65 return "%s=%s" % (attrname, val) 66 67 def __repr__(self): 68 return "Stage(%s)" % ', '.join([v for v in [ 69 self.__attr_repr__("type"), 70 self.__attr_repr__("vType"), 71 self.__attr_repr__("line"), 72 self.__attr_repr__("destStop"), 73 self.__attr_repr__("edges"), 74 self.__attr_repr__("travelTime"), 75 self.__attr_repr__("cost"), 76 self.__attr_repr__("length"), 77 self.__attr_repr__("intended"), 78 self.__attr_repr__("depart"), 79 self.__attr_repr__("departPos"), 80 self.__attr_repr__("arrivalPos"), 81 self.__attr_repr__("description"), 82 ] if v != ""]) 83 84 def toXML(self, firstStage=True, isPerson=True, extra=[]): 85 """write stage as xml element. 86 If firstStage=False, the from-attribute is omitted since sumo derives it from the prior stage. 87 If extra is a list of (attrname, value) these will be added to the xml element 88 """ 89 if self.type == tc.STAGE_WAITING: 90 to = ' edge="%s" endPos="%.2f"' % (self.edges[-1], self.arrivalPos) 91 if self.destStop: 92 to = ' busStop="%s"' % self.destStop 93 other = '' 94 if self.travelTime >= 0: 95 other += ' duration="%s"' % self.travelTime 96 other += ''.join([' %s="%s"' % i for i in extra]) 97 return '<stop%s%s/>' % (to, other) 98 99 elif self.type == tc.STAGE_DRIVING: 100 fro = ' from="%s"' % self.edges[0] if firstStage else '' 101 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 102 if self.destStop: 103 to = ' busStop="%s"' % self.destStop 104 elem = "ride" if isPerson else "transport" 105 other = '' 106 if self.line: 107 other += ' lines="%s"' % self.line 108 if self.intended: 109 other += ' intended="%s"' % self.intended 110 if self.depart != tc.INVALID_DOUBLE_VALUE: 111 other += ' depart="%s"' % self.depart 112 other += ''.join([' %s="%s"' % i for i in extra]) 113 return '<%s%s%s%s/>' % (elem, fro, to, other) 114 115 elif self.type == tc.STAGE_WALKING: 116 to = ' arrivalPos="%.2f"' % self.arrivalPos 117 if self.destStop: 118 to = ' busStop="%s"' % self.destStop 119 edges = ' edges="%s"' % ' '.join(self.edges) 120 other = ''.join([' %s="%s"' % i for i in extra]) 121 return '<walk%s%s%s/>' % (edges, to, other) 122 123 elif self.type == tc.STAGE_TRIP: 124 fro = ' from="%s"' % self.edges[0] if firstStage else '' 125 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 126 if self.destStop: 127 to = ' busStop="%s"' % self.destStop 128 other = '' 129 if self.vType: 130 other += ' vTypes="%s"' % self.vType 131 other += ''.join([' %s="%s"' % i for i in extra]) 132 return '<personTrip%s%s%s/>' % (fro, to, other) 133 134 elif self.type == tc.STAGE_TRANSHIP: 135 fro = ' from="%s"' % self.edges[0] if firstStage else '' 136 to = ' to="%s" arrivalPos="%.2f"' % (self.edges[-1], self.arrivalPos) 137 if self.destStop: 138 to = ' busStop="%s"' % self.destStop 139 other = ''.join([' %s="%s"' % i for i in extra]) 140 return '<tranship%s%s%s/>' % (fro, to, other) 141 142 else: 143 # STAGE_ACCESS and STAGE_WAITING_FOR_DEPART are never read from xml 144 # print("unwritten stage: ", self.type) 145 return ""