summaryrefslogtreecommitdiff
path: root/models/growth/node_deg_over_time.py
blob: a71e86cde316515b4bee595fb6cd1ba26f05720f (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
####
##
## Get an edgelist, a file pof arrival times and a node ID and return
## the degree of that node as a function of time (we suppose that IDs
## are sequential)
##
##

import sys


if len(sys.argv) < 4:
    print "Usage: %s <netfile> <timefile> <nodeid1> [<nodeid2> <nodeid3>...]" % sys.argv[0]
    sys.exit(1)

node_id = int(sys.argv[3])

lines = open(sys.argv[2], "r").readlines()

arrival_time = {}

#### WARNING!!!! THIS WORKS ONLY FOR M0=3
arrival_time[0] = 0
arrival_time[1] = 1
arrival_time[2] = 2


neigh_by_time = {}

max_t = -1

for l in lines:
    if l[0] == "#":
        continue
    t,node = [int(x) for x in l.strip(" \n").split(" ")]
    arrival_time[node] = t
    if t > max_t :
	max_t = t


lines = open(sys.argv[1], "r").readlines()


for l in lines:
    if l[0] == "#":
        continue
    n1,n2 = [int(x) for x in l.strip(" \n").split(" ")]


    if neigh_by_time.has_key(n1):
        neigh_by_time[n1].append(arrival_time[n2])
    else:
        neigh_by_time[n1] = [arrival_time[n2]]
        
    if neigh_by_time.has_key(n2):
        neigh_by_time[n2].append(arrival_time[n1])
    else:
        neigh_by_time[n2] = [arrival_time[n1]]



#print neigh_by_time[node_id]


for node_id in sys.argv[3:]:
    node_id = int(node_id)
    neigh_by_time[node_id].sort()
    last_time = neigh_by_time[node_id][0]
#### changed here
    k = 1
    print "#### ", node_id
    for t in neigh_by_time[node_id][1:]:
        if t != last_time:
            if last_time < arrival_time[node_id]:
                print arrival_time[node_id], k
            else:
                print last_time, k
            last_time = t
        k += 1
    print max_t, k-1
    print 
    print