def differentNumberOfResultsWithAllTypes():
    b = open('diffrent_number_of_results_for_all_types.csv', 'w')
    a = csv.writer(b)
    data = [[
        "Number of results", "EnumIncExcConnected", "EnumConnected",
        "EnumIncExcUnConnected", "EnumUnConnected"
    ]]
    print "Building a random graph with 1000000 nodes and 10000000 edges."
    G1 = snap.GenRndGnm(snap.PUNGraph, 1000000, 10 * 1000000)
    neighbors_dic = InitNeighbors(G1)
    for i in (1, 10, 100, 1000, 10000):
        times = []
        num_of_nodes = 1000000

        prunconnected.k = 5
        time1 = prunconnected.run(G1, i, neighbors_dic, "")[0]
        noprun.k = 5
        time2 = noprun.run(G1, i, neighbors_dic)

        prun2.k = 5
        time3 = prun2.run(G1, i, neighbors_dic, "")

        noprun.k = 5
        time4 = noprun.run(G1, i, neighbors_dic)
        data.append([i, time1, time2, time3, time4])
    a.writerows(data)
    b.close()
    pretty_file.pretty_file(
        "diffrent_number_of_results_for_all_types.csv",
        header=True,
        border=True,
        delimiter=",",
        new_filename="diffrent_number_of_results_for_all_types.txt")
def synthetic():
    b = open('synthetic.csv', 'w')
    a = csv.writer(b)
    data = [["Data", "k=1", "k=5", "k=25", "k=100"]]
    for file_name in ("web-Stanford.txt", "ca-AstroPh.txt",
                      "soc-LiveJournal1.txt", "cit-Patents.txt"):
        file = os.path.dirname(
            os.path.abspath(__file__)) + '/graphs/' + file_name
        G1 = BuildGraphFromFile(file)
        neighbors_dic = InitNeighbors(G1)
        times = []
        times.append(file_name)
        for i in (1, 5, 25, 100):
            prunconnected.k = i
            time = prunconnected.run(G1, 1000, neighbors_dic, "")[0]
            times.append(time)
        data.append(times)
    G1 = BuildGraphFromFiles("./graphs/twitter")
    neighbors_dic = InitNeighbors(G1)
    times = []
    times.append("twitter")
    for i in (1, 5, 25, 100):
        prun2.k = i
        time = prun2.run(G1, 1000, neighbors_dic, "")
        times.append(time)
    data.append(times)
    a.writerows(data)
    b.close()
    pretty_file.pretty_file("synthetic.csv",
                            header=True,
                            border=True,
                            delimiter=",",
                            new_filename="synthetic.txt")
def differentNumberOfResultsEnumInNotConnected():
    b = open('differentNumberOfResultsEnumInNotConnected.csv', 'w')
    a = csv.writer(b)
    data = [["Number of results", "EnumIncNotConnected"]]
    print "Building a random graph with 1000000 nodes and 10000000 edges."
    G1 = snap.GenRndGnm(snap.PUNGraph, 1000000, 10 * 1000000)
    neighbors_dic = InitNeighbors(G1)
    num_of_nodes = 1000000
    noprun.k = 5
    time2 = noprun.run(G1, 10000, neighbors_dic)
    print "%f" % time2
    time2 = 0
    for i in (1, 10, 100, 1000, 10000):
        times = []
        num_of_nodes = 1000000
        prun2.k = 5
        time2 = prun2.run(G1, i, neighbors_dic, "")

        data.append([i, time2])
    a.writerows(data)
    b.close()
    pretty_file.pretty_file(
        "differentNumberOfResultsEnumInNotConnected.csv",
        header=True,
        border=True,
        delimiter=",",
        new_filename="differentNumberOfResultsEnumInNotConnected.txt")
def differentNumberOfNodesEnum():
    b = open('diffrent_number_of_nodes.csv', 'w')
    a = csv.writer(b)
    data = [["Number of nodes", "EnumIncExc"]]
    for i in (1, 10, 100, 1000, 10000):
        times = []
        num_of_nodes = i * 1000
        times.append(num_of_nodes)
        print "Building a random graph with %s nodes and %s edges." % (
            num_of_nodes, 10 * num_of_nodes)
        G1 = snap.GenRndGnm(snap.PUNGraph, num_of_nodes, 10 * num_of_nodes)
        neighbors_dic = InitNeighbors(G1)

        noprun.k = 5
        time = noprun.run(G1, 1000, neighbors_dic)
        times.append(time)
        data.append(times)

    a.writerows(data)
    b.close()
    pretty_file.pretty_file("diffrent_number_of_nodes.csv",
                            header=True,
                            border=True,
                            delimiter=",",
                            new_filename="diffrent_number_of_nodes.txt")
    print "Results can be found in: diffrent_number_of_nodes.csv"
def comparisionWithStateOfArt():
    print "Graph is ready"

    b = open('comarisionWithStateOfArt.csv', 'w')
    a = csv.writer(b)
    data = [['Nodes', 'Edges', "k = 1", "k = 2", "k = 3", "k = 4"]]
    import all
    for n, m in [(1000, 14432), (2000, 28709), (4000, 58063), (8000, 116276),
                 (16000, 231622)]:
        print "Generating a random graph with %s nodes and %s edges" % (n, m)
        #G1 = BuildGraphFromFile('%sn_%sm' % (n,m))
        G1 = snap.GenRndGnm(snap.PUNGraph, n, m)
        neighbors_dic = InitNeighbors(G1)
        times = [n, m]
        for i in (1, 2, 3, 4):
            imp.reload(all)
            all.k = i
            time = all.run(G1, 100000, neighbors_dic, "")
            times.append(time)
        data.append(times)
    a.writerows(data)
    b.close()

    pretty_file.pretty_file("comarisionWithStateOfArt.csv",
                            header=True,
                            border=True,
                            delimiter=",",
                            new_filename="comparisionWithStateOfArt.txt")
def differentNumberOfEdgesEnum():
    b = open('diffrent_number_of_edges.csv', 'w')
    a = csv.writer(b)
    data = [["Number of edges", "Enum"]]
    for i in (1000, 10000, 100000):
        times = []
        num_of_edges = i * 1000
        print "Building a random graph with 1000000 nodes and %s edges." % num_of_edges
        G1 = snap.GenRndGnm(snap.PUNGraph, 1000000, num_of_edges)
        neighbors_dic = InitNeighbors(G1)
        print "Graph is ready"
        noprun.k = 5
        time2 = noprun.run(G1, 10000, neighbors_dic)
        data.append([num_of_edges, time2])
    a.writerows(data)
    b.close()
    pretty_file.pretty_file("diffrent_number_of_edges.csv",
                            header=True,
                            border=True,
                            delimiter=",",
                            new_filename="diffrent_number_of_edges.txt")
def differentNumberOfKEnum():
    import noprun
    #import noprunun2
    b = open('diffrent_number_of_k.csv', 'w')
    a = csv.writer(b)
    data = [["k", "Enum"]]
    print "Building a random graph with 1000000 nodes and 10000000 edges."
    G1 = snap.GenRndGnm(snap.PUNGraph, 1000000, 10 * 1000000)
    neighbors_dic = InitNeighbors(G1)
    for i in (1, 5, 25, 100):
        times = []
        num_of_nodes = 1000000

        noprun.k = i
        time2 = noprun.run(G1, 1000, neighbors_dic)
        data.append(["k = %s" % i, time2])
    a.writerows(data)
    b.close()
    pretty_file.pretty_file("diffrent_number_of_k.csv",
                            header=True,
                            border=True,
                            delimiter=",",
                            new_filename="diffrent_number_of_k.txt")