Exemple #1
0
def printRoutes(net, startVertex):
    if options.traveltime:
        weight = "duration"
    else:
        weight = "length"
    print "<routes>"
    for lastVertex in net.getNodes():
        routes = []
        for num, startPred in enumerate(lastVertex.preds):
            vertex = lastVertex
            pred = startPred
            route = ""
            lastEdge = None
            firstEdge = None
            while vertex != startVertex:
                firstEdge = pred.edge
                if not lastEdge:
                    lastEdge = pred.edge
                route = pred.edge.getID() + " " + route
                vertex = pred.edge._from
                pred = pred.pred
            if lastEdge != firstEdge:
                routes.append(
                    (
                        startPred.distance,
                        '%s_%s" %s="%s" edges="%s"/>'
                        % (firstEdge.getID(), lastEdge.getID(), weight, startPred.distance, route[:-1]),
                    )
                )
        for num, route in enumerate(sorted(routes)):
            print '    <route id="route%s_%s' % (num, route[1])
        print
    print "</routes>"
Exemple #2
0
def printRoutes(net, startVertex):
    if options.traveltime:
        weight = "duration"
    else:
        weight = "length"
    print("<routes>")
    for lastVertex in net.getNodes():
        routes = []
        for num, startPred in enumerate(lastVertex.preds):
            vertex = lastVertex
            pred = startPred
            route = ""
            lastEdge = None
            firstEdge = None
            while vertex != startVertex:
                firstEdge = pred.edge
                if not lastEdge:
                    lastEdge = pred.edge
                route = pred.edge.getID() + " " + route
                vertex = pred.edge._from
                pred = pred.pred
            if lastEdge != firstEdge:
                routes.append(
                    (startPred.distance, '%s_%s" %s="%s" edges="%s"/>' %
                     (firstEdge.getID(), lastEdge.getID(), weight,
                      startPred.distance, route[:-1])))
        for num, route in enumerate(sorted(routes)):
            print('    <route id="route%s_%s' % (num, route[1]))
        print()
    print("</routes>")
Exemple #3
0
def calcPaths(net, startEdgeLabel):
    for n in net.getNodes():
        n.preds = []
        n.wasUpdated = False
    for e in net.getEdges():
        e.weight = e.getLane(0).getLength()
        if options.traveltime:
            e.weight /= e.getLane(0).getSpeed()
    if startEdgeLabel:
        startVertex = net.getEdge[startEdgeLabel]._from
    else:
        startVertex = net.getNodes()[0]
    startVertex.preds.append(Predecessor(None, None, 0))
    updatedVertices = [startVertex]
    while len(updatedVertices) > 0:
        vertex = updatedVertices.pop(0)
        vertex.wasUpdated = False
        for edge in vertex.getOutgoing():
            if edge._to != startVertex and update(edge._to, edge):
                updatedVertices.append(edge._to)
    printRoutes(net, startVertex)
Exemple #4
0
def calcPaths(net, startEdgeLabel):
    for n in net.getNodes():
        n.preds = []
        n.wasUpdated = False
    for e in net.getEdges():
        e.weight = e.getLane(0).getLength()
        if options.traveltime:
            e.weight /= e.getLane(0).getSpeed()
    if startEdgeLabel:
        startVertex = net.getEdge[startEdgeLabel]._from
    else:
        startVertex = net.getNodes()[0]
    startVertex.preds.append(Predecessor(None, None, 0))
    updatedVertices = [startVertex]
    while len(updatedVertices) > 0:
        vertex = updatedVertices.pop(0)
        vertex.wasUpdated = False
        for edge in vertex.getOutgoing():
            if edge._to != startVertex and update(edge._to, edge):
                updatedVertices.append(edge._to)
    printRoutes(net, startVertex)