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

Method updateSurroundVeh

limsim/simModel/fixedScene/localScene.py:87–138  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

85 vdict[vid] = vehIns
86
87 def updateSurroundVeh(self):
88 nextStepVehicles = set()
89 for ed in self.edges:
90 nextStepVehicles = nextStepVehicles | set(
91 traci.edge.getLastStepVehicleIDs(ed)
92 )
93
94 for jc in self.junctions:
95 jinfo = self.netInfo.getJunction(jc)
96 if jinfo.JunctionLanes:
97 for il in jinfo.JunctionLanes:
98 nextStepVehicles = nextStepVehicles | set(
99 traci.lane.getLastStepVehicleIDs(il)
100 )
101
102 newVehicles = nextStepVehicles - self.currVehicles.keys()
103 for nv in newVehicles:
104 self.addVeh(self.currVehicles, nv)
105
106 cx, cy = self.localPos.x, self.localPos.y
107 vehInAoI = {}
108 outOfAoI = {}
109 outOfRange = set()
110 for vk, vv in self.currVehicles.items():
111 try:
112 x, y = traci.vehicle.getPosition(vk)
113 except TraCIException:
114 outOfRange.add(vk)
115 continue
116 if sqrt(pow((cx - x), 2) + pow((cy - y), 2)) <= self.localPos.radius:
117 try:
118 vehArrive = vv.arriveDestination(self.netInfo)
119 except:
120 vehArrive = False
121 if not vehArrive:
122 vehInAoI[vk] = vv
123 elif sqrt(pow((cx - x), 2) + pow((cy - y), 2)) <= 2 * self.localPos.radius:
124 try:
125 vehArrive = vv.arriveDestination(self.netInfo)
126 except:
127 vehArrive = False
128 if not vehArrive:
129 outOfAoI[vk] = vv
130 else:
131 vv.exitControlMode()
132 outOfRange.add(vk)
133
134 for vid in outOfRange:
135 del (self.currVehicles[vid])
136
137 self.vehINAoI = vehInAoI
138 self.outOfAoI = outOfAoI
139
140 def plotScene(self, node: dpg.node, ex: float, ey: float, ctf: CoordTF):
141 if self.edges:

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