summaryrefslogtreecommitdiffstats
path: root/apgl/main.py
blob: c9d5f1143a3541548a01d9be09368c5ba4a3f689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from apgl.graph import SparseGraph
from apgl.generator.BarabasiAlbertGenerator import BarabasiAlbertGenerator
from apgl.generator.SmallWorldGenerator import SmallWorldGenerator
from apgl.generator.KroneckerGenerator import KroneckerGenerator
from apgl.generator.ConfigModelGenerator import ConfigModelGenerator
from random import sample
from math import log
import numpy as np

vertices = 10000


def pgraph(l, name):
    s = sample(range(len(l)), int(len(l) / 100.))
    with open(name, "w") as fh:
        for i in s:
            friends = [(f, len(l[f])) for f in l[i]]
            line = str(i) + "\t" + "\t".join("\t".join(map(str, a))
                                             for a in friends)
            fh.write(line + "\n")


def ba():
    graph = SparseGraph(vertices)
    generator = BarabasiAlbertGenerator(10, 10)
    graph = generator.generate(graph)
    l, _ = graph.adjacencyList()
    pgraph(l, "b-a.txt")


def sw():
    # slow
    graph = SparseGraph(vertices)
    generator = SmallWorldGenerator(0.3, 50)
    graph = generator.generate(graph)
    l, _ = graph.adjacencyList()
    pgraph(l, "sw.txt")


def kk():
    init = SparseGraph(4)
    init[0, 1] = 1
    init[0, 2] = 1
    init[0, 3] = 1
    for i in range(4):
        init[i, i] = 1
    k = int(log(vertices, 4)) + 1
    generator = KroneckerGenerator(init, k)
    graph = generator.generate()
    l, _ = graph.adjacencyList()
    pgraph(l, "kk.txt")


def cm():
    with open("../facebook_analysis/coachella_degrees.txt") as fh:
        l = [int(line.strip()) for line in fh]
    l = np.array(l)
    n = len(l)
    graph = SparseGraph(n)
    generator = ConfigModelGenerator(l)
    graph = generator.generate(graph)
    l, _ = graph.adjacencyList()
    pgraph(l, "cm.txt")


cm()