def startElement(self, name, attrs):
     if name == 'interval':
         self._maxT = max(float(attrs['end']), self._maxT)
     if name == 'edge':
         edgeID = attrs['id']
         CO = float(attrs['CO_perVeh'])
         CO2 = float(attrs['CO2_perVeh'])
         HC = float(attrs['HC_perVeh'])
         PMx = float(attrs['PMx_perVeh'])
         NOx = float(attrs['NOx_perVeh'])
         fuel = float(attrs['fuel_perVeh'])
         if edgeID[0] == ':':
             nodeIDs = edgeID[1:edgeID.find('_')]
         else:
             fromNodeID = net.getEdge(edgeID)._from._id
             toNodeID = net.getEdge(edgeID)._to._id
             nodeIDs = [fromNodeID, toNodeID]
         for nodeID in nodeIDs:
             if nodeID not in self._nodeIntervalCO:
                 self._nodeIntervalCO[nodeID] = []
                 self._nodeIntervalCO2[nodeID] = []
                 self._nodeIntervalHC[nodeID] = []
                 self._nodeIntervalPMx[nodeID] = []
                 self._nodeIntervalNOx[nodeID] = []
                 self._nodeIntervalfuel[nodeID] = []
             self._nodeIntervalCO[nodeID].append(CO)
             self._nodeIntervalCO2[nodeID].append(CO2)
             self._nodeIntervalHC[nodeID].append(HC)
             self._nodeIntervalPMx[nodeID].append(PMx)
             self._nodeIntervalNOx[nodeID].append(NOx)
             self._nodeIntervalfuel[nodeID].append(fuel)
 def startElement(self, name, attrs):
     if name == "interval":
         self._maxT = max(float(attrs["end"]), self._maxT)
     if name == "edge":
         edgeID = attrs["id"]
         CO = float(attrs["CO_perVeh"])
         CO2 = float(attrs["CO2_perVeh"])
         HC = float(attrs["HC_perVeh"])
         PMx = float(attrs["PMx_perVeh"])
         NOx = float(attrs["NOx_perVeh"])
         fuel = float(attrs["fuel_perVeh"])
         if edgeID[0] == ":":
             nodeIDs = edgeID[1 : edgeID.find("_")]
         else:
             fromNodeID = net.getEdge(edgeID)._from._id
             toNodeID = net.getEdge(edgeID)._to._id
             nodeIDs = [fromNodeID, toNodeID]
         for nodeID in nodeIDs:
             if nodeID not in self._nodeIntervalCO:
                 self._nodeIntervalCO[nodeID] = []
                 self._nodeIntervalCO2[nodeID] = []
                 self._nodeIntervalHC[nodeID] = []
                 self._nodeIntervalPMx[nodeID] = []
                 self._nodeIntervalNOx[nodeID] = []
                 self._nodeIntervalfuel[nodeID] = []
             self._nodeIntervalCO[nodeID].append(CO)
             self._nodeIntervalCO2[nodeID].append(CO2)
             self._nodeIntervalHC[nodeID].append(HC)
             self._nodeIntervalPMx[nodeID].append(PMx)
             self._nodeIntervalNOx[nodeID].append(NOx)
             self._nodeIntervalfuel[nodeID].append(fuel)
 def startElement(self, name, attrs):
     if name == 'interval':
         self._maxT = max(float(attrs['end']), self._maxT)
     if name == 'edge':
         edgeID = attrs['id']
         CO = float(attrs['CO_perVeh'])
         CO2 = float(attrs['CO2_perVeh'])
         HC = float(attrs['HC_perVeh'])
         PMx = float(attrs['PMx_perVeh'])
         NOx = float(attrs['NOx_perVeh'])
         fuel = float(attrs['fuel_perVeh'])
         if edgeID[0]==':':
             nodeIDs = edgeID[1:edgeID.find('_')]
         else:
             fromNodeID = net.getEdge(edgeID)._from._id
             toNodeID = net.getEdge(edgeID)._to._id
             nodeIDs = [fromNodeID, toNodeID]
         for nodeID in nodeIDs:
             if nodeID not in self._nodeIntervalCO:
                 self._nodeIntervalCO[nodeID] = []
                 self._nodeIntervalCO2[nodeID] = []
                 self._nodeIntervalHC[nodeID] = []
                 self._nodeIntervalPMx[nodeID] = []
                 self._nodeIntervalNOx[nodeID] = []
                 self._nodeIntervalfuel[nodeID] = []
             self._nodeIntervalCO[nodeID].append(CO)
             self._nodeIntervalCO2[nodeID].append(CO2)
             self._nodeIntervalHC[nodeID].append(HC)
             self._nodeIntervalPMx[nodeID].append(PMx)
             self._nodeIntervalNOx[nodeID].append(NOx)
             self._nodeIntervalfuel[nodeID].append(fuel)
Ejemplo n.º 4
0
def getReachable(net, source_id, options):
    if not net.hasEdge(source_id):
        sys.exit("'%s' is not a valid edge id" % source_id)
    source = net.getEdge(source_id)
    fringe = [source]
    found = set()
    found.add(source)
    while len(fringe) > 0:
        new_fringe = []
        for edge in fringe:
            for reachable in edge.getOutgoing().iterkeys():
                if not reachable in found:
                    found.add(reachable)
                    new_fringe.append(reachable)
        fringe = new_fringe

    print "%s of %s edges are reachable from edge '%s':" % (
        len(found), len(net.getEdges()), source_id)

    if options.selection_output:
        with open(options.selection_output, 'w') as f:
            for e in found:
                f.write("edge:%s\n" % e.getID())
    else:
        print[e.getID() for e in found]
Ejemplo n.º 5
0
def getReachable(net, source_id, options, useIncoming=False):
    if not net.hasEdge(source_id):
        sys.exit("'{}' is not a valid edge id".format(source_id))
    source = net.getEdge(source_id)
    if options.vclass is not None and not source.allows(options.vclass):
        sys.exit("'{}' does not allow {}".format(source_id, options.vclass))
    fringe = [source]
    found = set()
    found.add(source)
    while len(fringe) > 0:
        new_fringe = []
        for edge in fringe:
            cands = edge.getIncoming() if useIncoming else edge.getOutgoing()
            for reachable in cands:
                if options.vclass is None or reachable.allows(options.vclass):
                    if reachable not in found:
                        found.add(reachable)
                        new_fringe.append(reachable)
        fringe = new_fringe

    if useIncoming:
        print("{} of {} edges can reach edge '{}':".format(
            len(found), len(net.getEdges()), source_id))
    else:
        print("{} of {} edges are reachable from edge '{}':".format(
            len(found), len(net.getEdges()), source_id))

    ids = sorted([e.getID() for e in found])
    if options.selection_output:
        with open(options.selection_output, 'w') as f:
            for e in ids:
                f.write("edge:{}\n".format(e))
    else:
        print(ids)
Ejemplo n.º 6
0
def getReachable(net, source_id, options):
    if not net.hasEdge(source_id):
        sys.exit("'%s' is not a valid edge id" % source_id)
    source = net.getEdge(source_id)
    fringe = [source]
    found = set()
    found.add(source)
    while len(fringe) > 0:
        new_fringe = []
        for edge in fringe:
            for reachable in edge.getOutgoing().iterkeys():
                if not reachable in found:
                    found.add(reachable)
                    new_fringe.append(reachable)
        fringe = new_fringe

    print "%s of %s edges are reachable from edge '%s':" % (
            len(found), len(net.getEdges()), source_id)

    if options.selection_output:
        with open(options.selection_output, 'w') as f:
            for e in found:
                f.write("edge:%s\n" % e.getID())
    else:
        print [e.getID() for e in found]
Ejemplo n.º 7
0
def getReachable(net, source_id, options, useIncoming=False):
    if not net.hasEdge(source_id):
        sys.exit("'{}' is not a valid edge id".format(source_id))
    source = net.getEdge(source_id)
    if options.vclass is not None and not source.allows(options.vclass):
        sys.exit("'{}' does not allow {}".format(source_id, options.vclass))
    fringe = [source]
    found = set()
    found.add(source)
    while len(fringe) > 0:
        new_fringe = []
        for edge in fringe:
            cands = edge.getIncoming() if useIncoming else edge.getOutgoing()
            for reachable in cands:
                if options.vclass is None or reachable.allows(options.vclass):
                    if not reachable in found:
                        found.add(reachable)
                        new_fringe.append(reachable)
        fringe = new_fringe

    if useIncoming:
        print("{} of {} edges can reach edge '{}':".format(len(found), len(net.getEdges()), source_id))
    else:
        print("{} of {} edges are reachable from edge '{}':".format(len(found), len(net.getEdges()), source_id))

    ids = sorted([e.getID() for e in found])
    if options.selection_output:
        with open(options.selection_output, 'w') as f:
            for e in ids:
                f.write("edge:{}\n".format(e))
    else:
        print(ids)
Ejemplo n.º 8
0
def getReachable(net, source_id, options, useIncoming=False):
    if not net.hasEdge(source_id):
        sys.exit("'%s' is not a valid edge id" % source_id)
    source = net.getEdge(source_id)
    if options.vclass is not None and not source.allows(options.vclass):
        sys.exit("'%s' does not allow %s" % (source_id, options.vclass))
    fringe = [source]
    found = set()
    found.add(source)
    while len(fringe) > 0:
        new_fringe = []
        for edge in fringe:
            cands = edge.getIncoming() if useIncoming else edge.getOutgoing()
            for reachable in cands.iterkeys():
                if options.vclass is None or reachable.allows(options.vclass):
                    if not reachable in found:
                        found.add(reachable)
                        new_fringe.append(reachable)
        fringe = new_fringe

    if useIncoming:
        print "%s of %s edges can reach edge '%s':" % (
            len(found), len(net.getEdges()), source_id)
    else:
        print "%s of %s edges are reachable from edge '%s':" % (
            len(found), len(net.getEdges()), source_id)

    if options.selection_output:
        with open(options.selection_output, 'w') as f:
            for e in sorted(found):
                f.write("edge:%s\n" % e.getID())
    else:
        print[e.getID() for e in found]
 def startElement(self, name, attrs):
     if name == 'interval':
         self._maxT = max(float(attrs['end']), self._maxT)
     if name == 'edge':
         edgeID = attrs['id']
         noiseStr = attrs['noise']
         if len(noiseStr) < 10:
             noise = float(noiseStr)
         else:
             noise = 0
         if edgeID[0] == ':':
             nodeID = edgeID[1:edgeID.find('_')]
             if nodeID not in self._nodeIntervalNoise:
                 self._nodeIntervalNoise[nodeID] = []
             self._nodeIntervalNoise[nodeID].append(noise)
         else:
             fromNodeID = net.getEdge(edgeID)._from._id
             if fromNodeID not in self._nodeIntervalNoise:
                 self._nodeIntervalNoise[fromNodeID] = []
             self._nodeIntervalNoise[fromNodeID].append(noise)
             toNodeID = net.getEdge(edgeID)._to._id
             if toNodeID not in self._nodeIntervalNoise:
                 self._nodeIntervalNoise[toNodeID] = []
             self._nodeIntervalNoise[toNodeID].append(noise)
 def startElement(self, name, attrs):
     if name == 'interval':
         self._maxT = max(float(attrs['end']), self._maxT)
     if name == 'edge':
         edgeID = attrs['id']
         noiseStr = attrs['noise']
         if len(noiseStr) < 10:
             noise = float(noiseStr)
         else:
             noise = 0
         if edgeID[0]==':':
             nodeID = edgeID[1:edgeID.find('_')]
             if nodeID not in self._nodeIntervalNoise:
                 self._nodeIntervalNoise[nodeID] = []
             self._nodeIntervalNoise[nodeID].append(noise)
         else:
             fromNodeID = net.getEdge(edgeID)._from._id
             if fromNodeID not in self._nodeIntervalNoise:
                 self._nodeIntervalNoise[fromNodeID] = []
             self._nodeIntervalNoise[fromNodeID].append(noise)
             toNodeID = net.getEdge(edgeID)._to._id
             if toNodeID not in self._nodeIntervalNoise:
                 self._nodeIntervalNoise[toNodeID] = []
             self._nodeIntervalNoise[toNodeID].append(noise)
 def startElement(self, name, attrs):
     if name == "interval":
         self._maxT = max(float(attrs["end"]), self._maxT)
     if name == "edge":
         edgeID = attrs["id"]
         noiseStr = attrs["noise"]
         if len(noiseStr) < 10:
             noise = float(noiseStr)
         else:
             noise = 0
         if edgeID[0] == ":":
             nodeID = edgeID[1 : edgeID.find("_")]
             if nodeID not in self._nodeIntervalNoise:
                 self._nodeIntervalNoise[nodeID] = []
             self._nodeIntervalNoise[nodeID].append(noise)
         else:
             fromNodeID = net.getEdge(edgeID)._from._id
             if fromNodeID not in self._nodeIntervalNoise:
                 self._nodeIntervalNoise[fromNodeID] = []
             self._nodeIntervalNoise[fromNodeID].append(noise)
             toNodeID = net.getEdge(edgeID)._to._id
             if toNodeID not in self._nodeIntervalNoise:
                 self._nodeIntervalNoise[toNodeID] = []
             self._nodeIntervalNoise[toNodeID].append(noise)
Ejemplo n.º 12
0
def getReachable(net, source_id, options, useIncoming=False):
    if not net.hasEdge(source_id):
        sys.exit("'{}' is not a valid edge id".format(source_id))
    source = net.getEdge(source_id)
    if options.vclass is not None and not source.allows(options.vclass):
        sys.exit("'{}' does not allow {}".format(source_id, options.vclass))
    fringe = [source]
    found = set()
    found.add(source)
    while len(fringe) > 0:
        new_fringe = []
        for edge in fringe:
            if options.vclass == "pedestrian":
                cands = chain(chain(*edge.getIncoming().values()),
                              chain(*edge.getOutgoing().values()))
            else:
                cands = chain(*(edge.getIncoming().values(
                ) if useIncoming else edge.getOutgoing().values()))
            #print("\n".join(map(str, list(cands))))
            for conn in cands:
                if options.vclass is None or (
                        conn.getFromLane().allows(options.vclass)
                        and conn.getToLane().allows(options.vclass)):
                    for reachable in [conn.getTo(), conn.getFrom()]:
                        if reachable not in found:
                            #print("added %s via %s" % (reachable, conn))
                            found.add(reachable)
                            new_fringe.append(reachable)
        fringe = new_fringe

    if useIncoming:
        print("{} of {} edges can reach edge '{}':".format(
            len(found), len(net.getEdges()), source_id))
    else:
        print("{} of {} edges are reachable from edge '{}':".format(
            len(found), len(net.getEdges()), source_id))

    ids = sorted([e.getID() for e in found])
    if options.selection_output:
        with open(options.selection_output, 'w') as f:
            for e in ids:
                f.write("edge:{}\n".format(e))
    else:
        print(ids)
Ejemplo n.º 13
0
def getReachable(net, source_id, options, useIncoming=False):
    if not net.hasEdge(source_id):
        sys.exit("'{}' is not a valid edge id".format(source_id))
    source = net.getEdge(source_id)
    if options.vclass is not None and not source.allows(options.vclass):
        sys.exit("'{}' does not allow {}".format(source_id, options.vclass))
    fringe = [source]
    found = set()
    found.add(source)
    while len(fringe) > 0:
        new_fringe = []
        for edge in fringe:
            if options.vclass == "pedestrian":
                cands = chain(chain(*edge.getIncoming().values()), chain(*edge.getOutgoing().values()))
            else:
                cands = chain(*(edge.getIncoming().values() if useIncoming else edge.getOutgoing().values()))
            # print("\n".join(map(str, list(cands))))
            for conn in cands:
                if options.vclass is None or (
                        conn.getFromLane().allows(options.vclass)
                        and conn.getToLane().allows(options.vclass)):
                    for reachable in [conn.getTo(), conn.getFrom()]:
                        if reachable not in found:
                            # print("added %s via %s" % (reachable, conn))
                            found.add(reachable)
                            new_fringe.append(reachable)
        fringe = new_fringe

    if useIncoming:
        print("{} of {} edges can reach edge '{}':".format(
            len(found), len(net.getEdges()), source_id))
    else:
        print("{} of {} edges are reachable from edge '{}':".format(
            len(found), len(net.getEdges()), source_id))

    ids = sorted([e.getID() for e in found])
    if options.selection_output:
        with open(options.selection_output, 'w') as f:
            for e in ids:
                f.write("edge:{}\n".format(e))
    else:
        print(ids)
Ejemplo n.º 14
0
                                    colIndices[line[colIndex].strip()] = colIndex
                            secondFreeTime = "on2" in colIndices.keys() and "off2" in colIndices.keys()
                        else:
                            sgID = line[colIndices["id"]]
                            sg = SignalGroup(sgID,
                                             transTimeOn=int(line[colIndices["transOn"]]),
                                             transTimeOff=int(line[colIndices["transOff"]]),
                                             debug=options.debug)
                            sg.addFreeTime(int(line[colIndices["on1"]]), int(line[colIndices["off1"]]))
                            if(secondFreeTime):
                                if(line[colIndices["on2"]] != "" and line[colIndices["off2"]] != ""):
                                    sg.addFreeTime(int(line[colIndices["on2"]]), int(line[colIndices["off2"]]))
                            signalGroups[sgID] = sg
                            signalGroupOrder.append(sgID)
                            sgFromLinkEdge = getEdgeID(sgToLinks[sgID][0][0])
                            if net.getEdge(sgFromLinkEdge).getFunction() == "walkingarea":
                                sg._stop = 'r'

                except Exception:
                    print("In file %s, line %s" % (inputFileName, i + 1), file=sys.stderr)
                    raise

        # build everything together
        tlLogic = TlLogic(key, subkey, cycleTime, offset, parameters=parameters, net=net, debug=options.debug)
        tlLogic.addSignalGroups(signalGroups, signalGroupOrder)
        tlLogic.setSignalGroupRelations(sgToLinks)
        tlLogic.setFreeTime()
        tlList.append(tlLogic)

    writeXmlOutput(tlList, options.output)
Ejemplo n.º 15
0
# @date
# @version $Id$

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

net = sumolib.net.readNet(sys.argv[1], withInternal=True)
lane = net.getLane("SC_0")

print("connections from %s:\n%s" %
      (lane.getID(), '\n'.join(list(map(str, lane.getOutgoing())))))
print("outgoing internal lanes of %s: %s" %
      (lane.getID(),
       [net.getLane(c.getViaLaneID()).getID() for c in lane.getOutgoing()]))

internal_edge = net.getEdge(":C_0")
internal_lane = net.getLane(":C_0_0")
internal_lane_cons = internal_lane.getOutgoing()
print("connections from %s:\n%s" %
      (internal_lane.getID(), '\n'.join(map(str, internal_lane_cons))))
assert (internal_edge.getFunction() == 'internal')
assert (internal_edge.isSpecial())
assert (internal_lane.getEdge().isSpecial())
assert (internal_edge.getFromNode().getID() == "C")
assert (internal_edge.getToNode().getID() == "C")
Ejemplo n.º 16
0
SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
Copyright (C) 2008-2016 DLR (http://www.dlr.de/) and contributors

This file is part of SUMO.
SUMO is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
"""
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

net = sumolib.net.readNet(sys.argv[1], withInternal=True)
lane = net.getLane("SC_0")


print(map(str, lane.getOutgoing()))

internal_edge = net.getEdge(":C_0")
internal_lane = net.getLane(":C_0_0")
assert internal_edge.getFunction() == 'internal'
assert internal_edge.isInternal()
assert internal_lane.isInternal()
Ejemplo n.º 17
0
        edge_count_dist = {}
        output_str_list = []
        dist_str_list = []

        # Iterate through components to output and summarise
        for idx, comp in enumerate(
                sorted(components, key=lambda c: next(iter(c)))):
            if options.selection_output:
                with open("{}comp{}.txt".format(options.selection_output, idx),
                          'w') as f:
                    for e in comp:
                        f.write("edge:{}\n".format(e))
            types = set()
            if options.print_types:
                for e in comp:
                    types.add(net.getEdge(e).getType())
                    if len(types) > 10:
                        break

            edge_count = len(comp)
            total += edge_count
            if edge_count > max:
                max = edge_count
                max_idx = idx

            if edge_count not in edge_count_dist:
                edge_count_dist[edge_count] = 0
            edge_count_dist[edge_count] += 1
            output_str = "Component: #{} Edge Count: {}\n {}\n".format(
                idx, edge_count, " ".join(comp))
            if types: