Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traffic_lights/loop_flow/evaluator.py
169685 views
1
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
2
# Copyright (C) 2012-2025 German Aerospace Center (DLR) and others.
3
# This program and the accompanying materials are made available under the
4
# terms of the Eclipse Public License 2.0 which is available at
5
# https://www.eclipse.org/legal/epl-2.0/
6
# This Source Code may also be made available under the following Secondary
7
# Licenses when the conditions for such availability set forth in the Eclipse
8
# Public License 2.0 are satisfied: GNU General Public License, version 2
9
# or later which is available at
10
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
11
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
12
13
# @file evaluator.py
14
# @author Daniel Krajzewicz
15
# @date 13-06-07
16
17
18
from __future__ import absolute_import
19
from __future__ import print_function
20
21
import sumolib.output
22
from pylab import clf, colorbar, imshow, legend, savefig, title, xticks, yticks
23
from runner import flow1def, flow2def, types
24
25
26
durationM = {}
27
waitStepsM = {}
28
durationMinMax = [0, 0]
29
waitStepsMinMax = [0, 0]
30
f1range = range(int(flow1def[0]), int(flow1def[1]), int(flow1def[2]))
31
rf1range = range(int(flow1def[0]), int(flow1def[1]), int(flow1def[2]))
32
rf1range.reverse()
33
f2range = range(int(flow2def[0]), int(flow2def[1]), int(flow2def[2]))
34
rf2range = range(int(flow2def[0]), int(flow2def[1]), int(flow2def[2]))
35
rf2range.reverse()
36
for t in types:
37
print("Processing outputs for %s" % t)
38
durationM[t] = []
39
waitStepsM[t] = []
40
for f1 in rf1range:
41
print(" f1 at %s" % f1)
42
durationM[t].append([])
43
waitStepsM[t].append([])
44
for f2 in f2range:
45
duration = 0
46
waitSteps = 0
47
vehNum = 0
48
# summary
49
pd = sumolib.output.parse(
50
"results/tripinfos_%s_%s_%s.xml" % (t, f1, f2), "tripinfo")
51
for v in pd:
52
if float(v.depart) < 3600:
53
continue
54
duration = duration + float(v.duration)
55
waitSteps = waitSteps + float(v.waitSteps)
56
vehNum = vehNum + 1
57
if vehNum != 0:
58
duration = duration / float(vehNum)
59
waitSteps = waitSteps / float(vehNum)
60
durationM[t][-1].append(duration)
61
waitStepsM[t][-1].append(waitSteps)
62
if duration > durationMinMax[1]:
63
durationMinMax[1] = duration
64
if waitSteps > waitStepsMinMax[1]:
65
waitStepsMinMax[1] = waitSteps
66
67
"""
68
<interval begin="0.00" end="60.00" id="2i_l0" nSamples="55"
69
meanSpeed="13.89" meanOccupancy="1.19" maxOccupancy="3.90"
70
meanMaxJamLengthInVehicles="0.00" meanMaxJamLengthInMeters="0.00" maxJamLengthInVehicles="0"
71
maxJamLengthInMeters="0.00" jamLengthInVehiclesSum="0" jamLengthInMetersSum="0.00" meanHaltingDuration="0.00"
72
maxHaltingDuration="0.00" haltingDurationSum="0.00" meanIntervalHaltingDuration="0.00"
73
maxIntervalHaltingDuration="0.00" intervalHaltingDurationSum="0.00"
74
startedHalts="0.00" meanVehicleNumber="0.92" maxVehicleNumber="3" />
75
"""
76
77
78
def makeIMSHOWfigure(matrix, oname, t, rangeX, rangeY, minMax=None):
79
if minMax:
80
imshow(matrix, vmin=minMax[0], vmax=minMax[1], interpolation='nearest')
81
else:
82
imshow(matrix, interpolation='nearest')
83
legend()
84
colorbar(shrink=0.5)
85
xticks(range(0, len(matrix)), rangeX, size=14)
86
yticks(range(0, len(matrix[0])), rangeY, size=14)
87
title(t)
88
savefig(oname)
89
clf()
90
91
92
for t in types:
93
makeIMSHOWfigure(durationM[t], "durationSS_%s_png" %
94
t, "average travel time\n(%s)" % t, f1range, rf2range, durationMinMax)
95
makeIMSHOWfigure(waitStepsM[t], "waitStepsSS_%s_png" %
96
t, "average waiting steps\n(%s)" % t, f1range, rf2range, waitStepsMinMax)
97
98