Revision 05763cfb simulator.py
simulator.py  

14  14 
import util.MyUtil as myu 
15  15 
from time import sleep 
16  16 
import time 
17 
import matplotlib.pyplot as plt 

18 
plt.ion() 

19  
20  
21  17  
22  18  
23  19 
def f(params): 
...  ...  
27  23 
params['gtG'] = G 
28  24 
params['nxG'] = nxG 
29  25 
ws = G.edge_properties["weight"] 
30 
vp, ep = gt.betweenness(G, norm=False, weight=ws)


26 
vp, ep = gt.betweenness(G, norm=True, weight=ws)


31  27 
btwd = {i: vp.a[i] for i in range(len(vp.a))} 
32  28 
params['btw'] = btwd 
33  29 
kcore = gt.kcore_decomposition(G) 
...  ...  
60  56 
for i in range(NN): 
61  57 
f = open(outPath+"/stats"+'%08d' % i+".csv", 'a+') 
62  58 
self.statsFiles[i] = f 
63 
f.write("Time,BC,DEG,KCORE\n") 

59 
f.write("Time,BC,DEG,KCORE,X,Y\n")


64  60  
65  61 
def batch_tasks(self, sched, mobi, num_workers=5): 
66  62 
# prepare next num_workers tasks 
...  ...  
97  93  
98  94 
# Log results to disk 
99  95 
for res in results: 
100 
#code.interact(local=dict(globals(), **locals())) 

101  96 
self.logRes(res, stats=['btw', 'deg', 'kcore']) 
102  97  
103  98 
if self.gui and self.num_workers == 1: 
99 
#code.interact(local=dict(globals(), **locals())) 

104  100 
res = results[0] 
105  101 
self.draw(res['nxG'], res['pos'], res['btw']) 
102 
else: 

103 
self.draw(res['nxG'], res['pos'], res['btw'], saveFig=True, 

104 
path=self.OP+"/topos/topo"+str(res['tag'])+".pdf") 

106  105  
107  106 
# Main Loop End Here 
108  107 
for f in self.statsFiles: 
...  ...  
115  114 
btw = res['btw'][n] 
116  115 
deg = res['deg'][n] 
117  116 
kcore = res['kcore'][n] 
117 
x, y = res['pos'][n] 

118  118 
self.statsFiles[n].write( 
119 
",".join(map(str, [tag, btw, deg, kcore]))+"\n") 

119 
",".join(map(str, [tag, btw, deg, kcore, x, y]))+"\n")


120  120  
121 
def draw(self, G, pos, measures=None): 

121 
def draw(self, G, pos, measures=None, saveFig=False, path=None):


122  122 
xmax = self.params['max_x'] 
123  123 
ymax = self.params['max_y'] 
124 
myu.draw(G, pos, xmax, ymax, measures) 

124 
myu.draw(G, pos, xmax, ymax, measures, saveFig=saveFig, path=path) 
Also available in: Unified diff