1
0
mirror of https://github.com/Ahp06/SUMO_Emissions.git synced 2024-11-21 19:16:30 +00:00

Added logic program list into trafic lights

This commit is contained in:
Ahp06 2018-11-29 11:48:07 +01:00
parent 9a964c97e9
commit 635004bcb9
3 changed files with 16 additions and 9 deletions

View File

@ -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()

View File

@ -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))

View File

@ -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"""