mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2025-04-08 03:41:00 +00:00
Replace global variable areas with local one
This commit is contained in:
parent
a22a68b10e
commit
cad845d0b4
@ -8,9 +8,9 @@ import config
|
||||
import sys
|
||||
from model import Area, Vehicle, Lane
|
||||
|
||||
areas = list()
|
||||
|
||||
def init_grid(simulation_bounds, cells_number):
|
||||
grid = list()
|
||||
width = simulation_bounds[1][0] / cells_number
|
||||
height = simulation_bounds[1][1] / cells_number
|
||||
for i in range(cells_number):
|
||||
@ -57,7 +57,7 @@ def get_emissions(grid: List[Area], vehicles: List[Vehicle]):
|
||||
for vehicle in vehicles:
|
||||
if vehicle.pos in area:
|
||||
area.emissions += vehicle.emissions
|
||||
if config.lock_mode and area.emissions > config.EMISSIONS_THRESHOLD and area.locked == False:
|
||||
if config.lock_mode and area.emissions > config.EMISSIONS_THRESHOLD and not area.locked:
|
||||
actions.lock_area(area)
|
||||
traci.polygon.setColor(area.name, (255, 0, 0))
|
||||
traci.polygon.setFilled(area.name, True)
|
||||
@ -72,40 +72,39 @@ def add_lanes_to_areas(areas: List[Area]):
|
||||
|
||||
|
||||
def main():
|
||||
grid = list()
|
||||
try:
|
||||
traci.start(config.sumo_cmd)
|
||||
grid = init_grid(traci.simulation.getNetBoundary(), config.CELLS_NUMBER)
|
||||
add_lanes_to_areas(grid)
|
||||
|
||||
|
||||
|
||||
step = 0
|
||||
while step < config.n_steps : #traci.simulation.getMinExpectedNumber() > 0:
|
||||
|
||||
step = 0
|
||||
while step < config.n_steps: # traci.simulation.getMinExpectedNumber() > 0:
|
||||
traci.simulationStep()
|
||||
|
||||
|
||||
vehicles = get_all_vehicles()
|
||||
get_emissions(grid, vehicles)
|
||||
|
||||
if config.routing_mode == True:
|
||||
actions.adjustEdgesWeight()
|
||||
actions.rerouteAllVehicles()
|
||||
|
||||
step += 1
|
||||
sys.stdout.write(f'Simulation step = {step}/{config.n_steps}'+'\r')
|
||||
|
||||
if config.routing_mode:
|
||||
actions.adjust_edges_weights()
|
||||
# actions.rerouteAllVehicles()
|
||||
|
||||
step += 1
|
||||
sys.stdout.write(f'Simulation step = {step}/{config.n_steps}' + '\r')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
finally:
|
||||
traci.close(False)
|
||||
|
||||
total_emissions = 0
|
||||
for area in areas:
|
||||
|
||||
total_emissions = 0
|
||||
for area in grid:
|
||||
total_emissions += area.emissions
|
||||
|
||||
#Total of emissions of all pollutants in mg for 200 steps of simulation without locking areas
|
||||
total_emissions200 = 43970763.15084749
|
||||
|
||||
|
||||
# Total of emissions of all pollutants in mg for 200 steps of simulation without locking areas
|
||||
total_emissions200 = 43970763.15084749
|
||||
|
||||
print(f'\n**** Total emissions = {total_emissions} mg ****')
|
||||
diff_with_lock = (total_emissions200 - total_emissions)/total_emissions200
|
||||
diff_with_lock = (total_emissions200 - total_emissions) / total_emissions200
|
||||
print(f'**** Reduction percentage of emissions = {diff_with_lock*100} % ****\n')
|
||||
|
||||
|
||||
|
@ -56,7 +56,7 @@ class Area:
|
||||
class Vehicle:
|
||||
|
||||
def __init__(self, veh_id: int, pos: Tuple[float, float]):
|
||||
self.emissions: float = None
|
||||
self.emissions: float = 0.0
|
||||
self.veh_id = veh_id
|
||||
self.pos = Point(pos)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user