-
Notifications
You must be signed in to change notification settings - Fork 1
/
calculateSpread.py
58 lines (40 loc) · 1.16 KB
/
calculateSpread.py
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
import random
import networkx as nx
import matplotlib.pyplot as plt
import itertools
from itertools import combinations
from itertools import permutations
def power_set(List):
subs = [list(j) for i in range(len(List)) for j in combinations(List, i+1)]
return subs
def init(G):
newG = G
for i in range(1, len(G.edge)):
for j in range(1, len(G.edge[i])):
newG[i][j] = random.uniform(0, 1)
print newG[i][j]
return newG
def getGraph(G):
newG = G
for i in newG.edges_iter():
print i
return newG
# for i in range(1, len(G.edge)):
# for j in range(1, len(G.edge[i])):
# if (G[i][j]]+ random.uniform(0, 1) > 1):
# newG[i][j] = 1
def computeSpread(num_iterations):
for m in range(1, num_iterations):
G_m = getGraph(G)
calculateValueOfCoalitions(G_m)
def calculateValueOfCoalitions(G_m):
subs = power_set(G.nodes())
print subs
# for i in G_m.node():
if __name__ == "__main__":
G = nx.read_gml('karate.gml')
G_Prob = init(G)
print G_Prob
num_iterations=1
# computeSpread(num_iterations)
# calculateValueOfCoalitions(G)