From 48bb475e0bf880561a087809deacb3915e6b74c0 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 3 May 2022 13:46:59 +0200 Subject: [PATCH] prio flow --- Car.py | 10 +++++++--- CarController.py | 7 ++++--- Flow.py | 2 ++ mainLoop.py | 4 ++-- rdpt_polytech.net.xml | 27 +++++++++++++++++++-------- rdpt_polytech.rou.xml | 3 --- 6 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Car.py b/Car.py index a171a1b..83ff5c2 100644 --- a/Car.py +++ b/Car.py @@ -54,7 +54,7 @@ class Car(): self.v=0 self.a=10 self.b=20 - self.minSpace=10 + self.minSpace=1 self.leaderBefore=False self.distToInter=0 @@ -350,6 +350,10 @@ class Car(): self.updateGraph(self.leaderDist, self.distToInter, 0) return """ + if False and ("f_0" in self.id or "f_1" in self.id or "f_2" in self.id): + self.v = 0 + return + if leader is None: vd = min(self.v + self.a * dt, vmax) self.v = max(0, vd-self.nu) @@ -406,10 +410,10 @@ class Car(): def update(self,dt): if self.controller.t < self.startTime: return - + """ if self.v < 1 and self.getCurrentEdge().isSpecial(): print(f"{self.id} stalled where he souldn't have") - + """ self.leader=self.getLeader(100) self.conduiteKrauss(self.vmax,self.leader,dt) diff --git a/CarController.py b/CarController.py index 05b61c6..a3193fc 100644 --- a/CarController.py +++ b/CarController.py @@ -164,8 +164,8 @@ class CarController: self.t+=self.dt for car in self.cars: car.update(self.dt) - - for flow in self.flows: + + for flow in sorted(self.flows, key=lambda f: f.priority, reverse = True): if flow.shouldSpawn(self.t): carsClose = self.getCarsClose(flow.carModel) try: @@ -175,7 +175,8 @@ class CarController: else: self.spawnFailed += 1 flow.addCar2Counter() - #print(f"nope, y as déjà une voiture ici : n°{self.spawnFailed}") + flow.priority += 1 + print(f"nope, y as déjà une voiture ici : n°{self.spawnFailed}") def draw(self,painter): for ind,car in enumerate(self.cars): diff --git a/Flow.py b/Flow.py index ae0d683..55ce6fb 100644 --- a/Flow.py +++ b/Flow.py @@ -13,6 +13,7 @@ class Flow: self.adjVPH = self.vph + randint(0,self.randomVal) self.carModel = Car("model",self.route,start,parentMap,parentController,None) self.carsSpawned = 0 + self.priority = 0 self.cc = parentController def prepareRoute(self): @@ -27,6 +28,7 @@ class Flow: newCar.id = self.id + str(self.carsSpawned) self.carsSpawned += 1 self.adjVPH = self.vph + randint(0,self.randomVal) + self.priority = 0 return newCar def addCar2Counter(self): diff --git a/mainLoop.py b/mainLoop.py index 07bd33f..c8b41bd 100644 --- a/mainLoop.py +++ b/mainLoop.py @@ -86,9 +86,9 @@ class mainLoop(QObject): @threadSafe def quickLoad(self): - self.map.fromPath("test12.net.xml") + self.map.fromPath("rdpt_polytech.net.xml") self.painter.generateTransform() - self.controller.fromPath("test21.rou.xml") + self.controller.fromPath("rdpt_polytech.rou.xml") self.controller.prepareRoute() def updateFps(self): diff --git a/rdpt_polytech.net.xml b/rdpt_polytech.net.xml index f8b52f0..892d6d1 100644 --- a/rdpt_polytech.net.xml +++ b/rdpt_polytech.net.xml @@ -1,6 +1,6 @@ -