2018-11-07 10:23:32 +00:00
|
|
|
'''
|
|
|
|
Created on 17 oct. 2018
|
|
|
|
|
2018-11-14 13:40:55 +00:00
|
|
|
@author: Axel Huynh-Phuc, Thibaud Gasser
|
2018-11-07 10:23:32 +00:00
|
|
|
'''
|
2018-11-14 13:40:55 +00:00
|
|
|
|
|
|
|
import traci
|
2018-11-07 10:23:32 +00:00
|
|
|
from shapely.geometry.linestring import LineString
|
|
|
|
|
|
|
|
|
|
|
|
class SUMOFactory(object):
|
|
|
|
|
2018-11-14 13:40:55 +00:00
|
|
|
def stop_vehicle(self, veh_id):
|
2018-11-07 10:23:32 +00:00
|
|
|
traci.vehicle.remove(veh_id, traci.constants.REMOVE_PARKING)
|
2018-11-14 13:40:55 +00:00
|
|
|
|
|
|
|
def lanes_in_area(self, area):
|
2018-11-07 10:23:32 +00:00
|
|
|
for lane_id in traci.lane.getIDList():
|
|
|
|
polygon_lane = LineString(traci.lane.getShape(lane_id))
|
2018-11-15 11:20:19 +00:00
|
|
|
if area.rectangle.intersects(polygon_lane):
|
2018-11-14 13:40:55 +00:00
|
|
|
yield lane_id
|
2018-11-07 10:23:32 +00:00
|
|
|
|
|
|
|
def lock_area(self, area):
|
2018-11-14 13:40:55 +00:00
|
|
|
for lane_id in self.lanes_in_area(area):
|
2018-11-16 15:39:01 +00:00
|
|
|
print(f'Setting max speed of {lane_id} to 9.')
|
|
|
|
traci.lane.setMaxSpeed(lane_id, 9)
|
2018-11-14 13:40:55 +00:00
|
|
|
|
|
|
|
for veh_id in traci.vehicle.getIDList():
|
|
|
|
traci.vehicle.rerouteTraveltime(veh_id, True)
|