Path: blob/main/tests/complex/traffic_lights/loop_flow/evaluator.py
169685 views
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo1# Copyright (C) 2012-2025 German Aerospace Center (DLR) and others.2# This program and the accompanying materials are made available under the3# terms of the Eclipse Public License 2.0 which is available at4# https://www.eclipse.org/legal/epl-2.0/5# This Source Code may also be made available under the following Secondary6# Licenses when the conditions for such availability set forth in the Eclipse7# Public License 2.0 are satisfied: GNU General Public License, version 28# or later which is available at9# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html10# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1112# @file evaluator.py13# @author Daniel Krajzewicz14# @date 13-06-07151617from __future__ import absolute_import18from __future__ import print_function1920import sumolib.output21from pylab import clf, colorbar, imshow, legend, savefig, title, xticks, yticks22from runner import flow1def, flow2def, types232425durationM = {}26waitStepsM = {}27durationMinMax = [0, 0]28waitStepsMinMax = [0, 0]29f1range = range(int(flow1def[0]), int(flow1def[1]), int(flow1def[2]))30rf1range = range(int(flow1def[0]), int(flow1def[1]), int(flow1def[2]))31rf1range.reverse()32f2range = range(int(flow2def[0]), int(flow2def[1]), int(flow2def[2]))33rf2range = range(int(flow2def[0]), int(flow2def[1]), int(flow2def[2]))34rf2range.reverse()35for t in types:36print("Processing outputs for %s" % t)37durationM[t] = []38waitStepsM[t] = []39for f1 in rf1range:40print(" f1 at %s" % f1)41durationM[t].append([])42waitStepsM[t].append([])43for f2 in f2range:44duration = 045waitSteps = 046vehNum = 047# summary48pd = sumolib.output.parse(49"results/tripinfos_%s_%s_%s.xml" % (t, f1, f2), "tripinfo")50for v in pd:51if float(v.depart) < 3600:52continue53duration = duration + float(v.duration)54waitSteps = waitSteps + float(v.waitSteps)55vehNum = vehNum + 156if vehNum != 0:57duration = duration / float(vehNum)58waitSteps = waitSteps / float(vehNum)59durationM[t][-1].append(duration)60waitStepsM[t][-1].append(waitSteps)61if duration > durationMinMax[1]:62durationMinMax[1] = duration63if waitSteps > waitStepsMinMax[1]:64waitStepsMinMax[1] = waitSteps6566"""67<interval begin="0.00" end="60.00" id="2i_l0" nSamples="55"68meanSpeed="13.89" meanOccupancy="1.19" maxOccupancy="3.90"69meanMaxJamLengthInVehicles="0.00" meanMaxJamLengthInMeters="0.00" maxJamLengthInVehicles="0"70maxJamLengthInMeters="0.00" jamLengthInVehiclesSum="0" jamLengthInMetersSum="0.00" meanHaltingDuration="0.00"71maxHaltingDuration="0.00" haltingDurationSum="0.00" meanIntervalHaltingDuration="0.00"72maxIntervalHaltingDuration="0.00" intervalHaltingDurationSum="0.00"73startedHalts="0.00" meanVehicleNumber="0.92" maxVehicleNumber="3" />74"""757677def makeIMSHOWfigure(matrix, oname, t, rangeX, rangeY, minMax=None):78if minMax:79imshow(matrix, vmin=minMax[0], vmax=minMax[1], interpolation='nearest')80else:81imshow(matrix, interpolation='nearest')82legend()83colorbar(shrink=0.5)84xticks(range(0, len(matrix)), rangeX, size=14)85yticks(range(0, len(matrix[0])), rangeY, size=14)86title(t)87savefig(oname)88clf()899091for t in types:92makeIMSHOWfigure(durationM[t], "durationSS_%s_png" %93t, "average travel time\n(%s)" % t, f1range, rf2range, durationMinMax)94makeIMSHOWfigure(waitStepsM[t], "waitStepsSS_%s_png" %95t, "average waiting steps\n(%s)" % t, f1range, rf2range, waitStepsMinMax)969798