Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/net/prepareVISUM.py
169674 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file prepareVISUM.py
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @date 2008-09-01
18
19
"""
20
21
Parses a VISUM-file and writes a modified
22
version in "<FILENAME>_mod.net".
23
Removes all roads whose type is not within
24
types2import, patches lane number information
25
for all others using the values stored in types2import.
26
"""
27
from __future__ import absolute_import
28
from __future__ import print_function
29
30
import os
31
import sys
32
import optparse
33
34
optParser = optparse.OptionParser(usage="usage: %prog [options] <visum.net>")
35
optParser.add_option("-s", "--sumo-netconvert", dest="netconvert",
36
default="netconvert",
37
help="netconvert executable", metavar="FILE")
38
(options, args) = optParser.parse_args()
39
if len(args) != 1:
40
print("Net argument missing.", file=sys.stderr)
41
optParser.print_help()
42
sys.exit(1)
43
44
types2import = {2: 1, 10: 2, 11: 4, 12: 3, 13: 2, 14: 2, 15: 3, 16: 3, 17: 3, 18: 3, 19: 1,
45
20: 2, 21: 3, 22: 2, 23: 2, 24: 1, 25: 1, 26: 1, 27: 2, 28: 2, 29: 2,
46
30: 3, 31: 2, 32: 2, 33: 2, 34: 1, 35: 1, 36: 1, 37: 2, 38: 1, 39: 3,
47
40: 3, 41: 1, 42: 1, 43: 2, 44: 3, 45: 2, 46: 1, 47: 1, 49: 3,
48
50: 2, 51: 3, 52: 3, 53: 1, 54: 3, 55: 3, 56: 3, 57: 3, 58: 3, 59: 3,
49
60: 1, 61: 1, 62: 1, 63: 1, 64: 1, 65: 1, 66: 1, 68: 2, 69: 2,
50
70: 1, 71: 2, 72: 3, 73: 3, 74: 3, 75: 1, 76: 1, 77: 3, 78: 3, 79: 1,
51
80: 1, 81: 1, 82: 1, 83: 1, 84: 1, 85: 3, 86: 3, 87: 3, 88: 3, 89: 3,
52
90: 1, 91: 1, 92: 1, 93: 1, 94: 2, 95: 1, 96: 1, 97: 1, 98: 2, 99: 2}
53
54
fdi = open(args[0])
55
modifiedVisumNet = os.path.basename(args[0])[:-4] + "_mod.net"
56
sumoNet = modifiedVisumNet + ".xml"
57
fdo = open(modifiedVisumNet, "w")
58
process = False
59
skip = False
60
for line in fdi:
61
skip = False
62
if line.find("*") == 0 or len(line) < 2:
63
process = False
64
if process:
65
vals = line.split(";")
66
typ = int(vals[5])
67
if typ not in types2import:
68
skip = True
69
else:
70
vals[8] = str(types2import[typ])
71
line = ";".join(vals)
72
if line.find("$STRECKE:") == 0:
73
process = True
74
if not skip:
75
fdo.write(line)
76
fdi.close()
77
fdo.close()
78
79
os.system("%s --visum-file %s --dismiss-loading-errors -o %s"
80
% (options.netconvert, modifiedVisumNet, sumoNet))
81
82