Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/emissions/findMinDiffModel.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) 2016-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 findMinDiffModel.py
16
# @author Michael Behrisch
17
# @date 2016-08-24
18
19
"""
20
This script takes the output file of the emission tests and tries to
21
find models most similar to a given model concerning the emission values.
22
"""
23
from __future__ import absolute_import
24
from __future__ import print_function
25
26
import sys
27
import pprint
28
29
emissionFile = sys.argv[1]
30
for refModel in sys.argv[2:]:
31
refValue = {}
32
minDiff = {}
33
findRef = False
34
minRelDiff = None
35
for line in open(emissionFile):
36
ls = line.split(":")
37
if line[:7] == "Running":
38
model = line.split()[1][1:-1]
39
if model == refModel:
40
findRef = True
41
elif line[:7] == "Success":
42
findRef = False
43
elif findRef and len(ls) > 1:
44
refValue[ls[0]] = float(ls[1])
45
for line in open(emissionFile):
46
ls = line.split(":")
47
if line[:7] == "Running":
48
model = line.split()[1][1:-1]
49
relDiff = 0.
50
fuelDiff = 0.
51
elif model != refModel and line[:7] == "Success":
52
if "HDV" in model:
53
print(refModel, model, relDiff / len(minDiff), fuelDiff)
54
if minRelDiff is None or relDiff < minRelDiff[0]:
55
minRelDiff = (relDiff, model)
56
elif model != refModel and len(ls) > 1:
57
emission = ls[0]
58
if emission != "length" and emission != "electricity":
59
diff = float(ls[1]) - refValue[emission]
60
relDiff += abs(diff) / refValue[emission]
61
if emission == "fuel":
62
fuelDiff = abs(diff) / refValue[emission]
63
if emission not in minDiff or abs(diff) < abs(minDiff[emission][0]):
64
minDiff[emission] = (diff, model)
65
print(refModel, minRelDiff[1], minRelDiff[0] / len(minDiff))
66
pprint.pprint(refValue)
67
pprint.pprint(minDiff)
68
69