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
|
|
|
|
2018-11-19 15:28:29 +00:00
|
|
|
def remove_vehicle(veh_id):
|
2018-11-15 12:51:46 +00:00
|
|
|
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-19 15:28:29 +00:00
|
|
|
def computeEdgeWeight(edge_id):
|
|
|
|
return traci.edge.getCO2Emission(edge_id)
|
|
|
|
|
2018-11-20 12:52:23 +00:00
|
|
|
def rerouteEffortVehicles():
|
2018-11-19 15:28:29 +00:00
|
|
|
for veh_id in traci.vehicle.getIDList():
|
2018-11-20 12:52:23 +00:00
|
|
|
traci.vehicle.rerouteEffort(veh_id)
|
2018-11-19 15:28:29 +00:00
|
|
|
|
|
|
|
def adjustEdgesWeight():
|
|
|
|
for edge_id in traci.edge.getIDList():
|
|
|
|
weight = computeEdgeWeight(edge_id) #by default edges weight = length/mean speed
|
2018-11-20 12:52:23 +00:00
|
|
|
traci.edge.setEffort(edge_id, weight)
|
2018-11-15 12:51:46 +00:00
|
|
|
|
2018-11-15 21:15:43 +00:00
|
|
|
def lock_area(area: Area, vehicles: Iterable[Vehicle]):
|
2018-11-19 15:28:29 +00:00
|
|
|
max_speed = 30
|
|
|
|
print(f' Setting max speed into {area.name} to {max_speed} km/h')
|
2018-11-15 21:15:43 +00:00
|
|
|
area.locked = True
|
2018-11-19 15:28:29 +00:00
|
|
|
for lane in area._lanes:
|
|
|
|
traci.lane.setMaxSpeed(lane.lane_id, max_speed/3.6)
|
|
|
|
|