traci._person
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 _person.py 15# @author Jakob Erdmann 16# @date 2015-02-06 17 18from __future__ import absolute_import 19from ._vehicletype import VTypeDomain 20from . import constants as tc 21from . import _simulation as simulation 22 23 24class Reservation(object): 25 26 def __init__(self, id, persons, group, fromEdge, toEdge, departPos, arrivalPos, 27 depart, reservationTime, state): 28 self.id = id 29 self.persons = persons 30 self.group = group 31 self.fromEdge = fromEdge 32 self.toEdge = toEdge 33 self.arrivalPos = arrivalPos 34 self.departPos = departPos 35 self.depart = depart 36 self.reservationTime = reservationTime 37 self.state = state 38 39 def __attr_repr__(self, attrname, default=""): 40 if getattr(self, attrname) == default: 41 return "" 42 else: 43 val = getattr(self, attrname) 44 if val == tc.INVALID_DOUBLE_VALUE: 45 val = "INVALID" 46 return "%s=%s" % (attrname, val) 47 48 def __repr__(self): 49 return "Reservation(%s)" % ', '.join([v for v in [ 50 self.__attr_repr__("id"), 51 self.__attr_repr__("persons"), 52 self.__attr_repr__("group"), 53 self.__attr_repr__("fromEdge"), 54 self.__attr_repr__("toEdge"), 55 self.__attr_repr__("departPos"), 56 self.__attr_repr__("arrivalPos"), 57 self.__attr_repr__("depart"), 58 self.__attr_repr__("reservationTime"), 59 self.__attr_repr__("state"), 60 ] if v != ""]) 61 62 63def _readReservations(result): 64 reservations = [] 65 for _ in range(result.readInt()): 66 result.read("!B") # Type 67 # compound size and type 68 assert result.read("!i")[0] == 10 69 id = result.readTypedString() 70 persons = result.readTypedStringList() 71 group = result.readTypedString() 72 fromEdge = result.readTypedString() 73 toEdge = result.readTypedString() 74 departPos = result.readTypedDouble() 75 arrivalPos = result.readTypedDouble() 76 depart = result.readTypedDouble() 77 reservationTime = result.readTypedDouble() 78 state = result.readTypedInt() 79 reservations.append(Reservation(id, persons, group, fromEdge, toEdge, departPos, 80 arrivalPos, depart, reservationTime, state)) 81 return tuple(reservations) 82 83 84_RETURN_VALUE_FUNC = {tc.VAR_STAGE: simulation._readStage, 85 tc.VAR_TAXI_RESERVATIONS: _readReservations 86 } 87 88 89class PersonDomain(VTypeDomain): 90 91 Reservation = Reservation 92 93 def __init__(self): 94 VTypeDomain.__init__(self, "person", tc.CMD_GET_PERSON_VARIABLE, tc.CMD_SET_PERSON_VARIABLE, 95 tc.CMD_SUBSCRIBE_PERSON_VARIABLE, tc.RESPONSE_SUBSCRIBE_PERSON_VARIABLE, 96 tc.CMD_SUBSCRIBE_PERSON_CONTEXT, tc.RESPONSE_SUBSCRIBE_PERSON_CONTEXT, 97 _RETURN_VALUE_FUNC) 98 99 def getSpeed(self, personID): 100 """getSpeed(string) -> double 101 102 Returns the speed in m/s of the named person within the last step. 103 """ 104 return self._getUniversal(tc.VAR_SPEED, personID) 105 106 def getPosition(self, personID): 107 """getPosition(string) -> (double, double) 108 109 Returns the position of the named person within the last step [m,m]. 110 """ 111 return self._getUniversal(tc.VAR_POSITION, personID) 112 113 def getPosition3D(self, personID): 114 """getPosition3D(string) -> (double, double, double) 115 116 Returns the position of the named person within the last step [m,m,m]. 117 """ 118 return self._getUniversal(tc.VAR_POSITION3D, personID) 119 120 def getAngle(self, personID): 121 """getAngle(string) -> double 122 123 Returns the angle in degrees of the named person within the last step. 124 """ 125 return self._getUniversal(tc.VAR_ANGLE, personID) 126 127 def getSlope(self, personID): 128 """getSlope(string) -> double 129 130 Returns the slope at the current position of the person in degrees 131 """ 132 return self._getUniversal(tc.VAR_SLOPE, personID) 133 134 def getRoadID(self, personID): 135 """getRoadID(string) -> string 136 137 Returns the id of the edge the named person was at within the last step. 138 """ 139 return self._getUniversal(tc.VAR_ROAD_ID, personID) 140 141 def getLaneID(self, personID): 142 """getLaneID(string) -> string 143 144 Returns the id of the lane the named person was at within the last step. 145 If the current person stage does not provide a lane, "" is returned. 146 """ 147 return self._getUniversal(tc.VAR_LANE_ID, personID) 148 149 def getTypeID(self, personID): 150 """getTypeID(string) -> string 151 152 Returns the id of the type of the named person. 153 """ 154 return self._getUniversal(tc.VAR_TYPE, personID) 155 156 def getLanePosition(self, personID): 157 """getLanePosition(string) -> double 158 159 The position of the person along the lane measured in m. 160 """ 161 return self._getUniversal(tc.VAR_LANEPOSITION, personID) 162 163 def getArrivalPos(self, personID): 164 """getArrivalPos(string) -> double 165 166 The final arrival position of the person's plan in m. 167 """ 168 return self._getUniversal(tc.VAR_ARRIVALPOS, personID) 169 170 def getWalkingDistance(self, personID, edgeID, pos, laneIndex=0): 171 """getWalkingDistance(string, string, double, integer) -> double 172 173 For a person in walking stage and an edge along the remaining route of 174 personID, return the distance from the current position 175 to the given edge and position along the walk. 176 Otherwise, raise a TraCIException 177 """ 178 return self._getUniversal(tc.DISTANCE_REQUEST, personID, "tru", 2, 179 (edgeID, pos, laneIndex), tc.REQUEST_DRIVINGDIST) 180 181 def getWalkingDistance2D(self, personID, x, y): 182 """getWalkingDistance2D(string, double, double) -> integer 183 184 Return the distance to the given network position along the walk (see getWalkingDistance) 185 """ 186 return self._getUniversal(tc.DISTANCE_REQUEST, personID, "tou", 2, (x, y), tc.REQUEST_DRIVINGDIST) 187 188 def getWaitingTime(self, personID): 189 """getWaitingTime(string) -> double 190 The waiting time of a person is defined as the time (in seconds) spent with a 191 speed below 0.1m/s since the last time it was faster than 0.1m/s. 192 (basically, the waiting time of a person is reset to 0 every time it moves). 193 """ 194 return self._getUniversal(tc.VAR_WAITING_TIME, personID) 195 196 def getNextEdge(self, personID): 197 """getNextEdge(string) -> string 198 If the person is walking, returns the next edge on the persons route 199 (including crossing and walkingareas). If there is no further edge or the 200 person is in another stage, returns the empty string. 201 """ 202 return self._getUniversal(tc.VAR_NEXT_EDGE, personID) 203 204 def getEdges(self, personID, nextStageIndex=0): 205 """getEdges(string, int) -> tuple(string) 206 207 Returns a tuple of all edges in the nth next stage. 208 For waiting stages this is a single edge 209 For walking stages this is the complete route 210 For driving stages this is [origin, destination] 211 212 nextStageIndex 0 retrieves value for the current stage. 213 nextStageIndex must be lower then value of getRemainingStages(personID) 214 """ 215 return self._getUniversal(tc.VAR_EDGES, personID, "i", nextStageIndex) 216 217 def getStage(self, personID, nextStageIndex=0): 218 """getStage(string, int) -> stage 219 Returns the nth stage object (type simulation.Stage) 220 Attribute type of this object has the following meaning: 221 0 for not-yet-departed 222 1 for waiting 223 2 for walking 224 3 for driving 225 4 for access to busStop or trainStop 226 5 for personTrip 227 nextStageIndex 0 retrieves value for the current stage. 228 nextStageIndex must be lower then value of getRemainingStages(personID) 229 """ 230 return self._getUniversal(tc.VAR_STAGE, personID, "i", nextStageIndex) 231 232 def getRemainingStages(self, personID): 233 """getRemainingStages(string) -> int 234 Returns the number of remaining stages (at least 1) 235 """ 236 return self._getUniversal(tc.VAR_STAGES_REMAINING, personID) 237 238 def getVehicle(self, personID): 239 """getVehicle(string) -> string 240 Returns the id of the current vehicle if the person is in stage driving 241 and has entered a vehicle. 242 Return the empty string otherwise 243 """ 244 return self._getUniversal(tc.VAR_VEHICLE, personID) 245 246 def getTaxiReservations(self, onlyNew=0): 247 """getTaxiReservations(int) -> tuple(Reservation) 248 Returns all reservations. If onlyNew is 1, each reservation is returned 249 only once 250 """ 251 return self._getUniversal(tc.VAR_TAXI_RESERVATIONS, "", "i", onlyNew) 252 253 def splitTaxiReservation(self, reservationID, personIDs): 254 """splitTaxiReservation(string, list(string)) -> string 255 Splits given list of person ids from the reservation with the given id 256 and creates a new reservation for these persons. Returns the new 257 reservation id. 258 """ 259 return self._getUniversal(tc.SPLIT_TAXI_RESERVATIONS, reservationID, "l", personIDs) 260 261 def removeStages(self, personID): 262 """removeStages(string) 263 Removes all stages of the person. If no new phases are appended, 264 the person will be removed from the simulation in the next simulationStep(). 265 """ 266 # remove all stages after the current and then abort the current stage 267 while self.getRemainingStages(personID) > 1: 268 self.removeStage(personID, 1) 269 self.removeStage(personID, 0) 270 271 def add(self, personID, edgeID, pos, depart=tc.DEPARTFLAG_NOW, typeID="DEFAULT_PEDTYPE"): 272 """add(string, string, double, double, string) 273 Inserts a new person to the simulation at the given edge, position and 274 time (in s). This function should be followed by appending Stages or the person 275 will immediately vanish on departure. 276 """ 277 format = "tssdd" 278 values = [4, typeID, edgeID, depart, pos] 279 self._setCmd(tc.ADD, personID, format, *values) 280 281 def appendWaitingStage(self, personID, duration, description="waiting", stopID=""): 282 """appendWaitingStage(string, float, string, string) 283 Appends a waiting stage with duration in s to the plan of the given person 284 """ 285 format = "tidss" 286 values = [4, tc.STAGE_WAITING, duration, description, stopID] 287 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 288 289 def appendWalkingStage(self, personID, edges, arrivalPos, duration=-1, speed=-1, stopID=""): 290 """appendWalkingStage(string, stringList, double, double, double, string) 291 Appends a walking stage to the plan of the given person 292 The walking speed can either be specified, computed from the duration parameter (in s) or taken from the 293 type of the person 294 """ 295 if isinstance(edges, str): 296 edges = [edges] 297 format = "tilddds" 298 values = [6, tc.STAGE_WALKING, edges, arrivalPos, duration, speed, stopID] 299 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 300 301 def appendDrivingStage(self, personID, toEdge, lines, stopID=""): 302 """appendDrivingStage(string, string, string, string) 303 Appends a driving stage to the plan of the given person 304 The lines parameter should be a space-separated list of line ids 305 """ 306 format = "tisss" 307 values = [4, tc.STAGE_DRIVING, toEdge, lines, stopID] 308 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 309 310 def appendStage(self, personID, stage): 311 """appendStage(string, stage) 312 Appends a stage object to the plan of the given person 313 Such an object is obtainable using getStage 314 """ 315 format, values = simulation._writeStage(stage) 316 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 317 318 def replaceStage(self, personID, stageIndex, stage): 319 """replaceStage(string, int, stage) 320 Replaces the nth subsequent stage with the given stage object 321 Such an object is obtainable using getStage 322 """ 323 format, values = simulation._writeStage(stage) 324 format = "ti" + format 325 values = [2, stageIndex] + values 326 self._setCmd(tc.REPLACE_STAGE, personID, format, *values) 327 328 def removeStage(self, personID, nextStageIndex): 329 """removeStage(string, int) 330 Removes the nth next stage 331 nextStageIndex must be lower then value of getRemainingStages(personID) 332 nextStageIndex 0 immediately aborts the current stage and proceeds to the next stage 333 """ 334 self._setCmd(tc.REMOVE_STAGE, personID, "i", nextStageIndex) 335 336 def rerouteTraveltime(self, personID): 337 """rerouteTraveltime(string) -> None Reroutes a pedestrian (walking person). 338 """ 339 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, personID, "t", 0) 340 341 def remove(self, personID, reason=tc.REMOVE_VAPORIZED): 342 '''Remove person with the given ID for the give reason. 343 Reasons are defined in module constants and start with REMOVE_''' 344 self._setCmd(tc.REMOVE, personID, "b", reason) 345 346 def moveTo(self, personID, laneID, pos, posLat=tc.INVALID_DOUBLE_VALUE): 347 """moveTo(string, string, double, double) -> None 348 349 Move a person to a new position along its current route. 350 """ 351 self._setCmd(tc.VAR_MOVE_TO, personID, "tsdd", 3, laneID, pos, posLat) 352 353 def moveToXY(self, personID, edgeID, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 354 '''Place person at the given x,y coordinates and force its angle to 355 the given value (for drawing). 356 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 357 natural angle of the edge on which it is driving. 358 If keepRoute is set to 1, the closest position 359 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 360 any edge in the network but its route then only consists of that edge. 361 If keepRoute is set to 2 the person has all the freedom of keepRoute=0 362 but in addition to that may even move outside the road network. 363 edgeID is an optional placement hint to resolve ambiguities. 364 The command fails if no suitable target position is found within the 365 distance given by matchThreshold. 366 ''' 367 format = "tsdddbd" 368 values = [6, edgeID, x, y, angle, keepRoute, matchThreshold] 369 self._setCmd(tc.MOVE_TO_XY, personID, format, *values) 370 371 def setSpeed(self, personID, speed): 372 """setSpeed(string, double) -> None 373 374 Sets the maximum speed in m/s for the named person for subsequent step. 375 """ 376 self._setCmd(tc.VAR_SPEED, personID, "d", speed) 377 378 def setType(self, personID, typeID): 379 """setType(string, string) -> None 380 381 Sets the id of the type for the named person. 382 """ 383 self._setCmd(tc.VAR_TYPE, personID, "s", typeID)
25class Reservation(object): 26 27 def __init__(self, id, persons, group, fromEdge, toEdge, departPos, arrivalPos, 28 depart, reservationTime, state): 29 self.id = id 30 self.persons = persons 31 self.group = group 32 self.fromEdge = fromEdge 33 self.toEdge = toEdge 34 self.arrivalPos = arrivalPos 35 self.departPos = departPos 36 self.depart = depart 37 self.reservationTime = reservationTime 38 self.state = state 39 40 def __attr_repr__(self, attrname, default=""): 41 if getattr(self, attrname) == default: 42 return "" 43 else: 44 val = getattr(self, attrname) 45 if val == tc.INVALID_DOUBLE_VALUE: 46 val = "INVALID" 47 return "%s=%s" % (attrname, val) 48 49 def __repr__(self): 50 return "Reservation(%s)" % ', '.join([v for v in [ 51 self.__attr_repr__("id"), 52 self.__attr_repr__("persons"), 53 self.__attr_repr__("group"), 54 self.__attr_repr__("fromEdge"), 55 self.__attr_repr__("toEdge"), 56 self.__attr_repr__("departPos"), 57 self.__attr_repr__("arrivalPos"), 58 self.__attr_repr__("depart"), 59 self.__attr_repr__("reservationTime"), 60 self.__attr_repr__("state"), 61 ] if v != ""])
27 def __init__(self, id, persons, group, fromEdge, toEdge, departPos, arrivalPos, 28 depart, reservationTime, state): 29 self.id = id 30 self.persons = persons 31 self.group = group 32 self.fromEdge = fromEdge 33 self.toEdge = toEdge 34 self.arrivalPos = arrivalPos 35 self.departPos = departPos 36 self.depart = depart 37 self.reservationTime = reservationTime 38 self.state = state
90class PersonDomain(VTypeDomain): 91 92 Reservation = Reservation 93 94 def __init__(self): 95 VTypeDomain.__init__(self, "person", tc.CMD_GET_PERSON_VARIABLE, tc.CMD_SET_PERSON_VARIABLE, 96 tc.CMD_SUBSCRIBE_PERSON_VARIABLE, tc.RESPONSE_SUBSCRIBE_PERSON_VARIABLE, 97 tc.CMD_SUBSCRIBE_PERSON_CONTEXT, tc.RESPONSE_SUBSCRIBE_PERSON_CONTEXT, 98 _RETURN_VALUE_FUNC) 99 100 def getSpeed(self, personID): 101 """getSpeed(string) -> double 102 103 Returns the speed in m/s of the named person within the last step. 104 """ 105 return self._getUniversal(tc.VAR_SPEED, personID) 106 107 def getPosition(self, personID): 108 """getPosition(string) -> (double, double) 109 110 Returns the position of the named person within the last step [m,m]. 111 """ 112 return self._getUniversal(tc.VAR_POSITION, personID) 113 114 def getPosition3D(self, personID): 115 """getPosition3D(string) -> (double, double, double) 116 117 Returns the position of the named person within the last step [m,m,m]. 118 """ 119 return self._getUniversal(tc.VAR_POSITION3D, personID) 120 121 def getAngle(self, personID): 122 """getAngle(string) -> double 123 124 Returns the angle in degrees of the named person within the last step. 125 """ 126 return self._getUniversal(tc.VAR_ANGLE, personID) 127 128 def getSlope(self, personID): 129 """getSlope(string) -> double 130 131 Returns the slope at the current position of the person in degrees 132 """ 133 return self._getUniversal(tc.VAR_SLOPE, personID) 134 135 def getRoadID(self, personID): 136 """getRoadID(string) -> string 137 138 Returns the id of the edge the named person was at within the last step. 139 """ 140 return self._getUniversal(tc.VAR_ROAD_ID, personID) 141 142 def getLaneID(self, personID): 143 """getLaneID(string) -> string 144 145 Returns the id of the lane the named person was at within the last step. 146 If the current person stage does not provide a lane, "" is returned. 147 """ 148 return self._getUniversal(tc.VAR_LANE_ID, personID) 149 150 def getTypeID(self, personID): 151 """getTypeID(string) -> string 152 153 Returns the id of the type of the named person. 154 """ 155 return self._getUniversal(tc.VAR_TYPE, personID) 156 157 def getLanePosition(self, personID): 158 """getLanePosition(string) -> double 159 160 The position of the person along the lane measured in m. 161 """ 162 return self._getUniversal(tc.VAR_LANEPOSITION, personID) 163 164 def getArrivalPos(self, personID): 165 """getArrivalPos(string) -> double 166 167 The final arrival position of the person's plan in m. 168 """ 169 return self._getUniversal(tc.VAR_ARRIVALPOS, personID) 170 171 def getWalkingDistance(self, personID, edgeID, pos, laneIndex=0): 172 """getWalkingDistance(string, string, double, integer) -> double 173 174 For a person in walking stage and an edge along the remaining route of 175 personID, return the distance from the current position 176 to the given edge and position along the walk. 177 Otherwise, raise a TraCIException 178 """ 179 return self._getUniversal(tc.DISTANCE_REQUEST, personID, "tru", 2, 180 (edgeID, pos, laneIndex), tc.REQUEST_DRIVINGDIST) 181 182 def getWalkingDistance2D(self, personID, x, y): 183 """getWalkingDistance2D(string, double, double) -> integer 184 185 Return the distance to the given network position along the walk (see getWalkingDistance) 186 """ 187 return self._getUniversal(tc.DISTANCE_REQUEST, personID, "tou", 2, (x, y), tc.REQUEST_DRIVINGDIST) 188 189 def getWaitingTime(self, personID): 190 """getWaitingTime(string) -> double 191 The waiting time of a person is defined as the time (in seconds) spent with a 192 speed below 0.1m/s since the last time it was faster than 0.1m/s. 193 (basically, the waiting time of a person is reset to 0 every time it moves). 194 """ 195 return self._getUniversal(tc.VAR_WAITING_TIME, personID) 196 197 def getNextEdge(self, personID): 198 """getNextEdge(string) -> string 199 If the person is walking, returns the next edge on the persons route 200 (including crossing and walkingareas). If there is no further edge or the 201 person is in another stage, returns the empty string. 202 """ 203 return self._getUniversal(tc.VAR_NEXT_EDGE, personID) 204 205 def getEdges(self, personID, nextStageIndex=0): 206 """getEdges(string, int) -> tuple(string) 207 208 Returns a tuple of all edges in the nth next stage. 209 For waiting stages this is a single edge 210 For walking stages this is the complete route 211 For driving stages this is [origin, destination] 212 213 nextStageIndex 0 retrieves value for the current stage. 214 nextStageIndex must be lower then value of getRemainingStages(personID) 215 """ 216 return self._getUniversal(tc.VAR_EDGES, personID, "i", nextStageIndex) 217 218 def getStage(self, personID, nextStageIndex=0): 219 """getStage(string, int) -> stage 220 Returns the nth stage object (type simulation.Stage) 221 Attribute type of this object has the following meaning: 222 0 for not-yet-departed 223 1 for waiting 224 2 for walking 225 3 for driving 226 4 for access to busStop or trainStop 227 5 for personTrip 228 nextStageIndex 0 retrieves value for the current stage. 229 nextStageIndex must be lower then value of getRemainingStages(personID) 230 """ 231 return self._getUniversal(tc.VAR_STAGE, personID, "i", nextStageIndex) 232 233 def getRemainingStages(self, personID): 234 """getRemainingStages(string) -> int 235 Returns the number of remaining stages (at least 1) 236 """ 237 return self._getUniversal(tc.VAR_STAGES_REMAINING, personID) 238 239 def getVehicle(self, personID): 240 """getVehicle(string) -> string 241 Returns the id of the current vehicle if the person is in stage driving 242 and has entered a vehicle. 243 Return the empty string otherwise 244 """ 245 return self._getUniversal(tc.VAR_VEHICLE, personID) 246 247 def getTaxiReservations(self, onlyNew=0): 248 """getTaxiReservations(int) -> tuple(Reservation) 249 Returns all reservations. If onlyNew is 1, each reservation is returned 250 only once 251 """ 252 return self._getUniversal(tc.VAR_TAXI_RESERVATIONS, "", "i", onlyNew) 253 254 def splitTaxiReservation(self, reservationID, personIDs): 255 """splitTaxiReservation(string, list(string)) -> string 256 Splits given list of person ids from the reservation with the given id 257 and creates a new reservation for these persons. Returns the new 258 reservation id. 259 """ 260 return self._getUniversal(tc.SPLIT_TAXI_RESERVATIONS, reservationID, "l", personIDs) 261 262 def removeStages(self, personID): 263 """removeStages(string) 264 Removes all stages of the person. If no new phases are appended, 265 the person will be removed from the simulation in the next simulationStep(). 266 """ 267 # remove all stages after the current and then abort the current stage 268 while self.getRemainingStages(personID) > 1: 269 self.removeStage(personID, 1) 270 self.removeStage(personID, 0) 271 272 def add(self, personID, edgeID, pos, depart=tc.DEPARTFLAG_NOW, typeID="DEFAULT_PEDTYPE"): 273 """add(string, string, double, double, string) 274 Inserts a new person to the simulation at the given edge, position and 275 time (in s). This function should be followed by appending Stages or the person 276 will immediately vanish on departure. 277 """ 278 format = "tssdd" 279 values = [4, typeID, edgeID, depart, pos] 280 self._setCmd(tc.ADD, personID, format, *values) 281 282 def appendWaitingStage(self, personID, duration, description="waiting", stopID=""): 283 """appendWaitingStage(string, float, string, string) 284 Appends a waiting stage with duration in s to the plan of the given person 285 """ 286 format = "tidss" 287 values = [4, tc.STAGE_WAITING, duration, description, stopID] 288 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 289 290 def appendWalkingStage(self, personID, edges, arrivalPos, duration=-1, speed=-1, stopID=""): 291 """appendWalkingStage(string, stringList, double, double, double, string) 292 Appends a walking stage to the plan of the given person 293 The walking speed can either be specified, computed from the duration parameter (in s) or taken from the 294 type of the person 295 """ 296 if isinstance(edges, str): 297 edges = [edges] 298 format = "tilddds" 299 values = [6, tc.STAGE_WALKING, edges, arrivalPos, duration, speed, stopID] 300 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 301 302 def appendDrivingStage(self, personID, toEdge, lines, stopID=""): 303 """appendDrivingStage(string, string, string, string) 304 Appends a driving stage to the plan of the given person 305 The lines parameter should be a space-separated list of line ids 306 """ 307 format = "tisss" 308 values = [4, tc.STAGE_DRIVING, toEdge, lines, stopID] 309 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 310 311 def appendStage(self, personID, stage): 312 """appendStage(string, stage) 313 Appends a stage object to the plan of the given person 314 Such an object is obtainable using getStage 315 """ 316 format, values = simulation._writeStage(stage) 317 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 318 319 def replaceStage(self, personID, stageIndex, stage): 320 """replaceStage(string, int, stage) 321 Replaces the nth subsequent stage with the given stage object 322 Such an object is obtainable using getStage 323 """ 324 format, values = simulation._writeStage(stage) 325 format = "ti" + format 326 values = [2, stageIndex] + values 327 self._setCmd(tc.REPLACE_STAGE, personID, format, *values) 328 329 def removeStage(self, personID, nextStageIndex): 330 """removeStage(string, int) 331 Removes the nth next stage 332 nextStageIndex must be lower then value of getRemainingStages(personID) 333 nextStageIndex 0 immediately aborts the current stage and proceeds to the next stage 334 """ 335 self._setCmd(tc.REMOVE_STAGE, personID, "i", nextStageIndex) 336 337 def rerouteTraveltime(self, personID): 338 """rerouteTraveltime(string) -> None Reroutes a pedestrian (walking person). 339 """ 340 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, personID, "t", 0) 341 342 def remove(self, personID, reason=tc.REMOVE_VAPORIZED): 343 '''Remove person with the given ID for the give reason. 344 Reasons are defined in module constants and start with REMOVE_''' 345 self._setCmd(tc.REMOVE, personID, "b", reason) 346 347 def moveTo(self, personID, laneID, pos, posLat=tc.INVALID_DOUBLE_VALUE): 348 """moveTo(string, string, double, double) -> None 349 350 Move a person to a new position along its current route. 351 """ 352 self._setCmd(tc.VAR_MOVE_TO, personID, "tsdd", 3, laneID, pos, posLat) 353 354 def moveToXY(self, personID, edgeID, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 355 '''Place person at the given x,y coordinates and force its angle to 356 the given value (for drawing). 357 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 358 natural angle of the edge on which it is driving. 359 If keepRoute is set to 1, the closest position 360 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 361 any edge in the network but its route then only consists of that edge. 362 If keepRoute is set to 2 the person has all the freedom of keepRoute=0 363 but in addition to that may even move outside the road network. 364 edgeID is an optional placement hint to resolve ambiguities. 365 The command fails if no suitable target position is found within the 366 distance given by matchThreshold. 367 ''' 368 format = "tsdddbd" 369 values = [6, edgeID, x, y, angle, keepRoute, matchThreshold] 370 self._setCmd(tc.MOVE_TO_XY, personID, format, *values) 371 372 def setSpeed(self, personID, speed): 373 """setSpeed(string, double) -> None 374 375 Sets the maximum speed in m/s for the named person for subsequent step. 376 """ 377 self._setCmd(tc.VAR_SPEED, personID, "d", speed) 378 379 def setType(self, personID, typeID): 380 """setType(string, string) -> None 381 382 Sets the id of the type for the named person. 383 """ 384 self._setCmd(tc.VAR_TYPE, personID, "s", typeID)
This class contains all functions which are common to the vehicletype, vehicle and person domain
100 def getSpeed(self, personID): 101 """getSpeed(string) -> double 102 103 Returns the speed in m/s of the named person within the last step. 104 """ 105 return self._getUniversal(tc.VAR_SPEED, personID)
getSpeed(string) -> double
Returns the speed in m/s of the named person within the last step.
107 def getPosition(self, personID): 108 """getPosition(string) -> (double, double) 109 110 Returns the position of the named person within the last step [m,m]. 111 """ 112 return self._getUniversal(tc.VAR_POSITION, personID)
getPosition(string) -> (double, double)
Returns the position of the named person within the last step [m,m].
114 def getPosition3D(self, personID): 115 """getPosition3D(string) -> (double, double, double) 116 117 Returns the position of the named person within the last step [m,m,m]. 118 """ 119 return self._getUniversal(tc.VAR_POSITION3D, personID)
getPosition3D(string) -> (double, double, double)
Returns the position of the named person within the last step [m,m,m].
121 def getAngle(self, personID): 122 """getAngle(string) -> double 123 124 Returns the angle in degrees of the named person within the last step. 125 """ 126 return self._getUniversal(tc.VAR_ANGLE, personID)
getAngle(string) -> double
Returns the angle in degrees of the named person within the last step.
128 def getSlope(self, personID): 129 """getSlope(string) -> double 130 131 Returns the slope at the current position of the person in degrees 132 """ 133 return self._getUniversal(tc.VAR_SLOPE, personID)
getSlope(string) -> double
Returns the slope at the current position of the person in degrees
135 def getRoadID(self, personID): 136 """getRoadID(string) -> string 137 138 Returns the id of the edge the named person was at within the last step. 139 """ 140 return self._getUniversal(tc.VAR_ROAD_ID, personID)
getRoadID(string) -> string
Returns the id of the edge the named person was at within the last step.
142 def getLaneID(self, personID): 143 """getLaneID(string) -> string 144 145 Returns the id of the lane the named person was at within the last step. 146 If the current person stage does not provide a lane, "" is returned. 147 """ 148 return self._getUniversal(tc.VAR_LANE_ID, personID)
getLaneID(string) -> string
Returns the id of the lane the named person was at within the last step. If the current person stage does not provide a lane, "" is returned.
150 def getTypeID(self, personID): 151 """getTypeID(string) -> string 152 153 Returns the id of the type of the named person. 154 """ 155 return self._getUniversal(tc.VAR_TYPE, personID)
getTypeID(string) -> string
Returns the id of the type of the named person.
157 def getLanePosition(self, personID): 158 """getLanePosition(string) -> double 159 160 The position of the person along the lane measured in m. 161 """ 162 return self._getUniversal(tc.VAR_LANEPOSITION, personID)
getLanePosition(string) -> double
The position of the person along the lane measured in m.
164 def getArrivalPos(self, personID): 165 """getArrivalPos(string) -> double 166 167 The final arrival position of the person's plan in m. 168 """ 169 return self._getUniversal(tc.VAR_ARRIVALPOS, personID)
getArrivalPos(string) -> double
The final arrival position of the person's plan in m.
171 def getWalkingDistance(self, personID, edgeID, pos, laneIndex=0): 172 """getWalkingDistance(string, string, double, integer) -> double 173 174 For a person in walking stage and an edge along the remaining route of 175 personID, return the distance from the current position 176 to the given edge and position along the walk. 177 Otherwise, raise a TraCIException 178 """ 179 return self._getUniversal(tc.DISTANCE_REQUEST, personID, "tru", 2, 180 (edgeID, pos, laneIndex), tc.REQUEST_DRIVINGDIST)
getWalkingDistance(string, string, double, integer) -> double
For a person in walking stage and an edge along the remaining route of personID, return the distance from the current position to the given edge and position along the walk. Otherwise, raise a TraCIException
182 def getWalkingDistance2D(self, personID, x, y): 183 """getWalkingDistance2D(string, double, double) -> integer 184 185 Return the distance to the given network position along the walk (see getWalkingDistance) 186 """ 187 return self._getUniversal(tc.DISTANCE_REQUEST, personID, "tou", 2, (x, y), tc.REQUEST_DRIVINGDIST)
getWalkingDistance2D(string, double, double) -> integer
Return the distance to the given network position along the walk (see getWalkingDistance)
189 def getWaitingTime(self, personID): 190 """getWaitingTime(string) -> double 191 The waiting time of a person is defined as the time (in seconds) spent with a 192 speed below 0.1m/s since the last time it was faster than 0.1m/s. 193 (basically, the waiting time of a person is reset to 0 every time it moves). 194 """ 195 return self._getUniversal(tc.VAR_WAITING_TIME, personID)
getWaitingTime(string) -> double The waiting time of a person 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 person is reset to 0 every time it moves).
197 def getNextEdge(self, personID): 198 """getNextEdge(string) -> string 199 If the person is walking, returns the next edge on the persons route 200 (including crossing and walkingareas). If there is no further edge or the 201 person is in another stage, returns the empty string. 202 """ 203 return self._getUniversal(tc.VAR_NEXT_EDGE, personID)
getNextEdge(string) -> string If the person is walking, returns the next edge on the persons route (including crossing and walkingareas). If there is no further edge or the person is in another stage, returns the empty string.
205 def getEdges(self, personID, nextStageIndex=0): 206 """getEdges(string, int) -> tuple(string) 207 208 Returns a tuple of all edges in the nth next stage. 209 For waiting stages this is a single edge 210 For walking stages this is the complete route 211 For driving stages this is [origin, destination] 212 213 nextStageIndex 0 retrieves value for the current stage. 214 nextStageIndex must be lower then value of getRemainingStages(personID) 215 """ 216 return self._getUniversal(tc.VAR_EDGES, personID, "i", nextStageIndex)
getEdges(string, int) -> tuple(string)
Returns a tuple of all edges in the nth next stage. For waiting stages this is a single edge For walking stages this is the complete route For driving stages this is [origin, destination]
nextStageIndex 0 retrieves value for the current stage. nextStageIndex must be lower then value of getRemainingStages(personID)
218 def getStage(self, personID, nextStageIndex=0): 219 """getStage(string, int) -> stage 220 Returns the nth stage object (type simulation.Stage) 221 Attribute type of this object has the following meaning: 222 0 for not-yet-departed 223 1 for waiting 224 2 for walking 225 3 for driving 226 4 for access to busStop or trainStop 227 5 for personTrip 228 nextStageIndex 0 retrieves value for the current stage. 229 nextStageIndex must be lower then value of getRemainingStages(personID) 230 """ 231 return self._getUniversal(tc.VAR_STAGE, personID, "i", nextStageIndex)
getStage(string, int) -> stage Returns the nth stage object (type simulation.Stage) Attribute type of this object has the following meaning: 0 for not-yet-departed 1 for waiting 2 for walking 3 for driving 4 for access to busStop or trainStop 5 for personTrip nextStageIndex 0 retrieves value for the current stage. nextStageIndex must be lower then value of getRemainingStages(personID)
233 def getRemainingStages(self, personID): 234 """getRemainingStages(string) -> int 235 Returns the number of remaining stages (at least 1) 236 """ 237 return self._getUniversal(tc.VAR_STAGES_REMAINING, personID)
getRemainingStages(string) -> int Returns the number of remaining stages (at least 1)
239 def getVehicle(self, personID): 240 """getVehicle(string) -> string 241 Returns the id of the current vehicle if the person is in stage driving 242 and has entered a vehicle. 243 Return the empty string otherwise 244 """ 245 return self._getUniversal(tc.VAR_VEHICLE, personID)
getVehicle(string) -> string Returns the id of the current vehicle if the person is in stage driving and has entered a vehicle. Return the empty string otherwise
247 def getTaxiReservations(self, onlyNew=0): 248 """getTaxiReservations(int) -> tuple(Reservation) 249 Returns all reservations. If onlyNew is 1, each reservation is returned 250 only once 251 """ 252 return self._getUniversal(tc.VAR_TAXI_RESERVATIONS, "", "i", onlyNew)
getTaxiReservations(int) -> tuple(Reservation) Returns all reservations. If onlyNew is 1, each reservation is returned only once
254 def splitTaxiReservation(self, reservationID, personIDs): 255 """splitTaxiReservation(string, list(string)) -> string 256 Splits given list of person ids from the reservation with the given id 257 and creates a new reservation for these persons. Returns the new 258 reservation id. 259 """ 260 return self._getUniversal(tc.SPLIT_TAXI_RESERVATIONS, reservationID, "l", personIDs)
splitTaxiReservation(string, list(string)) -> string Splits given list of person ids from the reservation with the given id and creates a new reservation for these persons. Returns the new reservation id.
262 def removeStages(self, personID): 263 """removeStages(string) 264 Removes all stages of the person. If no new phases are appended, 265 the person will be removed from the simulation in the next simulationStep(). 266 """ 267 # remove all stages after the current and then abort the current stage 268 while self.getRemainingStages(personID) > 1: 269 self.removeStage(personID, 1) 270 self.removeStage(personID, 0)
removeStages(string) Removes all stages of the person. If no new phases are appended, the person will be removed from the simulation in the next simulationStep().
272 def add(self, personID, edgeID, pos, depart=tc.DEPARTFLAG_NOW, typeID="DEFAULT_PEDTYPE"): 273 """add(string, string, double, double, string) 274 Inserts a new person to the simulation at the given edge, position and 275 time (in s). This function should be followed by appending Stages or the person 276 will immediately vanish on departure. 277 """ 278 format = "tssdd" 279 values = [4, typeID, edgeID, depart, pos] 280 self._setCmd(tc.ADD, personID, format, *values)
add(string, string, double, double, string) Inserts a new person to the simulation at the given edge, position and time (in s). This function should be followed by appending Stages or the person will immediately vanish on departure.
282 def appendWaitingStage(self, personID, duration, description="waiting", stopID=""): 283 """appendWaitingStage(string, float, string, string) 284 Appends a waiting stage with duration in s to the plan of the given person 285 """ 286 format = "tidss" 287 values = [4, tc.STAGE_WAITING, duration, description, stopID] 288 self._setCmd(tc.APPEND_STAGE, personID, format, *values)
appendWaitingStage(string, float, string, string) Appends a waiting stage with duration in s to the plan of the given person
290 def appendWalkingStage(self, personID, edges, arrivalPos, duration=-1, speed=-1, stopID=""): 291 """appendWalkingStage(string, stringList, double, double, double, string) 292 Appends a walking stage to the plan of the given person 293 The walking speed can either be specified, computed from the duration parameter (in s) or taken from the 294 type of the person 295 """ 296 if isinstance(edges, str): 297 edges = [edges] 298 format = "tilddds" 299 values = [6, tc.STAGE_WALKING, edges, arrivalPos, duration, speed, stopID] 300 self._setCmd(tc.APPEND_STAGE, personID, format, *values)
appendWalkingStage(string, stringList, double, double, double, string) Appends a walking stage to the plan of the given person The walking speed can either be specified, computed from the duration parameter (in s) or taken from the type of the person
302 def appendDrivingStage(self, personID, toEdge, lines, stopID=""): 303 """appendDrivingStage(string, string, string, string) 304 Appends a driving stage to the plan of the given person 305 The lines parameter should be a space-separated list of line ids 306 """ 307 format = "tisss" 308 values = [4, tc.STAGE_DRIVING, toEdge, lines, stopID] 309 self._setCmd(tc.APPEND_STAGE, personID, format, *values)
appendDrivingStage(string, string, string, string) Appends a driving stage to the plan of the given person The lines parameter should be a space-separated list of line ids
311 def appendStage(self, personID, stage): 312 """appendStage(string, stage) 313 Appends a stage object to the plan of the given person 314 Such an object is obtainable using getStage 315 """ 316 format, values = simulation._writeStage(stage) 317 self._setCmd(tc.APPEND_STAGE, personID, format, *values)
appendStage(string, stage) Appends a stage object to the plan of the given person Such an object is obtainable using getStage
319 def replaceStage(self, personID, stageIndex, stage): 320 """replaceStage(string, int, stage) 321 Replaces the nth subsequent stage with the given stage object 322 Such an object is obtainable using getStage 323 """ 324 format, values = simulation._writeStage(stage) 325 format = "ti" + format 326 values = [2, stageIndex] + values 327 self._setCmd(tc.REPLACE_STAGE, personID, format, *values)
replaceStage(string, int, stage) Replaces the nth subsequent stage with the given stage object Such an object is obtainable using getStage
329 def removeStage(self, personID, nextStageIndex): 330 """removeStage(string, int) 331 Removes the nth next stage 332 nextStageIndex must be lower then value of getRemainingStages(personID) 333 nextStageIndex 0 immediately aborts the current stage and proceeds to the next stage 334 """ 335 self._setCmd(tc.REMOVE_STAGE, personID, "i", nextStageIndex)
removeStage(string, int) Removes the nth next stage nextStageIndex must be lower then value of getRemainingStages(personID) nextStageIndex 0 immediately aborts the current stage and proceeds to the next stage
337 def rerouteTraveltime(self, personID): 338 """rerouteTraveltime(string) -> None Reroutes a pedestrian (walking person). 339 """ 340 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, personID, "t", 0)
rerouteTraveltime(string) -> None Reroutes a pedestrian (walking person).
342 def remove(self, personID, reason=tc.REMOVE_VAPORIZED): 343 '''Remove person with the given ID for the give reason. 344 Reasons are defined in module constants and start with REMOVE_''' 345 self._setCmd(tc.REMOVE, personID, "b", reason)
Remove person with the given ID for the give reason. Reasons are defined in module constants and start with REMOVE_
347 def moveTo(self, personID, laneID, pos, posLat=tc.INVALID_DOUBLE_VALUE): 348 """moveTo(string, string, double, double) -> None 349 350 Move a person to a new position along its current route. 351 """ 352 self._setCmd(tc.VAR_MOVE_TO, personID, "tsdd", 3, laneID, pos, posLat)
moveTo(string, string, double, double) -> None
Move a person to a new position along its current route.
354 def moveToXY(self, personID, edgeID, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 355 '''Place person at the given x,y coordinates and force its angle to 356 the given value (for drawing). 357 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 358 natural angle of the edge on which it is driving. 359 If keepRoute is set to 1, the closest position 360 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 361 any edge in the network but its route then only consists of that edge. 362 If keepRoute is set to 2 the person has all the freedom of keepRoute=0 363 but in addition to that may even move outside the road network. 364 edgeID is an optional placement hint to resolve ambiguities. 365 The command fails if no suitable target position is found within the 366 distance given by matchThreshold. 367 ''' 368 format = "tsdddbd" 369 values = [6, edgeID, x, y, angle, keepRoute, matchThreshold] 370 self._setCmd(tc.MOVE_TO_XY, personID, format, *values)
Place person 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 person has all the freedom of keepRoute=0 but in addition to that may even move outside the road network. edgeID is an optional placement hint to resolve ambiguities. The command fails if no suitable target position is found within the distance given by matchThreshold.
372 def setSpeed(self, personID, speed): 373 """setSpeed(string, double) -> None 374 375 Sets the maximum speed in m/s for the named person for subsequent step. 376 """ 377 self._setCmd(tc.VAR_SPEED, personID, "d", speed)
setSpeed(string, double) -> None
Sets the maximum speed in m/s for the named person for subsequent step.
379 def setType(self, personID, typeID): 380 """setType(string, string) -> None 381 382 Sets the id of the type for the named person. 383 """ 384 self._setCmd(tc.VAR_TYPE, personID, "s", typeID)
setType(string, string) -> None
Sets the id of the type for the named person.
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
25class Reservation(object): 26 27 def __init__(self, id, persons, group, fromEdge, toEdge, departPos, arrivalPos, 28 depart, reservationTime, state): 29 self.id = id 30 self.persons = persons 31 self.group = group 32 self.fromEdge = fromEdge 33 self.toEdge = toEdge 34 self.arrivalPos = arrivalPos 35 self.departPos = departPos 36 self.depart = depart 37 self.reservationTime = reservationTime 38 self.state = state 39 40 def __attr_repr__(self, attrname, default=""): 41 if getattr(self, attrname) == default: 42 return "" 43 else: 44 val = getattr(self, attrname) 45 if val == tc.INVALID_DOUBLE_VALUE: 46 val = "INVALID" 47 return "%s=%s" % (attrname, val) 48 49 def __repr__(self): 50 return "Reservation(%s)" % ', '.join([v for v in [ 51 self.__attr_repr__("id"), 52 self.__attr_repr__("persons"), 53 self.__attr_repr__("group"), 54 self.__attr_repr__("fromEdge"), 55 self.__attr_repr__("toEdge"), 56 self.__attr_repr__("departPos"), 57 self.__attr_repr__("arrivalPos"), 58 self.__attr_repr__("depart"), 59 self.__attr_repr__("reservationTime"), 60 self.__attr_repr__("state"), 61 ] if v != ""])