Ejemplo n.º 1
0
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_randomWalk_mod(graphSize, graphID, dkPath, original2k, resultPath,
                       interval):
    """
    Runs synthetic graph tests for various 'qe' and 'qv' values
    If an interval was specified for fine grained sampling, please
    note that the interal is closed bounds, that is [x, y] so qe_end and qv_end
    will terminate after sampling the end values specified, not before.
    """
    if not interval:
        outfile = open(resultPath + graphID + '_rwCoarse_dkDistances.txt', 'w')
        qe = 0.1
        qe_end = 0.9
        step = 0.1

    else:
        outfile = open(resultPath + graphID + '_rwFine_dkDistances.txt', 'w')
        qe = interval[0] * 100
        qe_end = interval[1] * 100
        step = 1

    outfile.write('dk-2 Distance\tqe\tqv\n')

    while qe <= qe_end:
        if not interval:
            qv = 0.1
            qv_end = 0.9
        else:
            qv = interval[2] * 100
            qv_end = interval[3] * 100

        while qv <= qv_end:
            qeFloat = float(qe) / 100 if not interval else qe
            qvFloat = float(qv) / 100 if not interval else qv
            print 'Running modified Random Walk (coarse) with parameters: n = ', graphSize, ' qe = ', qeFloat, ' qv = ', qvFloat

            newFile = graphID + '_rwCoarse_' + str(qeFloat) + '_' + str(
                qvFloat)

            # Create synthetic graph
            syntheticGraph = sm.randomWalk_mod(graphSize, qeFloat, qvFloat)

            # Write pickle, edge list, and 2k distro to file
            print 'Calculating dK-2...\n'
            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) + '\tqe = ' + str(qeFloat) + '\tqv = ' +
                str(qvFloat) + '\n')
            outfile.flush()

            qv += step

        qe += step

        outfile.write('\n')

    outfile.close()
Ejemplo n.º 3
0
def fit_randomWalk_mod(graphSize, graphID, dkPath, original2k, resultPath, interval):
    """
    Runs synthetic graph tests for various 'qe' and 'qv' values
    If an interval was specified for fine grained sampling, please
    note that the interal is closed bounds, that is [x, y] so qe_end and qv_end
    will terminate after sampling the end values specified, not before.
    """
    if not interval:
        outfile = open(resultPath + graphID + '_rwCoarse_dkDistances.txt', 'w')
        qe = 0.1
        qe_end = 0.9
        step = 0.1

    else:
        outfile = open(resultPath + graphID + '_rwFine_dkDistances.txt', 'w')
        qe = interval[0] * 100
        qe_end = interval[1] * 100
        step = 1

    outfile.write('dk-2 Distance\tqe\tqv\n')

    while qe <= qe_end:
        if not interval:
            qv = 0.1
            qv_end = 0.9
        else:
            qv = interval[2] * 100
            qv_end = interval[3] * 100

        while qv <= qv_end:
            qeFloat = float(qe) / 100 if not interval else qe
            qvFloat = float(qv) / 100 if not interval else qv
            print 'Running modified Random Walk (coarse) with parameters: n = ', graphSize, ' qe = ', qeFloat, ' qv = ', qvFloat

            newFile = graphID + '_rwCoarse_' + str(qeFloat) + '_' + str(qvFloat)
            
            # Create synthetic graph
            syntheticGraph = sm.randomWalk_mod(graphSize, qeFloat, qvFloat)
            
            # 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) + '\tqe = ' + str(qeFloat) + '\tqv = ' + str(qvFloat) + '\n')
            outfile.flush()

            qv += step

        qe += step

        outfile.write('\n')

    outfile.close()