import graph as G import randomWalk import metric as m filename = "../data/10000x320000.data" nodes = 2000 graph = G.readGraph(filename) t = randomWalk.RandomWalk(graph,nodes=nodes) w=t.getGraph() print "degreeDist ",m.degreeDist(w) print "wcc ", m.wccDist(w)
import graph as G import random def randomNodeNeighbor(graph, nodes=1000): nodes = min(nodes, len(G.getEdges(graph))) #dataNodes = G.getNodes(getEdges) sampleGraph = {} sampleNodes = {} while True: if len(G.getNodes(sampleGraph)) >= nodes: break randomNode = random.choice(graph.keys()) sampleGraph[randomNode] = graph[randomNode] return sampleGraph if __name__ == "__main__": print "fetching data" data = G.readGraph("../data/5000x25000.data") print "running randomNodeNeighbor" sample = randomNodeNeighbor(data, nodes=2000) print "vars: data, sample "
import json path = "../data/smallGraph.data" #path = "../data/smallGraph.data" numNodes = 1000 fid = open("../out-final/inDegreeDist-original-graph.out", "w") fod = open("../out-final/outDegreeDist-original-graph.out", "w") fwcc = open("../out-final/wccDist-original-graph.out", "w") fscc = open("../out-final/sccDist-original-graph.out", "w") fhop = open("../out-final/hopDist-original-graph.out", "w") fclust = open("../out-final/clustDist-original-graph.out", "w") print "Reading graph..." graph = G.readGraph(path) # print "Generating samples..." # print "\t* using random edge" # sampleRE = RE.randomEdge(graph, nodes=numNodes) # print "\t* using random node" # sampleRN = RN.sampleRN(graph, nodes=numNodes) # print "\t* using random node neighbour" # sampleRNN = RNN.randomNodeNeighbor(graph, nodes=numNodes) # print "\t* using random walk" # rw = RW.RandomWalk(graph, nodes=numNodes) # sampleRW = rw.getGraph() def getAlgo(num): if num == 1: return "random edge" elif num == 2:
from graph import Graph, readGraph from console import Console ''' Created on 18 Mar 2019 @author: Marius ''' #g = readGraph("graph_file2.txt") #g = readGraph("graph1k.txt") g = readGraph("graph10k.txt") c = Console(g) c.run()
path.append(d) return getOptimumPath(s, finalVD[d][1], path) def dijkstrasShortestPathAlgo(): source, destination = raw_input( "\nEnter source and destination (source-destination): ").strip().split( '-') verticesDistances = {} for v in graph.graphAdjDict.keys(): verticesDistances[v] = 99999999 verticesDistances[source] = 0 markedVertices.append(source) finalVD[source] = [0, None] verticesDistances.pop(source) findMinDistancesFromSourceToAllVertices( source, verticesDistances ) #Calculating minimum distances for all vertices from #Given source using dijkstras algorithm path = getOptimumPath(source, destination, []) path.reverse() print "Optimum path for", source, "to", destination, "is:", path, "with distance:", finalVD[ destination][0] graph.readGraph() dijkstrasShortestPathAlgo()
from graph import MatrGraph, readGraph from console import Console ''' Created on 28 May 2019 @author: Marius ''' g = readGraph("graphHam1.txt") #g = readGraph("graph1k.txt") c = Console(g) c.run()