mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2024-11-24 12:36:30 +00:00
Changed some config parameters
This commit is contained in:
parent
4c0ffc3778
commit
f092e6af8d
@ -21,20 +21,20 @@ def lanes_in_area(area):
|
|||||||
yield lane_id
|
yield lane_id
|
||||||
|
|
||||||
def computeEdgeWeight(edge_id):
|
def computeEdgeWeight(edge_id):
|
||||||
return traci.edge.getCO2Emission(edge_id)
|
return (traci.edge.getCOEmission(edge_id)
|
||||||
|
+ traci.edge.getNOxEmission(edge_id)
|
||||||
def rerouteEffortVehicles():
|
+ traci.edge.getHCEmission(edge_id)
|
||||||
for veh_id in traci.vehicle.getIDList():
|
+ traci.edge.getPMxEmission(edge_id)
|
||||||
traci.vehicle.rerouteEffort(veh_id)
|
+ traci.edge.getCO2Emission(edge_id))
|
||||||
|
|
||||||
def adjustEdgesWeight():
|
def adjustEdgesWeight():
|
||||||
for edge_id in traci.edge.getIDList():
|
for edge_id in traci.edge.getIDList():
|
||||||
weight = computeEdgeWeight(edge_id) #by default edges weight = length/mean speed
|
weight = computeEdgeWeight(edge_id) #by default edges weight = length/mean speed
|
||||||
traci.edge.setEffort(edge_id, weight)
|
traci.edge.adaptTraveltime(edge_id, weight)
|
||||||
|
|
||||||
def lock_area(area: Area, vehicles: Iterable[Vehicle]):
|
def lock_area(area: Area, vehicles: Iterable[Vehicle]):
|
||||||
max_speed = 30
|
max_speed = 30
|
||||||
print(f' Setting max speed into {area.name} to {max_speed} km/h')
|
print(f'Setting max speed into {area.name} to {max_speed} km/h')
|
||||||
area.locked = True
|
area.locked = True
|
||||||
for lane in area._lanes:
|
for lane in area._lanes:
|
||||||
traci.lane.setMaxSpeed(lane.lane_id, max_speed/3.6)
|
traci.lane.setMaxSpeed(lane.lane_id, max_speed/3.6)
|
||||||
|
@ -14,9 +14,12 @@ else:
|
|||||||
_SUMOCMD = 'sumo' # use 'sumo-gui' cmd for UI
|
_SUMOCMD = 'sumo' # use 'sumo-gui' cmd for UI
|
||||||
_SUMOCFG = "mulhouse_simulation/osm.sumocfg"
|
_SUMOCFG = "mulhouse_simulation/osm.sumocfg"
|
||||||
CELLS_NUMBER = 10
|
CELLS_NUMBER = 10
|
||||||
CO2_THRESHOLD = 500000
|
EMISSIONS_THRESHOLD = 500000
|
||||||
n_steps = 200
|
n_steps = 200
|
||||||
|
|
||||||
|
lock_mode = True
|
||||||
|
routing_mode = False
|
||||||
|
|
||||||
sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', _SUMOCMD)
|
sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', _SUMOCMD)
|
||||||
sumo_cmd = [sumo_binary, "-c", _SUMOCFG]
|
sumo_cmd = [sumo_binary, "-c", _SUMOCFG]
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ def init_grid(simulation_bounds, cells_number):
|
|||||||
ar_bounds = ((i * width, j * height), (i * width, (j + 1) * height),
|
ar_bounds = ((i * width, j * height), (i * width, (j + 1) * height),
|
||||||
((i + 1) * width, (j + 1) * height), ((i + 1) * width, j * height))
|
((i + 1) * width, (j + 1) * height), ((i + 1) * width, j * height))
|
||||||
area = Area(ar_bounds)
|
area = Area(ar_bounds)
|
||||||
area.name = 'area {}/{}'.format(i, j)
|
area.name = 'area ({},{})'.format(i, j)
|
||||||
areas.append(area)
|
areas.append(area)
|
||||||
traci.polygon.add(area.name, ar_bounds, (0, 255, 0))
|
traci.polygon.add(area.name, ar_bounds, (0, 255, 0))
|
||||||
return areas
|
return areas
|
||||||
@ -37,6 +37,7 @@ def get_all_vehicles() -> List[Vehicle]:
|
|||||||
veh_pos = traci.vehicle.getPosition(veh_id)
|
veh_pos = traci.vehicle.getPosition(veh_id)
|
||||||
vehicle = Vehicle(veh_id, veh_pos)
|
vehicle = Vehicle(veh_id, veh_pos)
|
||||||
vehicle.emissions = compute_vehicle_emissions(veh_id)
|
vehicle.emissions = compute_vehicle_emissions(veh_id)
|
||||||
|
traci.vehicle.setRoutingMode(veh_id, traci.constants.ROUTING_MODE_AGGREGATED)
|
||||||
vehicles.append(vehicle)
|
vehicles.append(vehicle)
|
||||||
return vehicles
|
return vehicles
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ def get_emissions(grid: List[Area], vehicles: List[Vehicle]):
|
|||||||
for vehicle in vehicles:
|
for vehicle in vehicles:
|
||||||
if vehicle.pos in area:
|
if vehicle.pos in area:
|
||||||
area.emissions += vehicle.emissions
|
area.emissions += vehicle.emissions
|
||||||
if area.emissions > config.CO2_THRESHOLD and area.locked == False:
|
if config.lock_mode == True and area.emissions > config.EMISSIONS_THRESHOLD and area.locked == False:
|
||||||
actions.lock_area(area, vehicles)
|
actions.lock_area(area, vehicles)
|
||||||
traci.polygon.setColor(area.name, (255, 0, 0))
|
traci.polygon.setColor(area.name, (255, 0, 0))
|
||||||
traci.polygon.setFilled(area.name, True)
|
traci.polygon.setFilled(area.name, True)
|
||||||
@ -74,32 +75,36 @@ def main():
|
|||||||
grid = init_grid(traci.simulation.getNetBoundary(), config.CELLS_NUMBER)
|
grid = init_grid(traci.simulation.getNetBoundary(), config.CELLS_NUMBER)
|
||||||
add_lanes_to_areas(grid)
|
add_lanes_to_areas(grid)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
step = 0
|
step = 0
|
||||||
while step < config.n_steps : #traci.simulation.getMinExpectedNumber() > 0:
|
while step < config.n_steps : #traci.simulation.getMinExpectedNumber() > 0:
|
||||||
traci.simulationStep()
|
traci.simulationStep()
|
||||||
|
|
||||||
vehicles = get_all_vehicles()
|
vehicles = get_all_vehicles()
|
||||||
get_emissions(grid, vehicles)
|
get_emissions(grid, vehicles)
|
||||||
#actions.adjustEdgesWeight()
|
|
||||||
#actions.rerouteEffortVehicles()
|
if config.routing_mode == True:
|
||||||
|
actions.adjustEdgesWeight()
|
||||||
|
actions.rerouteAllVehicles()
|
||||||
|
|
||||||
step += 1
|
step += 1
|
||||||
sys.stdout.write(f'Simulation step = {step}/{config.n_steps}'+'\r')
|
sys.stdout.write(f'Simulation step = {step}/{config.n_steps}'+'\r')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
traci.close(False)
|
||||||
|
|
||||||
total_emissions = 0
|
total_emissions = 0
|
||||||
for area in areas:
|
for area in areas:
|
||||||
total_emissions += area.emissions
|
total_emissions += area.emissions
|
||||||
|
|
||||||
#Total of emissions of all pollutants in mg for 200 steps of simulation without locking areas
|
#Total of emissions of all pollutants in mg for 200 steps of simulation without locking areas
|
||||||
total_emissions200 = 43970763.15084749
|
total_emissions200 = 43970763.15084749
|
||||||
|
|
||||||
print(f'\n**** Total emissions = {total_emissions} mg ****')
|
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')
|
print(f'**** Reduction percentage of emissions = {diff_with_lock*100} % ****\n')
|
||||||
|
|
||||||
traci.close(False)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user