示例#1
0
def betweenness_test(name):
    if os.path.isfile(DATA_PATH + name + ".between"):
        print "Skipping", name
        return

    start = time.time()

    G, coords = osmParser.simpleLoadFromFile(name)

    print "Calculating betweenness", name

    nodeToBetweenness = snap.TIntFltH()
    edgeToBetweenness = snap.TIntPrFltH()
    snap.GetBetweennessCentr(G, nodeToBetweenness, edgeToBetweenness, 0.25)

    betweenness = {}
    for node in nodeToBetweenness:
        betweenness[node] = nodeToBetweenness[node]

    betweenOut = open(DATA_PATH + name + ".between", 'w')
    pickle.dump(betweenness, betweenOut, 1)

    plotTopK(name, betweenness, coords, "GnBu")

    end = time.time()
    print "took", end - start, "seconds"
示例#2
0
def approx_closeness_test(name):
    if os.path.isfile(DATA_PATH + name + ".acloseness"):
        print "Skipping", name
        return

    start = time.time()

    G, coords = osmParser.simpleLoadFromFile(name)

    print "Calculating approx closeness", name

    closeness = weightedBetween.approxCloseness(G, coords)

    closeOut = open(DATA_PATH + name + ".acloseness", 'w')
    pickle.dump(closeness, closeOut, 1)

    plotTopK(name, closeness, coords, "PuBu")

    end = time.time()
    print "took", end - start, "seconds"
示例#3
0
def urbanness_test(name):
    if os.path.isfile(DATA_PATH + name + ".urban"):
        print "Skipping", name
        return

    start = time.time()

    G, coords = osmParser.simpleLoadFromFile(name)

    print "Calculating urbanness", name

    urbanness = weightedBetween.urbanness(G, coords)

    urbanOut = open(DATA_PATH + name + ".urban", 'w')
    pickle.dump(urbanness, urbanOut, 1)

    plotTopK(name, urbanness, coords, "BuPu")

    end = time.time()
    print "took", end - start, "seconds"
示例#4
0
def weighted_closeness_test(name):
    if os.path.isfile(DATA_PATH + name + ".wcloseness"):
        print "Skipping", name
        return

    start = time.time()

    G, coords = osmParser.simpleLoadFromFile(name)

    print "Calculating weighted closeness", name

    nodeToCloseness = weightedBetween.closenessCentrality(G, coords)

    closeOut = open(DATA_PATH + name + ".wcloseness", 'w')
    pickle.dump(nodeToCloseness, closeOut, 1)

    plotTopK(name, nodeToCloseness, coords, "GnBu")

    end = time.time()
    print "took", end - start, "seconds"
示例#5
0
    def __init__(self, name):

        graph, self.nid_to_coords = osmParser.simpleLoadFromFile(name)

        # For getting a new node id to set an edge to.
        self.NID_GENERATOR = 0

        # An integer representing the baseline # of time steps it takes to cross this street. Each indiv. car's time
        # may vary by a factor of 0.75 to 1.25.
        self.street_weights = {}

        # The average coordinates for each street (node). Average the lon lat of this street's endpoints.
        # Used for heuristics in A* search.
        self.street_coordinates = {}

        # Keep track of which edges in the snap_graph are which nodes in the dual graph. Discarded after initialization.
        self._names = {}

        # An instance of PUNGraph from snap.
        self.graph = self._create_dual_representation(graph)
示例#6
0
def plotStat(name, stat):
    if not os.path.isfile(DATA_PATH + name + "." + stat):
        print "Skipping", name
        return

    if stat == "tsd":
        print "Plotting TSD for", name
        plotTSD(name)
        return

    G, coords = osmParser.simpleLoadFromFile(name)

    infoIn = open(DATA_PATH + name + "." + stat, 'r')
    data = pickle.load(infoIn)

    color = ""
    if stat == "between":
        color = "RdPu"
    elif stat == "wbetween":
        color = "OrRd"
    elif stat == "closeness":
        color = "YlGnBu"
    elif stat == "wcloseness":
        color = "GnBu"
    elif stat == "acloseness":
        color = "PuBu"
    elif stat == "urbanness":
        color = "BuPu"
    else:
        print "Invalid stat name, exiting"
        return

    if stat == "wbetween":
        plotTopK(name, data, coords, color, useNodeBetween=False)
    else:
        plotTopK(name, data, coords, color)
示例#7
0
def plotCity(name):
    G, coordsMap = osmParser.simpleLoadFromFile(name)

    x = []
    y = []

    for edge in G.Edges():
        start = edge.GetSrcNId()
        end = edge.GetDstNId()

        coords1 = coordsMap[start]
        coords2 = coordsMap[end]

        x.append(coords1[0])
        x.append(coords2[0])
        x.append(None)
        y.append(coords1[1])
        y.append(coords2[1])
        y.append(None)

    plt.plot(y, x, 'k', linewidth=0.5)
    plt.xlabel("longitude")
    plt.ylabel("latitude")
    plt.axis('image')
示例#8
0
def closeness_test(name):
    if os.path.isfile(DATA_PATH + name + ".closeness"):
        print "Skipping", name
        return

    start = time.time()

    G, coords = osmParser.simpleLoadFromFile(name)

    print "Calculating closeness", name

    ##
    nodeToCloseness = {}
    for node in G.Nodes():
        nodeToCloseness[node.GetId()] = snap.GetClosenessCentr(G, node.GetId())
    ##

    closeOut = open(DATA_PATH + name + ".closeness", 'w')
    pickle.dump(nodeToCloseness, closeOut, 1)

    plotTopK(name, nodeToCloseness, coords, "YlGnBu")

    end = time.time()
    print "took", end - start, "seconds"
示例#9
0
def analyzeCity(city):
    graph, nodesMap = osmParser.simpleLoadFromFile(city)
    return algorithm2(graph, nodesMap), nodesMap