1
0
mirror of https://github.com/Ahp06/SUMO_Emissions.git synced 2024-11-22 03:26:30 +00:00

Added images folder for wiki

This commit is contained in:
Ahp06 2018-12-12 10:13:33 +01:00
parent 2ab280b94e
commit ab551cc429

View File

@ -28,6 +28,7 @@ def init_grid(simulation_bounds, areas_number):
traci.polygon.add(area.name, ar_bounds, (0, 255, 0)) traci.polygon.add(area.name, ar_bounds, (0, 255, 0))
return grid return grid
def get_all_lanes() -> List[Lane]: def get_all_lanes() -> List[Lane]:
lanes = [] lanes = []
for lane_id in traci.lane.getIDList(): for lane_id in traci.lane.getIDList():
@ -36,6 +37,7 @@ def get_all_lanes() -> List[Lane]:
lanes.append(Lane(lane_id, polygon_lane, initial_max_speed)) lanes.append(Lane(lane_id, polygon_lane, initial_max_speed))
return lanes return lanes
def parse_phase(phase_repr): def parse_phase(phase_repr):
duration = search('duration: {:f}', phase_repr) duration = search('duration: {:f}', phase_repr)
minDuration = search('minDuration: {:f}', phase_repr) minDuration = search('minDuration: {:f}', phase_repr)
@ -47,6 +49,7 @@ def parse_phase(phase_repr):
return Phase(duration[0], minDuration[0], maxDuration[0], phaseDef) return Phase(duration[0], minDuration[0], maxDuration[0], phaseDef)
def add_data_to_areas(areas: List[Area]): def add_data_to_areas(areas: List[Area]):
lanes = get_all_lanes() lanes = get_all_lanes()
for area in areas: for area in areas:
@ -63,6 +66,7 @@ def add_data_to_areas(areas: List[Area]):
logics.append(Logic(l, phases)) logics.append(Logic(l, phases))
area.add_tl(TrafficLight(tl_id, logics)) area.add_tl(TrafficLight(tl_id, logics))
def compute_vehicle_emissions(veh_id): def compute_vehicle_emissions(veh_id):
return (traci.vehicle.getCOEmission(veh_id) return (traci.vehicle.getCOEmission(veh_id)
+traci.vehicle.getNOxEmission(veh_id) +traci.vehicle.getNOxEmission(veh_id)
@ -80,6 +84,7 @@ def get_all_vehicles() -> List[Vehicle]:
vehicles.append(vehicle) vehicles.append(vehicle)
return vehicles return vehicles
def get_emissions(grid: List[Area], vehicles: List[Vehicle], current_step, config, logger): def get_emissions(grid: List[Area], vehicles: List[Vehicle], current_step, config, logger):
for area in grid: for area in grid:
vehicle_emissions = 0 vehicle_emissions = 0
@ -165,7 +170,7 @@ def main(args):
# > py ./emissions.py -f configs/config1.json -save # > py ./emissions.py -f configs/config1.json -save
# will load the configuration file "config1.json" and save logs into the logs directory # will load the configuration file "config1.json" and save logs into the logs directory
# > py ./emissions.py -f configs/config1.json -save & py ./emissions.py -f configs/config1.json -save -ref # > py ./emissions.py -f configs/config1.json -save -ref & py ./emissions.py -f configs/config1.json -save
# same as above but also launches a reference simulation by using -ref option # same as above but also launches a reference simulation by using -ref option
config = Config() config = Config()
@ -180,5 +185,6 @@ def main(args):
run(config, logger) run(config, logger)
if __name__ == '__main__': if __name__ == '__main__':
main(sys.argv[1:]) main(sys.argv[1:])