1
0
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:
Ahp06 2018-11-20 14:54:19 +01:00
parent 4c0ffc3778
commit f092e6af8d
3 changed files with 24 additions and 16 deletions

View File

@ -21,16 +21,16 @@ def lanes_in_area(area):
yield lane_id
def computeEdgeWeight(edge_id):
return traci.edge.getCO2Emission(edge_id)
def rerouteEffortVehicles():
for veh_id in traci.vehicle.getIDList():
traci.vehicle.rerouteEffort(veh_id)
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 adjustEdgesWeight():
for edge_id in traci.edge.getIDList():
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]):
max_speed = 30

View File

@ -14,9 +14,12 @@ else:
_SUMOCMD = 'sumo' # use 'sumo-gui' cmd for UI
_SUMOCFG = "mulhouse_simulation/osm.sumocfg"
CELLS_NUMBER = 10
CO2_THRESHOLD = 500000
EMISSIONS_THRESHOLD = 500000
n_steps = 200
lock_mode = True
routing_mode = False
sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', _SUMOCMD)
sumo_cmd = [sumo_binary, "-c", _SUMOCFG]

View File

@ -19,7 +19,7 @@ def init_grid(simulation_bounds, cells_number):
ar_bounds = ((i * width, j * height), (i * width, (j + 1) * height),
((i + 1) * width, (j + 1) * height), ((i + 1) * width, j * height))
area = Area(ar_bounds)
area.name = 'area {}/{}'.format(i, j)
area.name = 'area ({},{})'.format(i, j)
areas.append(area)
traci.polygon.add(area.name, ar_bounds, (0, 255, 0))
return areas
@ -37,6 +37,7 @@ def get_all_vehicles() -> List[Vehicle]:
veh_pos = traci.vehicle.getPosition(veh_id)
vehicle = Vehicle(veh_id, veh_pos)
vehicle.emissions = compute_vehicle_emissions(veh_id)
traci.vehicle.setRoutingMode(veh_id, traci.constants.ROUTING_MODE_AGGREGATED)
vehicles.append(vehicle)
return vehicles
@ -54,7 +55,7 @@ def get_emissions(grid: List[Area], vehicles: List[Vehicle]):
for vehicle in vehicles:
if vehicle.pos in area:
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)
traci.polygon.setColor(area.name, (255, 0, 0))
traci.polygon.setFilled(area.name, True)
@ -74,20 +75,26 @@ def main():
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:
traci.simulationStep()
vehicles = get_all_vehicles()
get_emissions(grid, vehicles)
#actions.adjustEdgesWeight()
#actions.rerouteEffortVehicles()
if config.routing_mode == True:
actions.adjustEdgesWeight()
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 += area.emissions
@ -99,8 +106,6 @@ def main():
diff_with_lock = (total_emissions200 - total_emissions)/total_emissions200
print(f'**** Reduction percentage of emissions = {diff_with_lock*100} % ****\n')
traci.close(False)
if __name__ == '__main__':
main()