Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/assign/bestIteration.py
169673 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
4
# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file bestIteration.py
16
# @author Jakob Erdmann
17
# @date 2021-05-10
18
19
"""
20
Run duaIterate and collect statistics on the iterations
21
"""
22
import os
23
import sys
24
import subprocess
25
import glob
26
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
27
from sumolib.statistics import Statistics # noqa
28
from sumolib.xml import parse # noqa
29
from shutil import copyfile # noqa
30
31
a = sys.argv[1:]
32
33
key = ""
34
key += "L" if "--logit" in a else "G"
35
key += "_meso" if ("--mesosim" in a or "-m" in a) else ""
36
key += "_mesojc" if ("--meso-junctioncontrol" in a or "-j" in a) else ""
37
key += "_dso" if "--marginal-cost" in a else "_due"
38
if "--marginal-cost.exp" in a:
39
key += "_e%s" % a[a.index("--marginal-cost.exp") + 1]
40
if "--logittheta" in a:
41
key += "_t%s" % a[a.index("--logittheta") + 1]
42
if "--convergence-steps" in a:
43
key += "_c%s" % a[a.index("--convergence-steps") + 1]
44
for endOpt in ['-e', '--end', 'sumo--end']:
45
if endOpt in a:
46
key += "_end%s" % a[a.index(endOpt) + 1]
47
if '_' in a[0]:
48
key += a[0][a[0].find('_'):-3]
49
if "--extra-key" in a:
50
# argument only for bestIteration.py
51
index = a.index("--extra-key")
52
key += "_%s" % a[index + 1]
53
a.pop(index + 1)
54
a.pop(index)
55
56
57
print("key", key)
58
59
if not os.path.isdir(key):
60
os.makedirs(key)
61
62
os.chdir(key)
63
subprocess.call(a)
64
TTT = Statistics("TTT")
65
ATT = Statistics("ATT")
66
values = []
67
for name in glob.glob('*/stats.xml'):
68
# print(name)
69
for stats in parse(name, 'statistics'):
70
vStats = stats.vehicleTripStatistics[0]
71
vehs = stats.vehicles[0]
72
ttt = float(vStats.totalTravelTime) + float(vStats.totalDepartDelay)
73
att = ttt / int(vehs.loaded)
74
TTT.add(ttt, name)
75
ATT.add(att, name)
76
values.append((att, ttt, vStats.totalTravelTime, vStats.totalDepartDelay,
77
vStats.duration, vStats.departDelay, name))
78
79
with open('results.txt', 'w') as f:
80
f.write('#' '\t'.join(['att', 'cttt', 'ttt', 'tdd', 'tt', 'dd', 'file']) + '\n')
81
for dat in values:
82
f.write('\t'.join(map(str, dat)) + '\n')
83
84
f.write('\n# %s\n# %s\n' % (TTT, ATT))
85
86
copyfile('results.txt', os.path.join('..', 'results_%s.txt' % key))
87
88