mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2024-11-22 11:36:29 +00:00
Added logic program list into trafic lights
This commit is contained in:
parent
9a964c97e9
commit
635004bcb9
@ -9,12 +9,12 @@ import traci
|
|||||||
from shapely.geometry.linestring import LineString
|
from shapely.geometry.linestring import LineString
|
||||||
|
|
||||||
from model import Area, Vehicle
|
from model import Area, Vehicle
|
||||||
|
from traci._trafficlight import Logic
|
||||||
|
|
||||||
|
|
||||||
def remove_vehicle(veh_id):
|
def remove_vehicle(veh_id):
|
||||||
traci.vehicle.remove(veh_id, traci.constants.REMOVE_PARKING)
|
traci.vehicle.remove(veh_id, traci.constants.REMOVE_PARKING)
|
||||||
|
|
||||||
|
|
||||||
def compute_edge_weight(edge_id):
|
def compute_edge_weight(edge_id):
|
||||||
return (traci.edge.getCOEmission(edge_id)
|
return (traci.edge.getCOEmission(edge_id)
|
||||||
+ traci.edge.getNOxEmission(edge_id)
|
+ traci.edge.getNOxEmission(edge_id)
|
||||||
@ -27,7 +27,6 @@ def adjust_edges_weights():
|
|||||||
weight = compute_edge_weight(edge_id) # by default edges weight = length/mean speed
|
weight = compute_edge_weight(edge_id) # by default edges weight = length/mean speed
|
||||||
traci.edge.adaptTraveltime(edge_id, weight)
|
traci.edge.adaptTraveltime(edge_id, weight)
|
||||||
|
|
||||||
|
|
||||||
def limit_speed_into_area(area: Area, vehicles: Iterable[Vehicle], max_speed):
|
def limit_speed_into_area(area: Area, vehicles: Iterable[Vehicle], max_speed):
|
||||||
print(f'Setting max speed into {area.name} to {max_speed} km/h')
|
print(f'Setting max speed into {area.name} to {max_speed} km/h')
|
||||||
area.locked = True
|
area.locked = True
|
||||||
@ -35,9 +34,14 @@ def limit_speed_into_area(area: Area, vehicles: Iterable[Vehicle], max_speed):
|
|||||||
traci.lane.setMaxSpeed(lane.lane_id, max_speed/3.6)
|
traci.lane.setMaxSpeed(lane.lane_id, max_speed/3.6)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def adjust_traffic_light_phase_duration(area,reduction_factor):
|
def adjust_traffic_light_phase_duration(area,reduction_factor):
|
||||||
for tl in area._tls:
|
tl_first = area._tls[0]
|
||||||
phaseDuration = traci.trafficlight.getPhaseDuration(tl.tl_id)
|
#phaseDuration = traci.trafficlight.getPhaseDuration(tl.tl_id)
|
||||||
traci.trafficlight.setPhaseDuration(tl.tl_id, phaseDuration*reduction_factor)
|
#traci.trafficlight.setPhaseDuration(tl.tl_id, phaseDuration*reduction_factor)
|
||||||
|
first_logic = tl_first._logics[0]
|
||||||
|
print('first logic of tl_first : ' + first_logic)
|
||||||
|
|
||||||
|
first_logic = Logic()
|
||||||
|
|
||||||
|
|
@ -73,8 +73,9 @@ def add_data_to_areas(areas: List[Area]):
|
|||||||
if area.rectangle.intersects(lane.polygon):
|
if area.rectangle.intersects(lane.polygon):
|
||||||
area.add_lane(lane)
|
area.add_lane(lane)
|
||||||
for tl_id in traci.trafficlight.getIDList(): #add traffic lights
|
for tl_id in traci.trafficlight.getIDList(): #add traffic lights
|
||||||
|
logics = traci.trafficlight.getCompleteRedYellowGreenDefinition(tl_id)
|
||||||
if lane.lane_id in traci.trafficlight.getControlledLanes(tl_id):
|
if lane.lane_id in traci.trafficlight.getControlledLanes(tl_id):
|
||||||
area.add_tl(TrafficLight(tl_id))
|
area.add_tl(TrafficLight(tl_id,logics))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ from typing import Tuple, Set
|
|||||||
from shapely.geometry import Point, LineString
|
from shapely.geometry import Point, LineString
|
||||||
from shapely.geometry import Polygon
|
from shapely.geometry import Polygon
|
||||||
from shapely.geometry.base import BaseGeometry
|
from shapely.geometry.base import BaseGeometry
|
||||||
|
from traci._trafficlight import Logic
|
||||||
|
|
||||||
|
|
||||||
class Lane:
|
class Lane:
|
||||||
@ -18,8 +19,9 @@ class Lane:
|
|||||||
|
|
||||||
class TrafficLight:
|
class TrafficLight:
|
||||||
|
|
||||||
def __init__(self, tl_id: str):
|
def __init__(self, tl_id: str, logics: Set[Logic]):
|
||||||
self.tl_id = tl_id
|
self.tl_id = tl_id
|
||||||
|
self._logics: Set[Logic] = logics
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
"""Overrides the default implementation"""
|
"""Overrides the default implementation"""
|
||||||
|
Loading…
Reference in New Issue
Block a user