1
0
mirror of https://github.com/Ahp06/SUMO_Emissions.git synced 2024-11-22 11:36:29 +00:00
sumo-emissions/sumo_project/actions.py

45 lines
1.2 KiB
Python
Raw Normal View History

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)
2018-11-15 12:51:46 +00:00
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
def compute_edge_weight(edge_id):
2018-11-20 13:54:19 +00:00
return (traci.edge.getCOEmission(edge_id)
+ traci.edge.getNOxEmission(edge_id)
+ traci.edge.getHCEmission(edge_id)
+ traci.edge.getPMxEmission(edge_id)
+ traci.edge.getCO2Emission(edge_id))
def adjust_edges_weights():
2018-11-19 15:28:29 +00:00
for edge_id in traci.edge.getIDList():
weight = compute_edge_weight(edge_id) # by default edges weight = length/mean speed
traci.edge.adaptTraveltime(edge_id, weight)
2018-11-15 12:51:46 +00:00
def lock_area(area: Area):
2018-11-19 15:28:29 +00:00
max_speed = 30
2018-11-20 13:54:19 +00:00
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)