MCPcopy Create free account
hub / github.com/PJLab-ADG/OASim / updateSurroudVeh

Method updateSurroudVeh

limsim/simModel/egoTracking/movingScene.py:96–162  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

94 # getSurroundVeh will update all vehicle's attributes
95 # so don't update again in other steps
96 def updateSurroudVeh(self):
97 nextStepVehicles = set()
98 for ed in self.edges:
99 nextStepVehicles = nextStepVehicles | set(
100 traci.edge.getLastStepVehicleIDs(ed)
101 )
102
103 for jc in self.junctions:
104 jinfo = self.netInfo.getJunction(jc)
105 if jinfo.JunctionLanes:
106 for il in jinfo.JunctionLanes:
107 nextStepVehicles = nextStepVehicles | set(
108 traci.lane.getLastStepVehicleIDs(il)
109 )
110
111 newVehicles = nextStepVehicles - self.currVehicles.keys()
112 for nv in newVehicles:
113 self.addVeh(self.currVehicles, nv)
114
115 ex, ey = traci.vehicle.getPosition(self.ego.id)
116 vehInAoI = {}
117 outOfAoI = {}
118 outOfRange = set()
119 for vk, vv in self.currVehicles.items():
120 if vk == self.ego.id:
121 continue
122 try:
123 x, y = traci.vehicle.getPosition(vk)
124 except TraCIException:
125 # vehicle is leaving the network.
126 outOfRange.add((vk, 0))
127 continue
128 if sqrt(pow((ex - x), 2) + pow((ey - y), 2)) <= self.ego.deArea:
129 try:
130 vehArrive = vv.arriveDestination(self.netInfo)
131 except:
132 vehArrive = False
133
134 if vehArrive:
135 outOfRange.add((vk, 1))
136 else:
137 vehInAoI[vk] = vv
138 elif sqrt(pow((ex - x), 2) + pow((ey - y), 2)) <= 2 * self.ego.deArea:
139 try:
140 vehArrive = vv.arriveDestination(self.netInfo)
141 except:
142 vehArrive = False
143
144 if vehArrive:
145 outOfRange.add((vk, 1))
146 else:
147 outOfAoI[vk] = vv
148 else:
149 vv.exitControlMode()
150 outOfRange.add((vk, 0))
151
152 for vid, atag in outOfRange:
153 del(self.currVehicles[vid])

Callers 3

getSceMethod · 0.45
getSceMethod · 0.45
getSceMethod · 0.45

Calls 4

addVehMethod · 0.95
getJunctionMethod · 0.80
arriveDestinationMethod · 0.80
exitControlModeMethod · 0.80

Tested by

no test coverage detected