summaryrefslogtreecommitdiff
path: root/models/growth/node_deg_over_time.py
diff options
context:
space:
mode:
authorKatolaZ <katolaz@yahoo.it>2015-10-19 16:23:00 +0100
committerKatolaZ <katolaz@yahoo.it>2015-10-19 16:23:00 +0100
commitdf8386f75b0538075d72d52693836bb8878f505b (patch)
tree704c2a0836f8b9fd9f470c12b6ae05637c431468 /models/growth/node_deg_over_time.py
parent363274e79eade464247089c105260bc34940da07 (diff)
First commit of MAMMULT code
Diffstat (limited to 'models/growth/node_deg_over_time.py')
-rw-r--r--models/growth/node_deg_over_time.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/models/growth/node_deg_over_time.py b/models/growth/node_deg_over_time.py
new file mode 100644
index 0000000..a71e86c
--- /dev/null
+++ b/models/growth/node_deg_over_time.py
@@ -0,0 +1,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