Revision 05763cfb util/UnitDiskGraph.py
util/UnitDiskGraph.py  

15  15 
return nsmallest(2, numbers)[1] 
16  16  
17  17  
18 
def reconnectGraph(g, distM): 

18 
def reconnectGraph(g, nxG, distM):


19  19 
labels, hist=gt.label_components(g, directed=False) 
20  20 
# While not only a single component 
21  21 
while (not all(e==0 for e in labels.a)): 
...  ...  
35  35 
closest=second_smallest(dp) 
36  36 
near_neigh=[k for k in range(len(dp)) if dp[k]==closest][0] 
37  37 
g.add_edge(g.vertex(i), g.vertex(near_neigh)) 
38 


38  39 
break 
39  40 
else: 
40  41 
#iteratively attach the smallest compo to the closest 
41  42 
#print "Separated Compo" 
42 
#code.interact(local=dict(globals(), **locals())) 

43  43 
d={k:len(v) for k,v in comp2nodes.items()} 
44  44 
minCompoLabel=min(d, key=d.get) 
45  45 
minCompo=comp2nodes[minCompoLabel] 
...  ...  
55  55 
nearest_dist = closest 
56  56 
couple=n,v 
57  57 
g.add_edge(g.vertex(couple[0]), g.vertex(couple[1])) 
58 
#code.interact(local=dict(globals(), **locals())) 

58  59 
#print "Connecting %d%d, which are %.04f distant" % (couple[0], couple[1], nearest_dist) 
59  60  
60  61 
labels, hist=gt.label_components(g, directed=False) 
62 
#at the end reconnect also nxG graph 

63 
for e in g.edges(): 

64 
if not nxG.has_edge(e.source(), e.target()): 

65 
nxG.add_edge(int(str(e.source())), int(str(e.target())), weight=1.0) 

61  66  
62  67  
63  68 
class UnitDiskGraph: 
...  ...  
100  105 
eprops = [self.gtG.ep["weight"]] 
101  106 
self.gtG.add_edge_list(edges, eprops=eprops) 
102  107 
#out=self.gtG.get_out_degrees(self.gtG.get_vertices()) 
103 
reconnectGraph(self.gtG, distM) 

108 
reconnectGraph(self.gtG, self.nxG, distM)


104  109 

105  110  
106  111 
def getGraph(self): 
107 
return self.gtG, self.nxG 

108  
109 


110  
111  
112  
113  
114  
115  
112 
return self.gtG, self.nxG 
Also available in: Unified diff