Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# SPDX-License-Identifier: EPL-2.0
# @file runner.py
# @author Jakob Erdmann
# @date
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
import sumolib.net # noqa
net = sumolib.net.readNet(sys.argv[1])
for r in net.getRoundabouts():
print("nodes=['%s'] edges=['%s']" % (
"', '".join(r.getNodes()),
"', '".join(r.getEdges())))
for toEdge in sorted(edge.getOutgoing().keys(), key=lambda e: e.getID()):
for conn in edge.getOutgoing()[toEdge]:
fd.write('\n' %
(edge.getID(),
toEdge.getID(),
conn.getFromLane().getIndex(),
conn.getToLane().getIndex()))
fd.write("\n")
if len(sys.argv) < 2:
print("Usage: " + sys.argv[0] + " ")
sys.exit()
print("Reading net...")
net = sumolib.net.readNet(sys.argv[1])
print("Writing nodes...")
writeNodes(net)
print("Writing edges...")
writeEdges(net)
print("Writing connections...")
writeConnections(net)
optParser.set_usage(
'\nvisum_convertRoutes.py -n visum.net.xml -r visum_routes.att -o visum.rou.xml')
# parse options
(options, args) = optParser.parse_args()
if not options.netfile or not options.routes or not options.output:
print("Missing arguments")
optParser.print_help()
exit()
if options.verbose:
print("Reading net...")
net = sumolib.net.readNet(options.netfile)
net2 = None
if options.net2:
net.move(-net.getLocationOffset()[0], -net.getLocationOffset()[1])
net2 = sumolib.net.readNet(options.net2)
net2.move(-net2.getLocationOffset()[0], -net2.getLocationOffset()[1])
# initialise nodes/edge map
emap = {}
for e in net._edges:
if e._from._id not in emap:
emap[e._from._id] = {}
if e._to._id not in emap[e._from._id]:
emap[e._from._id][e._to._id] = e._id
# fill with read values
if options.verbose:
print("Reading routes...")
separator = "\t" if options.tabs else ";"
parse = False
ok = True
options = getOptions()
# read general and signal groub based information from input file(s)
sections = ["general", "links", "signal groups"]
signalColumns = ["id", "on1", "off1", "on2", "off2", "transOn", "transOff"]
if(len(options.input) == 0):
inputFiles = []
else:
inputFiles = options.input.split(',')
tlList = []
# read SUMO network
net = None
if(len(options.net) > 0):
net = sumolib.net.readNet(options.net)
if(len(options.make_input_dir) > 0): # check input template directory
if(os.path.isdir(options.make_input_dir)):
writeInputTemplates(net, options.make_input_dir, options.delimiter)
else:
sys.stderr.write("The input template directory %s does not exit.\n" % options.make_input_dir)
sys.exit(-1)
for inputFile in inputFiles: # one signal program per input file
readSgHeader = False
secondFreeTime = False
colIndices = {}
activeSection = None
cycleTime = 90
key = "SZP 1"
subkey = "0"
for toEdge in sorted(edge.getOutgoing().keys(), key=lambda e: e.getID()):
for conn in edge.getOutgoing()[toEdge]:
fd.write('\n' %
(edge.getID(),
toEdge.getID(),
conn.getFromLane().getIndex(),
conn.getToLane().getIndex()))
fd.write("\n")
if len(sys.argv) < 2:
print("Usage: " + sys.argv[0] + " ")
sys.exit()
print("Reading net...")
net = sumolib.net.readNet(sys.argv[1])
print("Writing nodes...")
writeNodes(net)
print("Writing edges...")
writeEdges(net)
print("Writing connections...")
writeConnections(net)
def main(options):
net = sumolib.net.readNet(options.netfile, withLatestPrograms=True)
if options.addfile is not None:
sumolib.net.readNet(options.addfile, withLatestPrograms=True, net=net)
TLPairs = getTLPairs(net, options.routefile, options.speed_factor, options.ignorePriority)
TLPairs = removeDuplicates(TLPairs)
sortHelper = [(
(pairData.prio, pairData.numVehicles / pairData.travelTime), # sortKey
(pairKey, pairData)) # payload
for pairKey, pairData in TLPairs.items()]
tlPairsList = [
value for sortKey, value in sorted(sortHelper, reverse=True)]
print("number of tls-pairs: %s" % len(tlPairsList))
if options.verbose:
import bz2
import StringIO
from xml.sax import make_parser, handler
from optparse import OptionParser
sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), "..", "assign"))
from dijkstra import dijkstraPlain
from inputs import getMatrix
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import sumolib.net
# This class is used to build the nodes in the investigated network and
# includes the update-function for searching the k shortest paths.
class Net(sumolib.net.Net):
def __init__(self):
sumolib.net.Net.__init__(self)
self._endVertices = []
self._startVertices = []
def addNode(self, id, type=None, coord=None, incLanes=None):
if id not in self._id2node:
node = Vertex(id, coord, incLanes)
self._nodes.append(node)
self._id2node[id] = node
self.setAdditionalNodeInfo(self._id2node[id], type, coord, incLanes)
return self._id2node[id]
def getEdge(self, edgeLabel):
return self._id2edge[edgeLabel]
def main(options):
net = sumolib.net.readNet(options.netfile)
incomingRoutes = defaultdict(set) # edge : set(route0, route1, ...)
if options.longRoutes:
# build dictionary of routes leading from an intersection to each edge
for junction in net.getNodes():
isEntry = len(junction.getIncoming()) == 0
if len(junction.getOutgoing()) > 1 or isEntry:
for edge in junction.getOutgoing():
if isEntry or getNumSiblings(edge) > 1:
edges = getEdgesToIntersection(edge)
edgeIDs = tuple([e.getID() for e in edges])
incomingRoutes[edges[-1]].add(edgeIDs)
with open(options.outfile, 'w') as outf:
sumolib.writeXMLHeader(outf, "$Id$", "additional") # noqa
for junction in net.getNodes():
if len(junction.getOutgoing()) > 1:
def main(options):
if options.seed:
random.seed(options.seed)
net = sumolib.net.readNet(options.netfile)
if options.min_distance > net.getBBoxDiameter() * (options.intermediate + 1):
options.intermediate = int(
math.ceil(options.min_distance / net.getBBoxDiameter())) - 1
print("Warning: setting number of intermediate waypoints to %s to achieve a minimum trip length of %s in a network with diameter %.2f." % (
options.intermediate, options.min_distance, net.getBBoxDiameter()))
trip_generator = buildTripGenerator(net, options)
idx = 0
vtypeattrs, options.tripattrs, personattrs, otherattrs = split_trip_attributes(
options.tripattrs, options.pedestrians, options.vehicle_class)
vias = {}
def generate_one(idx):
label = "%s%s" % (options.tripprefix, idx)
optParser.add_option("--maxV", dest="maxV",
type="float", default=None, help="Define the maximum value boundary")
optParser.add_option("-v", "--verbose", dest="verbose", action="store_true",
default=False, help="If set, the script says what it's doing")
# standard plot options
helpers.addInteractionOptions(optParser)
helpers.addPlotOptions(optParser)
# parse
options, remaining_args = optParser.parse_args(args=args)
if options.net is None:
print("Error: a network to load must be given.")
return 1
if options.verbose:
print("Reading network from '%s'" % options.net)
net = sumolib.net.readNet(options.net)
speeds = {}
minV = None
maxV = None
for e in net._id2edge:
v = net._id2edge[e]._speed
if minV is None or minV > v:
minV = v
if maxV is None or maxV < v:
maxV = v
speeds[e] = v
if options.minV is not None:
minV = options.minV
if options.maxV is not None:
maxV = options.maxV
# if options.logColors: