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 getWalkingDistance(self, personID, edgeID, pos, laneIndex=0): 164 """getWalkingDistance(string, string, double, integer) -> double 165 166 For a person in walking stage and an edge along the remaining route of 167 personID, return the distance from the current position 168 to the given edge and position along the walk. 169 Otherwise, raise a TraCIException 170 """ 171 return self._getUniversal(tc.DISTANCE_REQUEST, personID, "tru", 2, 172 (edgeID, pos, laneIndex), tc.REQUEST_DRIVINGDIST) 173 174 def getWalkingDistance2D(self, personID, x, y): 175 """getWalkingDistance2D(string, double, double) -> integer 176 177 Return the distance to the given network position along the walk (see getWalkingDistance) 178 """ 179 return self._getUniversal(tc.DISTANCE_REQUEST, personID, "tou", 2, (x, y), tc.REQUEST_DRIVINGDIST) 180 181 def getWaitingTime(self, personID): 182 """getWaitingTime(string) -> double 183 The waiting time of a person is defined as the time (in seconds) spent with a 184 speed below 0.1m/s since the last time it was faster than 0.1m/s. 185 (basically, the waiting time of a person is reset to 0 every time it moves). 186 """ 187 return self._getUniversal(tc.VAR_WAITING_TIME, personID) 188 189 def getNextEdge(self, personID): 190 """getNextEdge(string) -> string 191 If the person is walking, returns the next edge on the persons route 192 (including crossing and walkingareas). If there is no further edge or the 193 person is in another stage, returns the empty string. 194 """ 195 return self._getUniversal(tc.VAR_NEXT_EDGE, personID) 196 197 def getEdges(self, personID, nextStageIndex=0): 198 """getEdges(string, int) -> tuple(string) 199 200 Returns a tuple of all edges in the nth next stage. 201 For waiting stages this is a single edge 202 For walking stages this is the complete route 203 For driving stages this is [origin, destination] 204 205 nextStageIndex 0 retrieves value for the current stage. 206 nextStageIndex must be lower then value of getRemainingStages(personID) 207 """ 208 return self._getUniversal(tc.VAR_EDGES, personID, "i", nextStageIndex) 209 210 def getStage(self, personID, nextStageIndex=0): 211 """getStage(string, int) -> stage 212 Returns the nth stage object (type simulation.Stage) 213 Attribute type of this object has the following meaning: 214 0 for not-yet-departed 215 1 for waiting 216 2 for walking 217 3 for driving 218 4 for access to busStop or trainStop 219 5 for personTrip 220 nextStageIndex 0 retrieves value for the current stage. 221 nextStageIndex must be lower then value of getRemainingStages(personID) 222 """ 223 return self._getUniversal(tc.VAR_STAGE, personID, "i", nextStageIndex) 224 225 def getRemainingStages(self, personID): 226 """getRemainingStages(string) -> int 227 Returns the number of remaining stages (at least 1) 228 """ 229 return self._getUniversal(tc.VAR_STAGES_REMAINING, personID) 230 231 def getVehicle(self, personID): 232 """getVehicle(string) -> string 233 Returns the id of the current vehicle if the person is in stage driving 234 and has entered a vehicle. 235 Return the empty string otherwise 236 """ 237 return self._getUniversal(tc.VAR_VEHICLE, personID) 238 239 def getTaxiReservations(self, onlyNew=0): 240 """getTaxiReservations(int) -> tuple(Reservation) 241 Returns all reservations. If onlyNew is 1, each reservation is returned 242 only once 243 """ 244 return self._getUniversal(tc.VAR_TAXI_RESERVATIONS, "", "i", onlyNew) 245 246 def splitTaxiReservation(self, reservationID, personIDs): 247 """splitTaxiReservation(string, list(string)) -> string 248 Splits given list of person ids from the reservation with the given id 249 and creates a new reservation for these persons. Returns the new 250 reservation id. 251 """ 252 return self._getUniversal(tc.SPLIT_TAXI_RESERVATIONS, reservationID, "l", personIDs) 253 254 def removeStages(self, personID): 255 """removeStages(string) 256 Removes all stages of the person. If no new phases are appended, 257 the person will be removed from the simulation in the next simulationStep(). 258 """ 259 # remove all stages after the current and then abort the current stage 260 while self.getRemainingStages(personID) > 1: 261 self.removeStage(personID, 1) 262 self.removeStage(personID, 0) 263 264 def add(self, personID, edgeID, pos, depart=tc.DEPARTFLAG_NOW, typeID="DEFAULT_PEDTYPE"): 265 """add(string, string, double, double, string) 266 Inserts a new person to the simulation at the given edge, position and 267 time (in s). This function should be followed by appending Stages or the person 268 will immediately vanish on departure. 269 """ 270 format = "tssdd" 271 values = [4, typeID, edgeID, depart, pos] 272 self._setCmd(tc.ADD, personID, format, *values) 273 274 def appendWaitingStage(self, personID, duration, description="waiting", stopID=""): 275 """appendWaitingStage(string, float, string, string) 276 Appends a waiting stage with duration in s to the plan of the given person 277 """ 278 format = "tidss" 279 values = [4, tc.STAGE_WAITING, duration, description, stopID] 280 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 281 282 def appendWalkingStage(self, personID, edges, arrivalPos, duration=-1, speed=-1, stopID=""): 283 """appendWalkingStage(string, stringList, double, double, double, string) 284 Appends a walking stage to the plan of the given person 285 The walking speed can either be specified, computed from the duration parameter (in s) or taken from the 286 type of the person 287 """ 288 if isinstance(edges, str): 289 edges = [edges] 290 format = "tilddds" 291 values = [6, tc.STAGE_WALKING, edges, arrivalPos, duration, speed, stopID] 292 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 293 294 def appendDrivingStage(self, personID, toEdge, lines, stopID=""): 295 """appendDrivingStage(string, string, string, string) 296 Appends a driving stage to the plan of the given person 297 The lines parameter should be a space-separated list of line ids 298 """ 299 format = "tisss" 300 values = [4, tc.STAGE_DRIVING, toEdge, lines, stopID] 301 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 302 303 def appendStage(self, personID, stage): 304 """appendStage(string, stage) 305 Appends a stage object to the plan of the given person 306 Such an object is obtainable using getStage 307 """ 308 format, values = simulation._writeStage(stage) 309 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 310 311 def replaceStage(self, personID, stageIndex, stage): 312 """replaceStage(string, int, stage) 313 Replaces the nth subsequent stage with the given stage object 314 Such an object is obtainable using getStage 315 """ 316 format, values = simulation._writeStage(stage) 317 format = "ti" + format 318 values = [2, stageIndex] + values 319 self._setCmd(tc.REPLACE_STAGE, personID, format, *values) 320 321 def removeStage(self, personID, nextStageIndex): 322 """removeStage(string, int) 323 Removes the nth next stage 324 nextStageIndex must be lower then value of getRemainingStages(personID) 325 nextStageIndex 0 immediately aborts the current stage and proceeds to the next stage 326 """ 327 self._setCmd(tc.REMOVE_STAGE, personID, "i", nextStageIndex) 328 329 def rerouteTraveltime(self, personID): 330 """rerouteTraveltime(string) -> None Reroutes a pedestrian (walking person). 331 """ 332 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, personID, "t", 0) 333 334 def remove(self, personID, reason=tc.REMOVE_VAPORIZED): 335 '''Remove person with the given ID for the give reason. 336 Reasons are defined in module constants and start with REMOVE_''' 337 self._setCmd(tc.REMOVE, personID, "b", reason) 338 339 def moveTo(self, personID, laneID, pos, posLat=tc.INVALID_DOUBLE_VALUE): 340 """moveTo(string, string, double, double) -> None 341 342 Move a person to a new position along its current route. 343 """ 344 self._setCmd(tc.VAR_MOVE_TO, personID, "tsdd", 3, laneID, pos, posLat) 345 346 def moveToXY(self, personID, edgeID, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 347 '''Place person at the given x,y coordinates and force its angle to 348 the given value (for drawing). 349 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 350 natural angle of the edge on which it is driving. 351 If keepRoute is set to 1, the closest position 352 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 353 any edge in the network but its route then only consists of that edge. 354 If keepRoute is set to 2 the person has all the freedom of keepRoute=0 355 but in addition to that may even move outside the road network. 356 edgeID is an optional placement hint to resolve ambiguities. 357 The command fails if no suitable target position is found within the 358 distance given by matchThreshold. 359 ''' 360 format = "tsdddbd" 361 values = [6, edgeID, x, y, angle, keepRoute, matchThreshold] 362 self._setCmd(tc.MOVE_TO_XY, personID, format, *values) 363 364 def setSpeed(self, personID, speed): 365 """setSpeed(string, double) -> None 366 367 Sets the maximum speed in m/s for the named person for subsequent step. 368 """ 369 self._setCmd(tc.VAR_SPEED, personID, "d", speed) 370 371 def setType(self, personID, typeID): 372 """setType(string, string) -> None 373 374 Sets the id of the type for the named person. 375 """ 376 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 getWalkingDistance(self, personID, edgeID, pos, laneIndex=0): 165 """getWalkingDistance(string, string, double, integer) -> double 166 167 For a person in walking stage and an edge along the remaining route of 168 personID, return the distance from the current position 169 to the given edge and position along the walk. 170 Otherwise, raise a TraCIException 171 """ 172 return self._getUniversal(tc.DISTANCE_REQUEST, personID, "tru", 2, 173 (edgeID, pos, laneIndex), tc.REQUEST_DRIVINGDIST) 174 175 def getWalkingDistance2D(self, personID, x, y): 176 """getWalkingDistance2D(string, double, double) -> integer 177 178 Return the distance to the given network position along the walk (see getWalkingDistance) 179 """ 180 return self._getUniversal(tc.DISTANCE_REQUEST, personID, "tou", 2, (x, y), tc.REQUEST_DRIVINGDIST) 181 182 def getWaitingTime(self, personID): 183 """getWaitingTime(string) -> double 184 The waiting time of a person is defined as the time (in seconds) spent with a 185 speed below 0.1m/s since the last time it was faster than 0.1m/s. 186 (basically, the waiting time of a person is reset to 0 every time it moves). 187 """ 188 return self._getUniversal(tc.VAR_WAITING_TIME, personID) 189 190 def getNextEdge(self, personID): 191 """getNextEdge(string) -> string 192 If the person is walking, returns the next edge on the persons route 193 (including crossing and walkingareas). If there is no further edge or the 194 person is in another stage, returns the empty string. 195 """ 196 return self._getUniversal(tc.VAR_NEXT_EDGE, personID) 197 198 def getEdges(self, personID, nextStageIndex=0): 199 """getEdges(string, int) -> tuple(string) 200 201 Returns a tuple of all edges in the nth next stage. 202 For waiting stages this is a single edge 203 For walking stages this is the complete route 204 For driving stages this is [origin, destination] 205 206 nextStageIndex 0 retrieves value for the current stage. 207 nextStageIndex must be lower then value of getRemainingStages(personID) 208 """ 209 return self._getUniversal(tc.VAR_EDGES, personID, "i", nextStageIndex) 210 211 def getStage(self, personID, nextStageIndex=0): 212 """getStage(string, int) -> stage 213 Returns the nth stage object (type simulation.Stage) 214 Attribute type of this object has the following meaning: 215 0 for not-yet-departed 216 1 for waiting 217 2 for walking 218 3 for driving 219 4 for access to busStop or trainStop 220 5 for personTrip 221 nextStageIndex 0 retrieves value for the current stage. 222 nextStageIndex must be lower then value of getRemainingStages(personID) 223 """ 224 return self._getUniversal(tc.VAR_STAGE, personID, "i", nextStageIndex) 225 226 def getRemainingStages(self, personID): 227 """getRemainingStages(string) -> int 228 Returns the number of remaining stages (at least 1) 229 """ 230 return self._getUniversal(tc.VAR_STAGES_REMAINING, personID) 231 232 def getVehicle(self, personID): 233 """getVehicle(string) -> string 234 Returns the id of the current vehicle if the person is in stage driving 235 and has entered a vehicle. 236 Return the empty string otherwise 237 """ 238 return self._getUniversal(tc.VAR_VEHICLE, personID) 239 240 def getTaxiReservations(self, onlyNew=0): 241 """getTaxiReservations(int) -> tuple(Reservation) 242 Returns all reservations. If onlyNew is 1, each reservation is returned 243 only once 244 """ 245 return self._getUniversal(tc.VAR_TAXI_RESERVATIONS, "", "i", onlyNew) 246 247 def splitTaxiReservation(self, reservationID, personIDs): 248 """splitTaxiReservation(string, list(string)) -> string 249 Splits given list of person ids from the reservation with the given id 250 and creates a new reservation for these persons. Returns the new 251 reservation id. 252 """ 253 return self._getUniversal(tc.SPLIT_TAXI_RESERVATIONS, reservationID, "l", personIDs) 254 255 def removeStages(self, personID): 256 """removeStages(string) 257 Removes all stages of the person. If no new phases are appended, 258 the person will be removed from the simulation in the next simulationStep(). 259 """ 260 # remove all stages after the current and then abort the current stage 261 while self.getRemainingStages(personID) > 1: 262 self.removeStage(personID, 1) 263 self.removeStage(personID, 0) 264 265 def add(self, personID, edgeID, pos, depart=tc.DEPARTFLAG_NOW, typeID="DEFAULT_PEDTYPE"): 266 """add(string, string, double, double, string) 267 Inserts a new person to the simulation at the given edge, position and 268 time (in s). This function should be followed by appending Stages or the person 269 will immediately vanish on departure. 270 """ 271 format = "tssdd" 272 values = [4, typeID, edgeID, depart, pos] 273 self._setCmd(tc.ADD, personID, format, *values) 274 275 def appendWaitingStage(self, personID, duration, description="waiting", stopID=""): 276 """appendWaitingStage(string, float, string, string) 277 Appends a waiting stage with duration in s to the plan of the given person 278 """ 279 format = "tidss" 280 values = [4, tc.STAGE_WAITING, duration, description, stopID] 281 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 282 283 def appendWalkingStage(self, personID, edges, arrivalPos, duration=-1, speed=-1, stopID=""): 284 """appendWalkingStage(string, stringList, double, double, double, string) 285 Appends a walking stage to the plan of the given person 286 The walking speed can either be specified, computed from the duration parameter (in s) or taken from the 287 type of the person 288 """ 289 if isinstance(edges, str): 290 edges = [edges] 291 format = "tilddds" 292 values = [6, tc.STAGE_WALKING, edges, arrivalPos, duration, speed, stopID] 293 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 294 295 def appendDrivingStage(self, personID, toEdge, lines, stopID=""): 296 """appendDrivingStage(string, string, string, string) 297 Appends a driving stage to the plan of the given person 298 The lines parameter should be a space-separated list of line ids 299 """ 300 format = "tisss" 301 values = [4, tc.STAGE_DRIVING, toEdge, lines, stopID] 302 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 303 304 def appendStage(self, personID, stage): 305 """appendStage(string, stage) 306 Appends a stage object to the plan of the given person 307 Such an object is obtainable using getStage 308 """ 309 format, values = simulation._writeStage(stage) 310 self._setCmd(tc.APPEND_STAGE, personID, format, *values) 311 312 def replaceStage(self, personID, stageIndex, stage): 313 """replaceStage(string, int, stage) 314 Replaces the nth subsequent stage with the given stage object 315 Such an object is obtainable using getStage 316 """ 317 format, values = simulation._writeStage(stage) 318 format = "ti" + format 319 values = [2, stageIndex] + values 320 self._setCmd(tc.REPLACE_STAGE, personID, format, *values) 321 322 def removeStage(self, personID, nextStageIndex): 323 """removeStage(string, int) 324 Removes the nth next stage 325 nextStageIndex must be lower then value of getRemainingStages(personID) 326 nextStageIndex 0 immediately aborts the current stage and proceeds to the next stage 327 """ 328 self._setCmd(tc.REMOVE_STAGE, personID, "i", nextStageIndex) 329 330 def rerouteTraveltime(self, personID): 331 """rerouteTraveltime(string) -> None Reroutes a pedestrian (walking person). 332 """ 333 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, personID, "t", 0) 334 335 def remove(self, personID, reason=tc.REMOVE_VAPORIZED): 336 '''Remove person with the given ID for the give reason. 337 Reasons are defined in module constants and start with REMOVE_''' 338 self._setCmd(tc.REMOVE, personID, "b", reason) 339 340 def moveTo(self, personID, laneID, pos, posLat=tc.INVALID_DOUBLE_VALUE): 341 """moveTo(string, string, double, double) -> None 342 343 Move a person to a new position along its current route. 344 """ 345 self._setCmd(tc.VAR_MOVE_TO, personID, "tsdd", 3, laneID, pos, posLat) 346 347 def moveToXY(self, personID, edgeID, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 348 '''Place person at the given x,y coordinates and force its angle to 349 the given value (for drawing). 350 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 351 natural angle of the edge on which it is driving. 352 If keepRoute is set to 1, the closest position 353 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 354 any edge in the network but its route then only consists of that edge. 355 If keepRoute is set to 2 the person has all the freedom of keepRoute=0 356 but in addition to that may even move outside the road network. 357 edgeID is an optional placement hint to resolve ambiguities. 358 The command fails if no suitable target position is found within the 359 distance given by matchThreshold. 360 ''' 361 format = "tsdddbd" 362 values = [6, edgeID, x, y, angle, keepRoute, matchThreshold] 363 self._setCmd(tc.MOVE_TO_XY, personID, format, *values) 364 365 def setSpeed(self, personID, speed): 366 """setSpeed(string, double) -> None 367 368 Sets the maximum speed in m/s for the named person for subsequent step. 369 """ 370 self._setCmd(tc.VAR_SPEED, personID, "d", speed) 371 372 def setType(self, personID, typeID): 373 """setType(string, string) -> None 374 375 Sets the id of the type for the named person. 376 """ 377 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 getWalkingDistance(self, personID, edgeID, pos, laneIndex=0): 165 """getWalkingDistance(string, string, double, integer) -> double 166 167 For a person in walking stage and an edge along the remaining route of 168 personID, return the distance from the current position 169 to the given edge and position along the walk. 170 Otherwise, raise a TraCIException 171 """ 172 return self._getUniversal(tc.DISTANCE_REQUEST, personID, "tru", 2, 173 (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
175 def getWalkingDistance2D(self, personID, x, y): 176 """getWalkingDistance2D(string, double, double) -> integer 177 178 Return the distance to the given network position along the walk (see getWalkingDistance) 179 """ 180 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)
182 def getWaitingTime(self, personID): 183 """getWaitingTime(string) -> double 184 The waiting time of a person is defined as the time (in seconds) spent with a 185 speed below 0.1m/s since the last time it was faster than 0.1m/s. 186 (basically, the waiting time of a person is reset to 0 every time it moves). 187 """ 188 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).
190 def getNextEdge(self, personID): 191 """getNextEdge(string) -> string 192 If the person is walking, returns the next edge on the persons route 193 (including crossing and walkingareas). If there is no further edge or the 194 person is in another stage, returns the empty string. 195 """ 196 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.
198 def getEdges(self, personID, nextStageIndex=0): 199 """getEdges(string, int) -> tuple(string) 200 201 Returns a tuple of all edges in the nth next stage. 202 For waiting stages this is a single edge 203 For walking stages this is the complete route 204 For driving stages this is [origin, destination] 205 206 nextStageIndex 0 retrieves value for the current stage. 207 nextStageIndex must be lower then value of getRemainingStages(personID) 208 """ 209 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)
211 def getStage(self, personID, nextStageIndex=0): 212 """getStage(string, int) -> stage 213 Returns the nth stage object (type simulation.Stage) 214 Attribute type of this object has the following meaning: 215 0 for not-yet-departed 216 1 for waiting 217 2 for walking 218 3 for driving 219 4 for access to busStop or trainStop 220 5 for personTrip 221 nextStageIndex 0 retrieves value for the current stage. 222 nextStageIndex must be lower then value of getRemainingStages(personID) 223 """ 224 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)
226 def getRemainingStages(self, personID): 227 """getRemainingStages(string) -> int 228 Returns the number of remaining stages (at least 1) 229 """ 230 return self._getUniversal(tc.VAR_STAGES_REMAINING, personID)
getRemainingStages(string) -> int Returns the number of remaining stages (at least 1)
232 def getVehicle(self, personID): 233 """getVehicle(string) -> string 234 Returns the id of the current vehicle if the person is in stage driving 235 and has entered a vehicle. 236 Return the empty string otherwise 237 """ 238 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
240 def getTaxiReservations(self, onlyNew=0): 241 """getTaxiReservations(int) -> tuple(Reservation) 242 Returns all reservations. If onlyNew is 1, each reservation is returned 243 only once 244 """ 245 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
247 def splitTaxiReservation(self, reservationID, personIDs): 248 """splitTaxiReservation(string, list(string)) -> string 249 Splits given list of person ids from the reservation with the given id 250 and creates a new reservation for these persons. Returns the new 251 reservation id. 252 """ 253 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.
255 def removeStages(self, personID): 256 """removeStages(string) 257 Removes all stages of the person. If no new phases are appended, 258 the person will be removed from the simulation in the next simulationStep(). 259 """ 260 # remove all stages after the current and then abort the current stage 261 while self.getRemainingStages(personID) > 1: 262 self.removeStage(personID, 1) 263 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().
265 def add(self, personID, edgeID, pos, depart=tc.DEPARTFLAG_NOW, typeID="DEFAULT_PEDTYPE"): 266 """add(string, string, double, double, string) 267 Inserts a new person to the simulation at the given edge, position and 268 time (in s). This function should be followed by appending Stages or the person 269 will immediately vanish on departure. 270 """ 271 format = "tssdd" 272 values = [4, typeID, edgeID, depart, pos] 273 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.
275 def appendWaitingStage(self, personID, duration, description="waiting", stopID=""): 276 """appendWaitingStage(string, float, string, string) 277 Appends a waiting stage with duration in s to the plan of the given person 278 """ 279 format = "tidss" 280 values = [4, tc.STAGE_WAITING, duration, description, stopID] 281 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
283 def appendWalkingStage(self, personID, edges, arrivalPos, duration=-1, speed=-1, stopID=""): 284 """appendWalkingStage(string, stringList, double, double, double, string) 285 Appends a walking stage to the plan of the given person 286 The walking speed can either be specified, computed from the duration parameter (in s) or taken from the 287 type of the person 288 """ 289 if isinstance(edges, str): 290 edges = [edges] 291 format = "tilddds" 292 values = [6, tc.STAGE_WALKING, edges, arrivalPos, duration, speed, stopID] 293 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
295 def appendDrivingStage(self, personID, toEdge, lines, stopID=""): 296 """appendDrivingStage(string, string, string, string) 297 Appends a driving stage to the plan of the given person 298 The lines parameter should be a space-separated list of line ids 299 """ 300 format = "tisss" 301 values = [4, tc.STAGE_DRIVING, toEdge, lines, stopID] 302 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
304 def appendStage(self, personID, stage): 305 """appendStage(string, stage) 306 Appends a stage object to the plan of the given person 307 Such an object is obtainable using getStage 308 """ 309 format, values = simulation._writeStage(stage) 310 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
312 def replaceStage(self, personID, stageIndex, stage): 313 """replaceStage(string, int, stage) 314 Replaces the nth subsequent stage with the given stage object 315 Such an object is obtainable using getStage 316 """ 317 format, values = simulation._writeStage(stage) 318 format = "ti" + format 319 values = [2, stageIndex] + values 320 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
322 def removeStage(self, personID, nextStageIndex): 323 """removeStage(string, int) 324 Removes the nth next stage 325 nextStageIndex must be lower then value of getRemainingStages(personID) 326 nextStageIndex 0 immediately aborts the current stage and proceeds to the next stage 327 """ 328 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
330 def rerouteTraveltime(self, personID): 331 """rerouteTraveltime(string) -> None Reroutes a pedestrian (walking person). 332 """ 333 self._setCmd(tc.CMD_REROUTE_TRAVELTIME, personID, "t", 0)
rerouteTraveltime(string) -> None Reroutes a pedestrian (walking person).
335 def remove(self, personID, reason=tc.REMOVE_VAPORIZED): 336 '''Remove person with the given ID for the give reason. 337 Reasons are defined in module constants and start with REMOVE_''' 338 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_
340 def moveTo(self, personID, laneID, pos, posLat=tc.INVALID_DOUBLE_VALUE): 341 """moveTo(string, string, double, double) -> None 342 343 Move a person to a new position along its current route. 344 """ 345 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.
347 def moveToXY(self, personID, edgeID, x, y, angle=tc.INVALID_DOUBLE_VALUE, keepRoute=1, matchThreshold=100): 348 '''Place person at the given x,y coordinates and force its angle to 349 the given value (for drawing). 350 If the angle is set to INVALID_DOUBLE_VALUE, the vehicle assumes the 351 natural angle of the edge on which it is driving. 352 If keepRoute is set to 1, the closest position 353 within the existing route is taken. If keepRoute is set to 0, the vehicle may move to 354 any edge in the network but its route then only consists of that edge. 355 If keepRoute is set to 2 the person has all the freedom of keepRoute=0 356 but in addition to that may even move outside the road network. 357 edgeID is an optional placement hint to resolve ambiguities. 358 The command fails if no suitable target position is found within the 359 distance given by matchThreshold. 360 ''' 361 format = "tsdddbd" 362 values = [6, edgeID, x, y, angle, keepRoute, matchThreshold] 363 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.
365 def setSpeed(self, personID, speed): 366 """setSpeed(string, double) -> None 367 368 Sets the maximum speed in m/s for the named person for subsequent step. 369 """ 370 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.
372 def setType(self, personID, typeID): 373 """setType(string, string) -> None 374 375 Sets the id of the type for the named person. 376 """ 377 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
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 != ""])