2018-11-15 21:15:43 +00:00
|
|
|
"""
|
2018-11-15 12:51:46 +00:00
|
|
|
Created on 17 oct. 2018
|
|
|
|
|
|
|
|
@author: Axel Huynh-Phuc, Thibaud Gasser
|
2018-11-15 21:15:43 +00:00
|
|
|
"""
|
|
|
|
from typing import Iterable
|
2018-11-15 12:51:46 +00:00
|
|
|
|
|
|
|
import traci
|
|
|
|
from shapely.geometry.linestring import LineString
|
|
|
|
|
2018-11-15 21:15:43 +00:00
|
|
|
from model import Area, Vehicle
|
|
|
|
|
2018-11-15 12:51:46 +00:00
|
|
|
|
|
|
|
def stop_vehicle(veh_id):
|
|
|
|
traci.vehicle.remove(veh_id, traci.constants.REMOVE_PARKING)
|
|
|
|
|
|
|
|
|
|
|
|
def lanes_in_area(area):
|
|
|
|
for lane_id in traci.lane.getIDList():
|
|
|
|
polygon_lane = LineString(traci.lane.getShape(lane_id))
|
|
|
|
if area.rectangle.intersects(polygon_lane):
|
|
|
|
yield lane_id
|
|
|
|
|
|
|
|
|
2018-11-15 21:15:43 +00:00
|
|
|
def lock_area(area: Area, vehicles: Iterable[Vehicle]):
|
|
|
|
for lane in area._lanes:
|
|
|
|
print(f'Setting max speed of {lane.lane_id} to 30.')
|
|
|
|
traci.lane.setMaxSpeed(lane.lane_id, 30)
|
|
|
|
area.locked = True
|
|
|
|
for vehicle in vehicles:
|
|
|
|
traci.vehicle.rerouteTraveltime(vehicle.veh_id, True)
|