def analyzeGraph(fileName, numHops): os.system("clear") print outputDir Graph = utilities.getGraph(fileName) #Graph = loadGraph() graphNodes = Graph.keys() visitedNodes = set() currIndex = 1 while currIndex <= NUMITERATIONS: startIdx = random.randint(0, len(graphNodes)) startNode = graphNodes[startIdx] if startNode not in visitedNodes: print "Random Walk" runRW(startNode, numHops, Graph, currIndex) print "Uniform sample" getUniformSample(numHops, Graph, currIndex) print "BFS" #runBFS(startNode, numHops, Graph, currIndex) bfs(startNode, numHops, Graph, currIndex) print "RDS" try: runRDS(startNode, numHops, Graph, currIndex) except: print "RDS: StartNode %s Run %s bombed......................." % ( startNode, currIndex) currIndex += 1 """
def analyzeGraph(fileName, numHops): os.system("clear") print outputDir Graph = utilities.getGraph(fileName) #Graph = loadGraph() graphNodes = Graph.keys() visitedNodes = set() currIndex = 1 while currIndex <= NUMITERATIONS: startIdx = random.randint(0, len(graphNodes)) startNode = graphNodes[startIdx] if startNode not in visitedNodes: print "Random Walk" runRW(startNode, numHops, Graph, currIndex) print "Uniform sample" getUniformSample(numHops, Graph, currIndex) print "BFS" #runBFS(startNode, numHops, Graph, currIndex) bfs(startNode, numHops, Graph, currIndex) print "RDS" try: runRDS(startNode, numHops, Graph, currIndex) except: print "RDS: StartNode %s Run %s bombed......................."%(startNode, currIndex) currIndex += 1 """
def analyzeGraph(fileName, numHops): os.system("clear") Graph = utilities.getGraph(fileName) #Graph = loadGraph() graphNodes = Graph.keys() startIdx = random.randint(0, len(graphNodes)) #FIXME start node should be explicit startNode = graphNodes[startIdx] print "startIdx = %s, startNode = %s"%(startIdx, startNode) print "Random Walk" RWalkDict, RWalkList = runRW(startNode, numHops, Graph, ITERNUM) print RWalkDict zEst = utilities.getZEstimate(RWalkList, Graph) print "Z-estimate = %s"%zEst print "Uniform sample:" UNI = getUniformSample(numHops, Graph, ITERNUM) print UNI print "BFS" BFSWalk = runBFS(startNode, numHops, Graph, ITERNUM) print BFSWalk
def getRawData(fileName): opfile = "rawDataDegree_%s"%fileName degDistFile = "rawDataDistribution_%s"%fileName distDict = {} #distribution count Graph = utilities.getGraph(fileName) graphNodes = Graph.keys() for neighborList in Graph.values(): degree = len(neighborList) if distDict.has_key(degree): distDict[degree] += 1 else: distDict[degree] = 1 fp = open(opfile, "w") fp2 = open(degDistFile, "w") for node in graphNodes: fp.write("%s\t%s\n"%(node, len(Graph[node]))) fp2.write("%s\t%s\t%s\n"%(len(Graph[node]), \ distDict[len(Graph[node])], distDict[len(Graph[node])] / len(Graph))) """ """ fp.close() fp2.close() print ("Files saved: %s, %s"%(opfile, degDistFile))
def getRawData(fileName): opfile = "rawData/rawDataDegree_%s" % fileName degDistFile = "rawData/rawDataDistribution_%s" % fileName distDict = {} #distribution count Graph = utilities.getGraph(fileName) graphNodes = Graph.keys() for neighborList in Graph.values(): degree = len(neighborList) if distDict.has_key(degree): distDict[degree] += 1 else: distDict[degree] = 1 fp = open(opfile, "w") fp2 = open(degDistFile, "w") for node in graphNodes: fp.write("%s\t%s\n" % (node, len(Graph[node]))) fp2.write("%s\t%s\t%s\n"%(len(Graph[node]), \ distDict[len(Graph[node])], distDict[len(Graph[node])] / len(Graph))) """ """ fp.close() fp2.close() print("Files saved: %s, %s" % (opfile, degDistFile))
def analyzeGraph(fileName, numHops): os.system("clear") Graph = utilities.getGraph(fileName) #Graph = loadGraph() graphNodes = Graph.keys() startIdx = random.randint( 0, len(graphNodes)) #FIXME start node should be explicit startNode = graphNodes[startIdx] print "startIdx = %s, startNode = %s" % (startIdx, startNode) print "Random Walk" RWalkDict, RWalkList = runRW(startNode, numHops, Graph, ITERNUM) print RWalkDict zEst = utilities.getZEstimate(RWalkList, Graph) print "Z-estimate = %s" % zEst print "Uniform sample:" UNI = getUniformSample(numHops, Graph, ITERNUM) print UNI print "BFS" BFSWalk = runBFS(startNode, numHops, Graph, ITERNUM) print BFSWalk