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

Class LocalScene

limsim/simModel/fixedScene/localScene.py:15–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14
15class LocalScene:
16 def __init__(self, netInfo: NetworkBuild, localPos: DummyVehicle) -> None:
17 self.netInfo = netInfo
18 self.localPos = localPos
19 self.edges, self.junctions = self.getRoadGraph()
20 self.currVehicles: dict[str, Vehicle] = {}
21 self.vehINAoI: dict[str, Vehicle] = {}
22 self.outOfAoI: dict[str, Vehicle] = {}
23
24 def getRoadGraph(self) -> tuple[set[str]]:
25 ex, ey = self.localPos.x, self.localPos.y
26 currGeox = int(ex // 100)
27 currGeoy = int(ey // 100)
28
29 sceGeohashIDs = (
30 (currGeox-1, currGeoy-1),
31 (currGeox, currGeoy-1),
32 (currGeox+1, currGeoy-1),
33 (currGeox-1, currGeoy),
34 (currGeox, currGeoy),
35 (currGeox+1, currGeoy),
36 (currGeox-1, currGeoy+1),
37 (currGeox, currGeoy+1),
38 (currGeox+1, currGeoy+1),
39 )
40
41 edges: set = set()
42 juncs: set = set()
43
44 for sgh in sceGeohashIDs:
45 try:
46 geohash = self.netInfo.geoHashes[sgh]
47 except KeyError:
48 continue
49 edges = edges | geohash.edges
50 juncs = juncs | geohash.junctions
51
52 return edges, juncs
53
54 def updateScene(self, dataQue: Queue, timeStep: int):
55 NowTLs = {}
56 for jid in self.junctions:
57 junc = self.netInfo.getJunction(jid)
58 for jlid in junc.JunctionLanes:
59 jl = self.netInfo.getJunctionLane(jlid)
60 tlid = jl.tlLogic
61 if tlid:
62 if tlid not in NowTLs.keys():
63 currPhaseIndex = traci.trafficlight.getPhase(tlid)
64 tlLogic = self.netInfo.getTlLogic(tlid)
65 currPhase = tlLogic.currPhase(currPhaseIndex)
66 nextPhase = tlLogic.nextPhase(currPhaseIndex)
67 switchTime = round(traci.trafficlight.getNextSwitch(
68 tlid) - traci.simulation.getTime(), 1)
69 NowTLs[tlid] = (currPhase, nextPhase, switchTime)
70 dataQue.put((
71 'trafficLightStates',
72 (timeStep, tlid, currPhase, nextPhase, switchTime)

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected