def main(): msg = "usage: ./p2p2012.py type r|g|g2 ttl par tries churn_rate" if len(sys.argv) < 7: print msg sys.exit(1) global out_file, churn_rate out_file = sys.stdout gtype = sys.argv[1] walk = sys.argv[2] ttl = int(sys.argv[3]) par = int(sys.argv[4]) tries = int(sys.argv[5]) churn_rate = float(sys.argv[6]) if gtype == "a": g = nx.barabasi_albert_graph(97134, 3) elif gtype == "b": g = nx.barabasi_albert_graph(905668, 12) elif gtype == "c": g = sm.randomWalk_mod(97134, 0.90, 0.23) elif gtype == "d": g = sm.randomWalk_mod(905668, 0.93, 0.98) elif gtype == "e": g = sm.nearestNeighbor_mod(97134, 0.53, 1) elif gtype == "f": g = sm.nearestNeighbor_mod(905668, 0.90, 5) elif gtype == "g": g = nx.random_regular_graph(6, 97134) elif gtype == "h": g = nx.random_regular_graph(20, 905668) elif gtype == "i": g = nx.read_edgelist(sys.argv[7]) if walk == "r": lookup(g, ttl, tries, par, get_random_node) elif walk == "g": lookup(g, ttl, tries, par, get_greedy_node) elif walk == "g2": lookup(g, ttl, tries, par, get_greedy2_node) elif walk == "sum": sum_edges(g, int(sys.argv[3])) nodes = g.number_of_nodes() edges = g.size() avg_cc = nx.average_clustering(g) print >> sys.stderr, nodes, edges, avg_cc
def fit_nearestNeighbor_mod(graphSize, graphID, dkPath, original2k, resultPath, k): """ Runs synthetic graph tests for various 'k' and 'u' values and stores them """ if k: outfile = open(resultPath + graphID + '_nnFine_dkDistances.txt', 'w') kList = [k] uList = [] myU = 0.01 while myU < 1: uList.append(myU) myU += 0.01 else: outfile = open(resultPath + graphID + '_nnCoarse_dkDistances.txt', 'w') kList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] uList = [ .01, .05, .10, .20, .25, .30, .35, .40, .45, .50, .55, .60, .65, .70, .75, .80, .85, .95 ] outfile.write('dk-2 Distance\tk\tu\n') for k in kList: for u in uList: print 'Running modified Nearest Neighbor with parameters: n = ', graphSize, ' k = ', k, ' u = ', u newFile = graphID + '_nn_' + str(k) + '_' + str(u) # Create synthetic graph syntheticGraph = sm.nearestNeighbor_mod(graphSize, u, k) # Write pickle, edge list, and 2k distro to file print 'Writing pickle and calculating dK-2...\n' nx.write_gpickle(syntheticGraph, resultPath + newFile + '.pickle') getdk2(syntheticGraph, newFile, dkPath, resultPath) # Find distance between the dK-2 distributions dkDistance = tk.get_2k_distance( original2k, resultPath + newFile + '_target.2k') outfile.write( str(dkDistance) + '\tk = ' + str(k) + '\tu = ' + str(u) + '\n') outfile.flush() outfile.write('\n') outfile.close()
def fit_nearestNeighbor_mod(graphSize, graphID, dkPath, original2k, resultPath, k): """ Runs synthetic graph tests for various 'k' and 'u' values and stores them """ if k: outfile = open(resultPath + graphID + '_nnFine_dkDistances.txt', 'w') kList = [k] uList = [] myU = 0.01 while myU < 1: uList.append(myU) myU += 0.01 else: outfile = open(resultPath + graphID + '_nnCoarse_dkDistances.txt', 'w') kList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] uList = [.01, .05, .10, .20, .25,.30, .35, .40, .45, .50, .55, .60, .65, .70, .75,.80, .85, .95] outfile.write('dk-2 Distance\tk\tu\n') for k in kList: for u in uList: print 'Running modified Nearest Neighbor with parameters: n = ', graphSize, ' k = ', k, ' u = ', u newFile = graphID + '_nn_' + str(k) + '_' + str(u) # Create synthetic graph syntheticGraph = sm.nearestNeighbor_mod(graphSize, u, k) # Write pickle, edge list, and 2k distro to file print 'Writing pickle and calculating dK-2...\n' nx.write_gpickle(syntheticGraph, resultPath + newFile + '.pickle') getdk2(syntheticGraph, newFile, dkPath, resultPath) # Find distance between the dK-2 distributions dkDistance = tk.get_2k_distance(original2k, resultPath + newFile + '_target.2k') outfile.write(str(dkDistance) + '\tk = ' + str(k) + '\tu = ' + str(u) + '\n') outfile.flush() outfile.write('\n') outfile.close()