sumolib.files.selection

 1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
 2# Copyright (C) 2008-2026 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    selection.py
14# @author  Daniel Krajzewicz
15# @author  Michael Behrisch
16# @date    2013-05-06
17
18
19def read(file, lanes2edges=True):
20    ret = {}
21    fd = open(file)
22    for line in fd:
23        vals = line.strip().split(":")
24        if lanes2edges and vals[0] == "lane":
25            vals[0] = "edge"
26            vals[1] = vals[1][:vals[1].rfind("_")]
27        if vals[0] not in ret:
28            ret[vals[0]] = set()
29        ret[vals[0]].add(vals[1])
30    fd.close()
31    return ret
32
33
34def write(fdo, entries):
35    for t in entries:
36        writeTyped(fdo, t, entries[t])
37
38
39def writeTyped(fdo, typeName, entries):
40    for e in entries:
41        fdo.write("%s:%s\n" % (typeName, e))
def read(file, lanes2edges=True):
20def read(file, lanes2edges=True):
21    ret = {}
22    fd = open(file)
23    for line in fd:
24        vals = line.strip().split(":")
25        if lanes2edges and vals[0] == "lane":
26            vals[0] = "edge"
27            vals[1] = vals[1][:vals[1].rfind("_")]
28        if vals[0] not in ret:
29            ret[vals[0]] = set()
30        ret[vals[0]].add(vals[1])
31    fd.close()
32    return ret
def write(fdo, entries):
35def write(fdo, entries):
36    for t in entries:
37        writeTyped(fdo, t, entries[t])
def writeTyped(fdo, typeName, entries):
40def writeTyped(fdo, typeName, entries):
41    for e in entries:
42        fdo.write("%s:%s\n" % (typeName, e))