traci._inductionloop
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 _inductionloop.py 15# @author Michael Behrisch 16# @author Daniel Krajzewicz 17# @date 2011-03-16 18 19from __future__ import absolute_import 20from .domain import Domain 21from . import constants as tc 22 23 24def readVehicleData(result): 25 result.readLength() 26 nbData = result.readInt() 27 data = [] 28 for _ in range(nbData): 29 vehID = result.readTypedString() 30 length = result.readTypedDouble() 31 entryTime = result.readTypedDouble() 32 leaveTime = result.readTypedDouble() 33 typeID = result.readTypedString() 34 data.append((vehID, length, entryTime, leaveTime, typeID)) 35 return tuple(data) 36 37 38_RETURN_VALUE_FUNC = {tc.LAST_STEP_VEHICLE_DATA: readVehicleData} 39 40 41class InductionLoopDomain(Domain): 42 43 def __init__(self): 44 Domain.__init__(self, "inductionloop", tc.CMD_GET_INDUCTIONLOOP_VARIABLE, tc.CMD_SET_INDUCTIONLOOP_VARIABLE, 45 tc.CMD_SUBSCRIBE_INDUCTIONLOOP_VARIABLE, tc.RESPONSE_SUBSCRIBE_INDUCTIONLOOP_VARIABLE, 46 tc.CMD_SUBSCRIBE_INDUCTIONLOOP_CONTEXT, tc.RESPONSE_SUBSCRIBE_INDUCTIONLOOP_CONTEXT, 47 _RETURN_VALUE_FUNC, 48 subscriptionDefault=(tc.LAST_STEP_VEHICLE_NUMBER,)) 49 50 def getPosition(self, loopID): 51 """getPosition(string) -> double 52 53 Returns the position measured from the beginning of the lane in meters. 54 """ 55 return self._getUniversal(tc.VAR_POSITION, loopID) 56 57 def getLaneID(self, loopID): 58 """getLaneID(string) -> string 59 60 Returns the id of the lane the loop is on. 61 """ 62 return self._getUniversal(tc.VAR_LANE_ID, loopID) 63 64 def getLastStepVehicleNumber(self, loopID): 65 """getLastStepVehicleNumber(string) -> integer 66 67 Returns the number of vehicles that were on the named induction loop within the last simulation step. 68 """ 69 return self._getUniversal(tc.LAST_STEP_VEHICLE_NUMBER, loopID) 70 71 def getLastStepMeanSpeed(self, loopID): 72 """getLastStepMeanSpeed(string) -> double 73 74 Returns the mean speed in m/s of vehicles that were on the named induction loop within the last simulation step. 75 """ 76 return self._getUniversal(tc.LAST_STEP_MEAN_SPEED, loopID) 77 78 def getLastStepVehicleIDs(self, loopID): 79 """getLastStepVehicleIDs(string) -> tuple(string) 80 81 Returns the tuple of ids of vehicles that were on the named induction loop in the last simulation step. 82 """ 83 return self._getUniversal(tc.LAST_STEP_VEHICLE_ID_LIST, loopID) 84 85 def getLastStepOccupancy(self, loopID): 86 """getLastStepOccupancy(string) -> double 87 88 Returns the percentage of time the detector was occupied by a vehicle. 89 """ 90 return self._getUniversal(tc.LAST_STEP_OCCUPANCY, loopID) 91 92 def getLastStepMeanLength(self, loopID): 93 """getLastStepMeanLength(string) -> double 94 95 Returns the mean length in m of vehicles which were on the detector in the last step. 96 """ 97 return self._getUniversal(tc.LAST_STEP_LENGTH, loopID) 98 99 def getTimeSinceDetection(self, loopID): 100 """getTimeSinceDetection(string) -> double 101 102 Returns the time in s since last detection. 103 """ 104 return self._getUniversal(tc.LAST_STEP_TIME_SINCE_DETECTION, loopID) 105 106 def getVehicleData(self, loopID): 107 """getVehicleData(string) -> tuple((veh_id, veh_length, entry_time, exit_time, vType), ...) 108 109 Returns a complex structure containing several information about vehicles which passed the detector. 110 """ 111 return self._getUniversal(tc.LAST_STEP_VEHICLE_DATA, loopID) 112 113 def getIntervalOccupancy(self, loopID): 114 """getIntervalOccupancy(string) -> double 115 116 Returns the percentage of time the detector was occupied by a vehicle 117 during the current interval. 118 """ 119 return self._getUniversal(tc.VAR_INTERVAL_OCCUPANCY, loopID) 120 121 def getIntervalMeanSpeed(self, loopID): 122 """getIntervalMeanSpeed(string) -> double 123 124 Returns the average speed of vehicles during the current interval. 125 """ 126 return self._getUniversal(tc.VAR_INTERVAL_SPEED, loopID) 127 128 def getIntervalVehicleNumber(self, loopID): 129 """getIntervalVehicleNumber(string) -> integer 130 131 Returns the number of vehicles that passed the detector during the current interval 132 """ 133 return self._getUniversal(tc.VAR_INTERVAL_NUMBER, loopID) 134 135 def getIntervalVehicleIDs(self, loopID): 136 """getIntervalVehicleIDs(string) -> tuple(string) 137 138 Returns the ids of vehicles that passed the detector during the current interval 139 """ 140 return self._getUniversal(tc.VAR_INTERVAL_IDS, loopID) 141 142 def getLastIntervalOccupancy(self, loopID): 143 """getLastIntervalOccupancy(string) -> double 144 145 Returns the percentage of time the detector was occupied by a vehicle 146 during the previous interval. 147 """ 148 return self._getUniversal(tc.VAR_LAST_INTERVAL_OCCUPANCY, loopID) 149 150 def getLastIntervalMeanSpeed(self, loopID): 151 """getLastIntervalMeanSpeed(string) -> double 152 153 Returns the average speed of vehicles during the previous interval. 154 """ 155 return self._getUniversal(tc.VAR_LAST_INTERVAL_SPEED, loopID) 156 157 def getLastIntervalVehicleNumber(self, loopID): 158 """getLastIntervalVehicleNumber(string) -> integer 159 160 Returns the number of vehicles that passed the detector during the previous interval 161 """ 162 return self._getUniversal(tc.VAR_LAST_INTERVAL_NUMBER, loopID) 163 164 def getLastIntervalVehicleIDs(self, loopID): 165 """getLastIntervalVehicleIDs(string) -> tuple(string) 166 167 Returns the ids of vehicles that passed the detector during the previous interval 168 """ 169 return self._getUniversal(tc.VAR_LAST_INTERVAL_IDS, loopID) 170 171 def overrideTimeSinceDetection(self, loopID, time): 172 """overrideTimeSinceDetection(string, double) -> None 173 Persistently overrides the measured time since detection with the given value. 174 Setting a negative value resets the override 175 """ 176 self._setCmd(tc.VAR_VIRTUAL_DETECTION, loopID, "d", time)
25def readVehicleData(result): 26 result.readLength() 27 nbData = result.readInt() 28 data = [] 29 for _ in range(nbData): 30 vehID = result.readTypedString() 31 length = result.readTypedDouble() 32 entryTime = result.readTypedDouble() 33 leaveTime = result.readTypedDouble() 34 typeID = result.readTypedString() 35 data.append((vehID, length, entryTime, leaveTime, typeID)) 36 return tuple(data)
42class InductionLoopDomain(Domain): 43 44 def __init__(self): 45 Domain.__init__(self, "inductionloop", tc.CMD_GET_INDUCTIONLOOP_VARIABLE, tc.CMD_SET_INDUCTIONLOOP_VARIABLE, 46 tc.CMD_SUBSCRIBE_INDUCTIONLOOP_VARIABLE, tc.RESPONSE_SUBSCRIBE_INDUCTIONLOOP_VARIABLE, 47 tc.CMD_SUBSCRIBE_INDUCTIONLOOP_CONTEXT, tc.RESPONSE_SUBSCRIBE_INDUCTIONLOOP_CONTEXT, 48 _RETURN_VALUE_FUNC, 49 subscriptionDefault=(tc.LAST_STEP_VEHICLE_NUMBER,)) 50 51 def getPosition(self, loopID): 52 """getPosition(string) -> double 53 54 Returns the position measured from the beginning of the lane in meters. 55 """ 56 return self._getUniversal(tc.VAR_POSITION, loopID) 57 58 def getLaneID(self, loopID): 59 """getLaneID(string) -> string 60 61 Returns the id of the lane the loop is on. 62 """ 63 return self._getUniversal(tc.VAR_LANE_ID, loopID) 64 65 def getLastStepVehicleNumber(self, loopID): 66 """getLastStepVehicleNumber(string) -> integer 67 68 Returns the number of vehicles that were on the named induction loop within the last simulation step. 69 """ 70 return self._getUniversal(tc.LAST_STEP_VEHICLE_NUMBER, loopID) 71 72 def getLastStepMeanSpeed(self, loopID): 73 """getLastStepMeanSpeed(string) -> double 74 75 Returns the mean speed in m/s of vehicles that were on the named induction loop within the last simulation step. 76 """ 77 return self._getUniversal(tc.LAST_STEP_MEAN_SPEED, loopID) 78 79 def getLastStepVehicleIDs(self, loopID): 80 """getLastStepVehicleIDs(string) -> tuple(string) 81 82 Returns the tuple of ids of vehicles that were on the named induction loop in the last simulation step. 83 """ 84 return self._getUniversal(tc.LAST_STEP_VEHICLE_ID_LIST, loopID) 85 86 def getLastStepOccupancy(self, loopID): 87 """getLastStepOccupancy(string) -> double 88 89 Returns the percentage of time the detector was occupied by a vehicle. 90 """ 91 return self._getUniversal(tc.LAST_STEP_OCCUPANCY, loopID) 92 93 def getLastStepMeanLength(self, loopID): 94 """getLastStepMeanLength(string) -> double 95 96 Returns the mean length in m of vehicles which were on the detector in the last step. 97 """ 98 return self._getUniversal(tc.LAST_STEP_LENGTH, loopID) 99 100 def getTimeSinceDetection(self, loopID): 101 """getTimeSinceDetection(string) -> double 102 103 Returns the time in s since last detection. 104 """ 105 return self._getUniversal(tc.LAST_STEP_TIME_SINCE_DETECTION, loopID) 106 107 def getVehicleData(self, loopID): 108 """getVehicleData(string) -> tuple((veh_id, veh_length, entry_time, exit_time, vType), ...) 109 110 Returns a complex structure containing several information about vehicles which passed the detector. 111 """ 112 return self._getUniversal(tc.LAST_STEP_VEHICLE_DATA, loopID) 113 114 def getIntervalOccupancy(self, loopID): 115 """getIntervalOccupancy(string) -> double 116 117 Returns the percentage of time the detector was occupied by a vehicle 118 during the current interval. 119 """ 120 return self._getUniversal(tc.VAR_INTERVAL_OCCUPANCY, loopID) 121 122 def getIntervalMeanSpeed(self, loopID): 123 """getIntervalMeanSpeed(string) -> double 124 125 Returns the average speed of vehicles during the current interval. 126 """ 127 return self._getUniversal(tc.VAR_INTERVAL_SPEED, loopID) 128 129 def getIntervalVehicleNumber(self, loopID): 130 """getIntervalVehicleNumber(string) -> integer 131 132 Returns the number of vehicles that passed the detector during the current interval 133 """ 134 return self._getUniversal(tc.VAR_INTERVAL_NUMBER, loopID) 135 136 def getIntervalVehicleIDs(self, loopID): 137 """getIntervalVehicleIDs(string) -> tuple(string) 138 139 Returns the ids of vehicles that passed the detector during the current interval 140 """ 141 return self._getUniversal(tc.VAR_INTERVAL_IDS, loopID) 142 143 def getLastIntervalOccupancy(self, loopID): 144 """getLastIntervalOccupancy(string) -> double 145 146 Returns the percentage of time the detector was occupied by a vehicle 147 during the previous interval. 148 """ 149 return self._getUniversal(tc.VAR_LAST_INTERVAL_OCCUPANCY, loopID) 150 151 def getLastIntervalMeanSpeed(self, loopID): 152 """getLastIntervalMeanSpeed(string) -> double 153 154 Returns the average speed of vehicles during the previous interval. 155 """ 156 return self._getUniversal(tc.VAR_LAST_INTERVAL_SPEED, loopID) 157 158 def getLastIntervalVehicleNumber(self, loopID): 159 """getLastIntervalVehicleNumber(string) -> integer 160 161 Returns the number of vehicles that passed the detector during the previous interval 162 """ 163 return self._getUniversal(tc.VAR_LAST_INTERVAL_NUMBER, loopID) 164 165 def getLastIntervalVehicleIDs(self, loopID): 166 """getLastIntervalVehicleIDs(string) -> tuple(string) 167 168 Returns the ids of vehicles that passed the detector during the previous interval 169 """ 170 return self._getUniversal(tc.VAR_LAST_INTERVAL_IDS, loopID) 171 172 def overrideTimeSinceDetection(self, loopID, time): 173 """overrideTimeSinceDetection(string, double) -> None 174 Persistently overrides the measured time since detection with the given value. 175 Setting a negative value resets the override 176 """ 177 self._setCmd(tc.VAR_VIRTUAL_DETECTION, loopID, "d", time)
51 def getPosition(self, loopID): 52 """getPosition(string) -> double 53 54 Returns the position measured from the beginning of the lane in meters. 55 """ 56 return self._getUniversal(tc.VAR_POSITION, loopID)
getPosition(string) -> double
Returns the position measured from the beginning of the lane in meters.
58 def getLaneID(self, loopID): 59 """getLaneID(string) -> string 60 61 Returns the id of the lane the loop is on. 62 """ 63 return self._getUniversal(tc.VAR_LANE_ID, loopID)
getLaneID(string) -> string
Returns the id of the lane the loop is on.
65 def getLastStepVehicleNumber(self, loopID): 66 """getLastStepVehicleNumber(string) -> integer 67 68 Returns the number of vehicles that were on the named induction loop within the last simulation step. 69 """ 70 return self._getUniversal(tc.LAST_STEP_VEHICLE_NUMBER, loopID)
getLastStepVehicleNumber(string) -> integer
Returns the number of vehicles that were on the named induction loop within the last simulation step.
72 def getLastStepMeanSpeed(self, loopID): 73 """getLastStepMeanSpeed(string) -> double 74 75 Returns the mean speed in m/s of vehicles that were on the named induction loop within the last simulation step. 76 """ 77 return self._getUniversal(tc.LAST_STEP_MEAN_SPEED, loopID)
getLastStepMeanSpeed(string) -> double
Returns the mean speed in m/s of vehicles that were on the named induction loop within the last simulation step.
79 def getLastStepVehicleIDs(self, loopID): 80 """getLastStepVehicleIDs(string) -> tuple(string) 81 82 Returns the tuple of ids of vehicles that were on the named induction loop in the last simulation step. 83 """ 84 return self._getUniversal(tc.LAST_STEP_VEHICLE_ID_LIST, loopID)
getLastStepVehicleIDs(string) -> tuple(string)
Returns the tuple of ids of vehicles that were on the named induction loop in the last simulation step.
86 def getLastStepOccupancy(self, loopID): 87 """getLastStepOccupancy(string) -> double 88 89 Returns the percentage of time the detector was occupied by a vehicle. 90 """ 91 return self._getUniversal(tc.LAST_STEP_OCCUPANCY, loopID)
getLastStepOccupancy(string) -> double
Returns the percentage of time the detector was occupied by a vehicle.
93 def getLastStepMeanLength(self, loopID): 94 """getLastStepMeanLength(string) -> double 95 96 Returns the mean length in m of vehicles which were on the detector in the last step. 97 """ 98 return self._getUniversal(tc.LAST_STEP_LENGTH, loopID)
getLastStepMeanLength(string) -> double
Returns the mean length in m of vehicles which were on the detector in the last step.
100 def getTimeSinceDetection(self, loopID): 101 """getTimeSinceDetection(string) -> double 102 103 Returns the time in s since last detection. 104 """ 105 return self._getUniversal(tc.LAST_STEP_TIME_SINCE_DETECTION, loopID)
getTimeSinceDetection(string) -> double
Returns the time in s since last detection.
107 def getVehicleData(self, loopID): 108 """getVehicleData(string) -> tuple((veh_id, veh_length, entry_time, exit_time, vType), ...) 109 110 Returns a complex structure containing several information about vehicles which passed the detector. 111 """ 112 return self._getUniversal(tc.LAST_STEP_VEHICLE_DATA, loopID)
getVehicleData(string) -> tuple((veh_id, veh_length, entry_time, exit_time, vType), ...)
Returns a complex structure containing several information about vehicles which passed the detector.
114 def getIntervalOccupancy(self, loopID): 115 """getIntervalOccupancy(string) -> double 116 117 Returns the percentage of time the detector was occupied by a vehicle 118 during the current interval. 119 """ 120 return self._getUniversal(tc.VAR_INTERVAL_OCCUPANCY, loopID)
getIntervalOccupancy(string) -> double
Returns the percentage of time the detector was occupied by a vehicle during the current interval.
122 def getIntervalMeanSpeed(self, loopID): 123 """getIntervalMeanSpeed(string) -> double 124 125 Returns the average speed of vehicles during the current interval. 126 """ 127 return self._getUniversal(tc.VAR_INTERVAL_SPEED, loopID)
getIntervalMeanSpeed(string) -> double
Returns the average speed of vehicles during the current interval.
129 def getIntervalVehicleNumber(self, loopID): 130 """getIntervalVehicleNumber(string) -> integer 131 132 Returns the number of vehicles that passed the detector during the current interval 133 """ 134 return self._getUniversal(tc.VAR_INTERVAL_NUMBER, loopID)
getIntervalVehicleNumber(string) -> integer
Returns the number of vehicles that passed the detector during the current interval
136 def getIntervalVehicleIDs(self, loopID): 137 """getIntervalVehicleIDs(string) -> tuple(string) 138 139 Returns the ids of vehicles that passed the detector during the current interval 140 """ 141 return self._getUniversal(tc.VAR_INTERVAL_IDS, loopID)
getIntervalVehicleIDs(string) -> tuple(string)
Returns the ids of vehicles that passed the detector during the current interval
143 def getLastIntervalOccupancy(self, loopID): 144 """getLastIntervalOccupancy(string) -> double 145 146 Returns the percentage of time the detector was occupied by a vehicle 147 during the previous interval. 148 """ 149 return self._getUniversal(tc.VAR_LAST_INTERVAL_OCCUPANCY, loopID)
getLastIntervalOccupancy(string) -> double
Returns the percentage of time the detector was occupied by a vehicle during the previous interval.
151 def getLastIntervalMeanSpeed(self, loopID): 152 """getLastIntervalMeanSpeed(string) -> double 153 154 Returns the average speed of vehicles during the previous interval. 155 """ 156 return self._getUniversal(tc.VAR_LAST_INTERVAL_SPEED, loopID)
getLastIntervalMeanSpeed(string) -> double
Returns the average speed of vehicles during the previous interval.
158 def getLastIntervalVehicleNumber(self, loopID): 159 """getLastIntervalVehicleNumber(string) -> integer 160 161 Returns the number of vehicles that passed the detector during the previous interval 162 """ 163 return self._getUniversal(tc.VAR_LAST_INTERVAL_NUMBER, loopID)
getLastIntervalVehicleNumber(string) -> integer
Returns the number of vehicles that passed the detector during the previous interval
165 def getLastIntervalVehicleIDs(self, loopID): 166 """getLastIntervalVehicleIDs(string) -> tuple(string) 167 168 Returns the ids of vehicles that passed the detector during the previous interval 169 """ 170 return self._getUniversal(tc.VAR_LAST_INTERVAL_IDS, loopID)
getLastIntervalVehicleIDs(string) -> tuple(string)
Returns the ids of vehicles that passed the detector during the previous interval
172 def overrideTimeSinceDetection(self, loopID, time): 173 """overrideTimeSinceDetection(string, double) -> None 174 Persistently overrides the measured time since detection with the given value. 175 Setting a negative value resets the override 176 """ 177 self._setCmd(tc.VAR_VIRTUAL_DETECTION, loopID, "d", time)
overrideTimeSinceDetection(string, double) -> None Persistently overrides the measured time since detection with the given value. Setting a negative value resets the override