Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/route/route2sel.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 route2sel.py
15
# @author Jakob Erdmann
16
# @date 2015-08-05
17
18
from __future__ import print_function
19
from __future__ import absolute_import
20
import os
21
import sys
22
23
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
24
from sumolib.output import parse, parse_fast # noqa
25
from sumolib.options import ArgumentParser # noqa
26
27
28
def parse_args():
29
ap = ArgumentParser()
30
ap.add_option("routefiles", nargs="+", category="input", type=ap.file_list, help="route files")
31
ap.add_option("-o", "--outfile", category="output", type=ap.file, help="name of output file")
32
options = ap.parse_args()
33
if options.outfile is None:
34
options.outfile = options.routefiles[0] + ".sel.txt"
35
return options
36
37
38
def main():
39
options = parse_args()
40
edges = set()
41
42
for routefile in options.routefiles:
43
for route in parse_fast(routefile, 'route', ['edges']):
44
edges.update(route.edges.split())
45
for walk in parse_fast(routefile, 'walk', ['edges']):
46
edges.update(walk.edges.split())
47
48
# warn about potentially missing edges
49
for trip in parse(routefile, ['trip', 'flow'], heterogeneous=True):
50
for attr in ['attr_from', 'to', 'via']:
51
if trip.attr_from:
52
edges.update(trip.attr_from)
53
if trip.to:
54
edges.update(trip.to)
55
if trip.via:
56
edges.update(trip.via.split())
57
for walk in parse_fast(routefile, 'walk', ['from', 'to']):
58
edges.update([walk.attr_from, walk.to])
59
60
with open(options.outfile, 'w') as outf:
61
for e in sorted(list(edges)):
62
outf.write('edge:%s\n' % e)
63
64
65
if __name__ == "__main__":
66
main()
67
68