mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2024-11-21 19:16:30 +00:00
Fixed some typos
This commit is contained in:
parent
b639b5b55b
commit
9e37aad577
@ -8,14 +8,11 @@ Created on 17 oct. 2018
|
||||
This module defines the global configuration for the simulation
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from model import Emission
|
||||
from data import Data
|
||||
from model import Emission
|
||||
|
||||
|
||||
class Config:
|
||||
|
@ -8,15 +8,8 @@ Created on 17 oct. 2018
|
||||
This module is used for loading simulation data
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
import datetime
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
import pprint
|
||||
import sys
|
||||
import time
|
||||
import traci
|
||||
from typing import List
|
||||
|
||||
@ -24,8 +17,7 @@ import jsonpickle
|
||||
from parse import search
|
||||
from shapely.geometry import LineString
|
||||
|
||||
import actions
|
||||
from model import Area, Vehicle, Lane, TrafficLight, Phase, Logic, Emission
|
||||
from model import Area, Lane, TrafficLight, Phase, Logic
|
||||
|
||||
|
||||
class Data:
|
||||
@ -33,6 +25,10 @@ class Data:
|
||||
def __init__(self, dump_name, map_bounds, areas_number,simulation_dir):
|
||||
"""
|
||||
Data constructor
|
||||
:param dump_name : The dump name chosen by the user
|
||||
:param map_bounds: The bounds of the simulated map
|
||||
:param areas_number: The number of areas in line and row chosen by the user
|
||||
:param simulation_dir: The directory which contains all files needed for SUMO
|
||||
"""
|
||||
self.dump_name = dump_name
|
||||
self.map_bounds = map_bounds
|
||||
|
@ -4,17 +4,18 @@ Created on 17 oct. 2018
|
||||
@author: Axel Huynh-Phuc, Thibaud Gasser
|
||||
"""
|
||||
|
||||
"""
|
||||
This module defines how pollutant emissions are recovered and how we act on the areas
|
||||
"""
|
||||
|
||||
import traci
|
||||
from typing import List
|
||||
|
||||
from shapely.geometry import LineString
|
||||
|
||||
import actions
|
||||
from config import Config
|
||||
from data import Data
|
||||
from model import Area, Vehicle, Lane, TrafficLight, Phase, Logic, Emission
|
||||
from model import Vehicle, Emission
|
||||
from runner import RunProcess
|
||||
|
||||
|
||||
def compute_vehicle_emissions(veh_id):
|
||||
"""
|
||||
Recover the emissions of different pollutants from a vehicle and create an Emission instance
|
||||
@ -43,16 +44,13 @@ def get_all_vehicles() -> List[Vehicle]:
|
||||
vehicles.append(vehicle)
|
||||
return vehicles
|
||||
|
||||
|
||||
def get_emissions(p : RunProcess, vehicles: List[Vehicle], current_step):
|
||||
"""
|
||||
For each area retrieves the acquired emissions in the window,
|
||||
and acts according to the configuration chosen by the user
|
||||
:param grid: The list of areas
|
||||
:param p: The current process
|
||||
:param vehicles: The list of vehicles
|
||||
:param current_step: The simulation current step
|
||||
:param config: The simulation configuration
|
||||
:param logger: The simulation logger
|
||||
:return:
|
||||
"""
|
||||
for area in p.data.grid:
|
||||
@ -86,6 +84,8 @@ def get_emissions(p : RunProcess, vehicles: List[Vehicle], current_step):
|
||||
traci.polygon.setFilled(area.name, True)
|
||||
|
||||
else:
|
||||
if area.infrastructure_changed():
|
||||
p.logger.info(f'Action - Reversed actions into area {area.name}')
|
||||
actions.reverse_actions(area)
|
||||
traci.polygon.setFilled(area.name, False)
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"_SUMOCMD": "sumo",
|
||||
|
||||
"emissions_threshold": 500000,
|
||||
"n_steps": 200,
|
||||
"window_size":100,
|
||||
|
||||
"without_actions_mode": false,
|
||||
|
||||
"limit_speed_mode": true,
|
||||
"speed_rf": 1.1,
|
||||
|
||||
"adjust_traffic_light_mode": true,
|
||||
"trafficLights_duration_rf": 0.3,
|
||||
|
||||
"weight_routing_mode": false,
|
||||
|
||||
"lock_area_mode": false
|
||||
|
||||
}
|
@ -20,7 +20,7 @@ from shapely.geometry.base import BaseGeometry
|
||||
class Lane:
|
||||
"""
|
||||
The Lane class includes the polygon defining the lane
|
||||
and keep in memory the initial maximum speed on the lane
|
||||
and keep in memory the initial maximum speed of the lane
|
||||
"""
|
||||
|
||||
def __init__(self, lane_id: str, polygon: LineString, initial_max_speed: float):
|
||||
@ -258,6 +258,9 @@ class Area:
|
||||
(xmax, ymax),
|
||||
(xmax, ymin)))
|
||||
|
||||
def infrastructure_changed(self):
|
||||
return (self.limited_speed or self.locked or self.tls_adjusted or self.weight_adjusted)
|
||||
|
||||
|
||||
class Vehicle:
|
||||
"""
|
||||
|
@ -8,6 +8,10 @@ Created on 19 janv. 2019
|
||||
This module defines the entry point of the application
|
||||
"""
|
||||
|
||||
"""
|
||||
Init the Traci API
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
import datetime
|
||||
@ -26,9 +30,7 @@ from data import Data
|
||||
import emissions
|
||||
from model import Emission
|
||||
|
||||
"""
|
||||
Init the Traci API
|
||||
"""
|
||||
|
||||
if 'SUMO_HOME' in os.environ:
|
||||
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
|
||||
sys.path.append(tools)
|
||||
@ -36,6 +38,9 @@ else:
|
||||
sys.exit("please declare environment variable 'SUMO_HOME'")
|
||||
|
||||
class RunProcess(multiprocessing.Process):
|
||||
"""
|
||||
Run process inheriting from multiprocessing.Process
|
||||
"""
|
||||
|
||||
def __init__(self, data : Data, config : Config, save_logs, csv_export):
|
||||
"""
|
||||
@ -99,12 +104,15 @@ class RunProcess(multiprocessing.Process):
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Run a data set
|
||||
Launch a simulation, will be called when a RunProcess instance is started
|
||||
"""
|
||||
try:
|
||||
self.init_logger()
|
||||
self.logger.info(f'Running simulation dump "{self.data.dump_name}" with the config "{self.config.config_filename}" ...')
|
||||
|
||||
if self.config.without_actions_mode:
|
||||
self.logger.info('Reference simulation')
|
||||
|
||||
traci.start(self.config.sumo_cmd)
|
||||
|
||||
for area in self.data.grid: # Set acquisition window size
|
||||
@ -134,20 +142,25 @@ class RunProcess(multiprocessing.Process):
|
||||
total_emissions += area.sum_all_emissions()
|
||||
|
||||
self.logger.info(f'Total emissions = {total_emissions.value()} mg')
|
||||
for pollutant in ['co2','co','nox','hc','pmx']:
|
||||
value = total_emissions.__getattribute__(pollutant)
|
||||
self.logger.info(f'{pollutant.upper()} = {value} mg')
|
||||
|
||||
if not self.config.without_actions_mode: # If it's not a simulation without actions
|
||||
ref = self.config.get_ref_emissions()
|
||||
if not (ref is None): # If a reference value exist (add yours into config.py)
|
||||
global_diff = (ref.value() - total_emissions.value()) / ref.value()
|
||||
self.logger.info(f'Global reduction percentage of emissions = {global_diff * 100} %')
|
||||
self.logger.info(f'-> CO2 emissions = {emissions.get_reduction_percentage(ref.co2, total_emissions.co2)} %')
|
||||
self.logger.info(f'-> CO emissions = {emissions.get_reduction_percentage(ref.co, total_emissions.co)} %')
|
||||
self.logger.info(f'-> Nox emissions = {emissions.get_reduction_percentage(ref.nox, total_emissions.nox)} %')
|
||||
self.logger.info(f'-> HC emissions = {emissions.get_reduction_percentage(ref.hc, total_emissions.hc)} %')
|
||||
self.logger.info(f'-> PMx emissions = {emissions.get_reduction_percentage(ref.pmx, total_emissions.pmx)} %')
|
||||
|
||||
for pollutant in ['co2','co','nox','hc','pmx']:
|
||||
reduc_percentage = emissions.get_reduction_percentage(ref.__getattribute__(pollutant),
|
||||
total_emissions.__getattribute__(pollutant))
|
||||
self.logger.info(f'-> {pollutant.upper()} reduction = {reduc_percentage} %')
|
||||
|
||||
|
||||
simulation_time = round(time.perf_counter() - start, 2)
|
||||
self.logger.info(f'End of the simulation ({simulation_time}s)')
|
||||
|
||||
# 1 step is equal to one second simulated
|
||||
self.logger.info(f'Real-time factor : {self.config.n_steps / simulation_time}')
|
||||
|
||||
@ -190,9 +203,6 @@ def add_options(parser):
|
||||
:return:
|
||||
"""
|
||||
|
||||
# TODO: Faire que -areas & -simulation_dir soit requis si -new_dump
|
||||
# Faire que -c soit requis si -run
|
||||
|
||||
parser.add_argument("-new_dump", "--new_dump", type=str,
|
||||
help='Load and create a new data dump with the configuration file chosen')
|
||||
parser.add_argument("-areas", "--areas", type=int,
|
||||
|
Loading…
Reference in New Issue
Block a user