From 635004bcb9444aa52db3e7475611ff55d5dc14f3 Mon Sep 17 00:00:00 2001 From: Ahp06 Date: Thu, 29 Nov 2018 11:48:07 +0100 Subject: [PATCH] Added logic program list into trafic lights --- sumo_project/actions.py | 16 ++++++++++------ sumo_project/emissions.py | 3 ++- sumo_project/model.py | 6 ++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/sumo_project/actions.py b/sumo_project/actions.py index 5453e1b..739a8cb 100644 --- a/sumo_project/actions.py +++ b/sumo_project/actions.py @@ -9,12 +9,12 @@ import traci from shapely.geometry.linestring import LineString from model import Area, Vehicle +from traci._trafficlight import Logic def remove_vehicle(veh_id): traci.vehicle.remove(veh_id, traci.constants.REMOVE_PARKING) - def compute_edge_weight(edge_id): return (traci.edge.getCOEmission(edge_id) + traci.edge.getNOxEmission(edge_id) @@ -27,17 +27,21 @@ def adjust_edges_weights(): weight = compute_edge_weight(edge_id) # by default edges weight = length/mean speed traci.edge.adaptTraveltime(edge_id, weight) - 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') area.locked = True for lane in area._lanes: traci.lane.setMaxSpeed(lane.lane_id, max_speed/3.6) - + + def adjust_traffic_light_phase_duration(area,reduction_factor): - for tl in area._tls: - phaseDuration = traci.trafficlight.getPhaseDuration(tl.tl_id) - traci.trafficlight.setPhaseDuration(tl.tl_id, phaseDuration*reduction_factor) + tl_first = area._tls[0] + #phaseDuration = traci.trafficlight.getPhaseDuration(tl.tl_id) + #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() \ No newline at end of file diff --git a/sumo_project/emissions.py b/sumo_project/emissions.py index ad461e8..bd6b913 100644 --- a/sumo_project/emissions.py +++ b/sumo_project/emissions.py @@ -73,8 +73,9 @@ def add_data_to_areas(areas: List[Area]): if area.rectangle.intersects(lane.polygon): area.add_lane(lane) 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): - area.add_tl(TrafficLight(tl_id)) + area.add_tl(TrafficLight(tl_id,logics)) diff --git a/sumo_project/model.py b/sumo_project/model.py index 5a90846..3e8da99 100644 --- a/sumo_project/model.py +++ b/sumo_project/model.py @@ -3,6 +3,7 @@ from typing import Tuple, Set from shapely.geometry import Point, LineString from shapely.geometry import Polygon from shapely.geometry.base import BaseGeometry +from traci._trafficlight import Logic class Lane: @@ -18,8 +19,9 @@ class Lane: class TrafficLight: - def __init__(self, tl_id: str): - self.tl_id = tl_id + def __init__(self, tl_id: str, logics: Set[Logic]): + self.tl_id = tl_id + self._logics: Set[Logic] = logics def __hash__(self): """Overrides the default implementation"""