dist prio
This commit is contained in:
parent
d7dd8e2fa2
commit
ab8049e583
45
Car.py
45
Car.py
@ -11,16 +11,11 @@ class updateSignals(QObject):
|
|||||||
class Car():
|
class Car():
|
||||||
def getShape(self, edgeInd):
|
def getShape(self, edgeInd):
|
||||||
startEdge = self.route[edgeInd]
|
startEdge = self.route[edgeInd]
|
||||||
nextEdge = self.route[edgeInd+1]
|
|
||||||
|
|
||||||
inverted = not (startEdge.getToNode()==nextEdge.getFromNode() or startEdge.getToNode()==nextEdge.getToNode())
|
laneId = 0
|
||||||
laneId = 0 if not inverted else 1
|
|
||||||
lane = startEdge.getLane(laneId)
|
lane = startEdge.getLane(laneId)
|
||||||
vmax = lane.getSpeed()
|
vmax = lane.getSpeed()
|
||||||
laneShape = lane.getShape()
|
laneShape = lane.getShape()
|
||||||
if(inverted):
|
|
||||||
laneShape = laneShape.reverse()
|
|
||||||
|
|
||||||
return (laneShape, vmax, laneId)
|
return (laneShape, vmax, laneId)
|
||||||
|
|
||||||
def initPath(self):
|
def initPath(self):
|
||||||
@ -129,8 +124,8 @@ class Car():
|
|||||||
edgeInd+=1
|
edgeInd+=1
|
||||||
carComing = self.getLeaderAtIntersection(prevInd,edgeInd)
|
carComing = self.getLeaderAtIntersection(prevInd,edgeInd)
|
||||||
if(carComing is not None):
|
if(carComing is not None):
|
||||||
self.leaderDist = l
|
self.leaderDist = l+carComing[0]
|
||||||
return carComing
|
return carComing[1]
|
||||||
if(not self.route[edgeInd].isSpecial()):
|
if(not self.route[edgeInd].isSpecial()):
|
||||||
prevInd = edgeInd
|
prevInd = edgeInd
|
||||||
carsHere = self.controller.getCarsOnLane(self.route[edgeInd].getID(), laneId)
|
carsHere = self.controller.getCarsOnLane(self.route[edgeInd].getID(), laneId)
|
||||||
@ -152,6 +147,22 @@ class Car():
|
|||||||
return
|
return
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def getCurrentEdge(self):
|
||||||
|
return self.route[self.index]
|
||||||
|
|
||||||
|
def getCarDist(self, car, edge, laneInd, startFromEnd = True):
|
||||||
|
lanes = edge.getLane(laneInd).getShape().copy()
|
||||||
|
if startFromEnd:
|
||||||
|
lanes.reverse()
|
||||||
|
cDist = 0
|
||||||
|
for i,l in enumerate(lanes[:-1]):
|
||||||
|
if car.laneInd != (i if not startFromEnd else len(lanes)-i-2):
|
||||||
|
cDist += dist(l, lanes[i+1])
|
||||||
|
else:
|
||||||
|
cDist += dist(l, car.pos)
|
||||||
|
return cDist
|
||||||
|
return cDist
|
||||||
|
|
||||||
def getLeaderAtIntersection(self, prevInd, edgeInd):
|
def getLeaderAtIntersection(self, prevInd, edgeInd):
|
||||||
if(self.route[edgeInd].isSpecial()):
|
if(self.route[edgeInd].isSpecial()):
|
||||||
return None
|
return None
|
||||||
@ -173,13 +184,25 @@ class Car():
|
|||||||
if(f == '0'):
|
if(f == '0'):
|
||||||
continue
|
continue
|
||||||
edge = conn[i].getFrom()
|
edge = conn[i].getFrom()
|
||||||
cars += list(self.controller.getCarsOnLane(edge.getID(), conn[i].getFromLane().getIndex())) # doit y avoir moyen de le faire en gardant les filters, flemme
|
laneInd = conn[i].getFromLane().getIndex()
|
||||||
intLane = self.map.getLane(conn[i].getViaLaneID())
|
intLane = self.map.getLane(conn[i].getViaLaneID())
|
||||||
|
intLaneLgt = intLane.getLength()
|
||||||
|
carsInEdge = list(self.controller.getCarsOnLane(edge.getID(), laneInd)) # doit y avoir moyen de le faire en gardant les filters, flemme
|
||||||
|
if len(carsInEdge) != 0:
|
||||||
|
carsInEdge = zip([self.getCarDist(c, edge, laneInd)+intLaneLgt for c in carsInEdge], carsInEdge)
|
||||||
|
closest = min(carsInEdge, key=lambda c: c[0])
|
||||||
|
cars.append(closest)
|
||||||
intEdge = intLane.getEdge()
|
intEdge = intLane.getEdge()
|
||||||
cars += list(self.controller.getCarsOnLane(intEdge.getID(), intLane.getIndex()))
|
carsInEdge = list(self.controller.getCarsOnLane(intEdge.getID(), intLane.getIndex()))
|
||||||
|
if len(carsInEdge) != 0:
|
||||||
|
carsInEdge = zip([self.getCarDist(c, intEdge, intLane.getIndex()) for c in carsInEdge], carsInEdge)
|
||||||
|
closest = min(carsInEdge, key=lambda c: c[0])
|
||||||
|
cars.append(closest)
|
||||||
|
|
||||||
if(len(cars) == 0):
|
if(len(cars) == 0):
|
||||||
return None
|
return None
|
||||||
return cars[0] # TODO: récuperer la voiture la plus proche au lieu d'un au hasard
|
cDist,closest = min(cars, key=lambda c: c[0])
|
||||||
|
return (cDist,closest)
|
||||||
|
|
||||||
def draw(self,painter):
|
def draw(self,painter):
|
||||||
pt = QPointF(*self.pos)
|
pt = QPointF(*self.pos)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user