List of commits:
Subject Hash Author Date (UTC)
Cleanup whitespaces, disabe target_list mode 9c90bce538a4eec167340c46004203d694879022 Vasilis Ververis 2017-02-24 01:22:56
Cleanup, add more config options 7f0a631d299eb350cc1d9f48371d145d1e3823f3 Vasilis Ververis 2017-02-24 00:57:28
Set fileformat to unix 4eed6d1916a812e143e1096e963c3b233129e8d7 Vasilis Ververis 2017-02-23 16:45:16
Fix redis hostname 57276c0a5aa259092b81a09b8c81f134ac58c959 Vasilis Ververis 2017-02-23 15:33:02
Add test dataset e76fd091a7c646c07d40dd4e037fed743edffacf Vasilis Ververis 2017-02-23 15:22:03
Add 2012 dataset a53b501c7751f5dcf05e4f495b2d766cd6fd4727 Vasilis Ververis 2017-02-23 15:06:50
Set redis config, cleanup remove spaces and tabs a53dadd1a517ad483b3bcfaf8f1a8dbf06986dba Vasilis Ververis 2017-02-23 14:09:53
added the backend code 7cd35621d7adef15ecc88a7ad61d2709530f8a52 lizzzi111 2016-05-12 21:29:37
Commit 9c90bce538a4eec167340c46004203d694879022 - Cleanup whitespaces, disabe target_list mode
Author: Vasilis Ververis
Author date (UTC): 2017-02-24 01:22
Committer name: Vasilis Ververis
Committer date (UTC): 2017-02-24 01:22
Parent(s): 7f0a631d299eb350cc1d9f48371d145d1e3823f3
Signing key:
Tree: e718327df1e112954cd4c909d21656da08e0114e
File Lines added Lines deleted
config.py 1 1
percolation.py 36 36
File config.py changed (mode: 100644) (index ab286ad..4cad512)
... ... percolation_modes = {'failure': percolation.failure,
120 120 #'russian_shutoff': percolation.russian #'russian_shutoff': percolation.russian
121 121 } }
122 122
123 advanced_percolation_modes = {'target_list': percolation.target_list,
123 advanced_percolation_modes = {#'target_list': percolation.target_list,
124 124 'hybrid_mode': percolation.hybrid_mode 'hybrid_mode': percolation.hybrid_mode
125 125 } }
126 126
File percolation.py changed (mode: 100644) (index 7038340..a32ff93)
... ... import visualization
12 12 ### functions used by all percolation modes ### ### functions used by all percolation modes ###
13 13 ############################################### ###############################################
14 14 def percolation(percolated_graph,intact_graph): def percolation(percolated_graph,intact_graph):
15 return 100.0*(1.0-float(percolated_graph.num_vertices())/float(intact_graph.num_vertices()))
15 return 100.0*(1.0-float(percolated_graph.num_vertices())/float(intact_graph.num_vertices()))
16 16
17 17 def print_info(flc, glc): def print_info(flc, glc):
18 18 print 'filtered graph - vertices: '+str(flc.num_vertices())+' / edges: '+str(flc.num_edges()) print 'filtered graph - vertices: '+str(flc.num_vertices())+' / edges: '+str(flc.num_edges())
 
... ... def print_info(flc, glc):
28 28 ####### percolation modes ####### ####### percolation modes #######
29 29 ################################# #################################
30 30
31 # These percolation modes take as input the mode name and n - a dictionary of
31 # These percolation modes take as input the mode name and n - a dictionary of
32 32 # numbers of nodes to take out (as keys) and corresponding percentages. # numbers of nodes to take out (as keys) and corresponding percentages.
33 33 # They return a dictionary of percentage keys and percolation values. # They return a dictionary of percentage keys and percolation values.
34 34 # Advanced percolation modes nest this dictionary within a dictionary of groups. # Advanced percolation modes nest this dictionary within a dictionary of groups.
 
... ... def failure(self, mode_name, n):
47 47 for v in np.random.choice(list(self.glc.vertices()),size=max(n.keys()),replace=False): for v in np.random.choice(list(self.glc.vertices()),size=max(n.keys()),replace=False):
48 48 self.exclusion_map[self.g.vertex(v)] = 0 self.exclusion_map[self.g.vertex(v)] = 0
49 49 counter += 1 counter += 1
50 if counter in n.keys():
50 if counter in n.keys():
51 51 print counter,'nodes removed' print counter,'nodes removed'
52 52 # graph without the excluded vertices (i.e. those that have value 0 in the exclusion map) # graph without the excluded vertices (i.e. those that have value 0 in the exclusion map)
53 f = gt.GraphView(self.g, vfilt = self.exclusion_map)
53 f = gt.GraphView(self.g, vfilt = self.exclusion_map)
54 54 # largest component of graph f # largest component of graph f
55 flc = gt.GraphView(self.g, vfilt = gt.label_largest_component(f))
55 flc = gt.GraphView(self.g, vfilt = gt.label_largest_component(f))
56 56 print_info(flc,self.glc) print_info(flc,self.glc)
57 57 results[n[counter]] = percolation(flc,self.glc) results[n[counter]] = percolation(flc,self.glc)
58 58 # visualize deterioration # visualize deterioration
 
... ... def random_walk(self, mode_name, n):
71 71 alternate_list = list(self.label_map.a) alternate_list = list(self.label_map.a)
72 72 np.random.shuffle(alternate_list) np.random.shuffle(alternate_list)
73 73 results = rw(self,start,n,alternate_list,mode_name) results = rw(self,start,n,alternate_list,mode_name)
74
74
75 75 #return dict(zip(percentages,percolations)) #return dict(zip(percentages,percolations))
76 76 return results return results
77
77
78 78 ##################################################################### #####################################################################
79 79
80 80 ################################# #################################
 
... ... def target_list(self, mode_name, n):
96 96 for score in all_scores: for score in all_scores:
97 97 #get nodes with highest value of score #get nodes with highest value of score
98 98 nodes_max[score] = self.redis.zrange(self.score_prefix+score, -max(n.keys()), -1, withscores=False, score_cast_func=float).reverse() nodes_max[score] = self.redis.zrange(self.score_prefix+score, -max(n.keys()), -1, withscores=False, score_cast_func=float).reverse()
99
99
100 100 #loop through all metrics and scores #loop through all metrics and scores
101 101 for metric in all_metrics+all_scores: for metric in all_metrics+all_scores:
102 102 print 'Taking out top nodes for metric',metric print 'Taking out top nodes for metric',metric
103
103
104 104 # initialise variables and exclusion map # initialise variables and exclusion map
105 105 counter = 0 counter = 0
106 106 self.exclusion_map.a = 1 self.exclusion_map.a = 1
 
... ... def target_list(self, mode_name, n):
110 110 vertex = gt.find_vertex(self.g,self.label_map,node)[0] vertex = gt.find_vertex(self.g,self.label_map,node)[0]
111 111 self.exclusion_map[vertex] = 0 self.exclusion_map[vertex] = 0
112 112 counter += 1 counter += 1
113 if counter in n.keys():
113 if counter in n.keys():
114 114 print counter,'nodes removed' print counter,'nodes removed'
115 115 # graph without the excluded vertices (i.e. those that have value 0 in the exclusion map) # graph without the excluded vertices (i.e. those that have value 0 in the exclusion map)
116 f = gt.GraphView(self.g, vfilt = self.exclusion_map)
116 f = gt.GraphView(self.g, vfilt = self.exclusion_map)
117 117 # largest component of graph f # largest component of graph f
118 flc = gt.GraphView(self.g, vfilt = gt.label_largest_component(f))
118 flc = gt.GraphView(self.g, vfilt = gt.label_largest_component(f))
119 119 print_info(flc,self.glc) print_info(flc,self.glc)
120 120 results[metric][n[counter]] = percolation(flc,self.glc) results[metric][n[counter]] = percolation(flc,self.glc)
121 121 # visualize deterioration # visualize deterioration
 
... ... def hybrid_mode(self, mode_name, n):
144 144 #get nodes with highest value of score #get nodes with highest value of score
145 145 temp_list = self.redis.zrange(self.score_prefix+score, 0, -1, withscores=False, score_cast_func=float) temp_list = self.redis.zrange(self.score_prefix+score, 0, -1, withscores=False, score_cast_func=float)
146 146 alternate_lists[score] = [node for node in reversed(temp_list)] alternate_lists[score] = [node for node in reversed(temp_list)]
147
147
148 148 #loop through all metrics and scores #loop through all metrics and scores
149 149 for metric in all_metrics+all_scores: for metric in all_metrics+all_scores:
150 150 print 'Starting from node with highest value of metric',metric print 'Starting from node with highest value of metric',metric
151 151 #initialise exclusion vertex property map #initialise exclusion vertex property map
152 self.exclusion_map.a = 1
153
152 self.exclusion_map.a = 1
153
154 154 #first vertex for random walk #first vertex for random walk
155 155 start = gt.find_vertex(self.g,self.label_map,alternate_lists[metric][0])[0] start = gt.find_vertex(self.g,self.label_map,alternate_lists[metric][0])[0]
156
156
157 157 #do random walk #do random walk
158 158 results[metric] = rw(self,start,n,alternate_lists[metric],mode_name+'_'+metric) results[metric] = rw(self,start,n,alternate_lists[metric],mode_name+'_'+metric)
159 159
 
... ... def russian(self, mode_name, n):
172 172 print 'Shutting off node',int(v),'because it\'s Russian!' print 'Shutting off node',int(v),'because it\'s Russian!'
173 173 self.exclusion_map[v] = 1 self.exclusion_map[v] = 1
174 174 counter += 1 counter += 1
175 # if counter in n.keys():
175 # if counter in n.keys():
176 176 # print counter,'nodes removed' # print counter,'nodes removed'
177 177 # graph without the excluded vertices (i.e. those that have value 0 in the exclusion map) # graph without the excluded vertices (i.e. those that have value 0 in the exclusion map)
178 # f = gt.GraphView(self.g, vfilt = self.exclusion_map)
178 # f = gt.GraphView(self.g, vfilt = self.exclusion_map)
179 179 # largest component of graph f # largest component of graph f
180 # flc = gt.GraphView(self.g, vfilt = gt.label_largest_component(f))
180 # flc = gt.GraphView(self.g, vfilt = gt.label_largest_component(f))
181 181 # print_info(flc,self.glc) # print_info(flc,self.glc)
182 182 # results[n[counter]] = percolation(flc,self.glc) # results[n[counter]] = percolation(flc,self.glc)
183 183 # visualize deterioration # visualize deterioration
184 184 # visualization.draw_deterioration(self,self.sfdp,mode_name+'_'+metric+'_'+str(int(n[counter]))+'_pct') # visualization.draw_deterioration(self,self.sfdp,mode_name+'_'+metric+'_'+str(int(n[counter]))+'_pct')
185
186 f = gt.GraphView(self.g, vfilt = self.exclusion_map)
187 flc = gt.GraphView(self.g, vfilt = gt.label_largest_component(f))
185
186 f = gt.GraphView(self.g, vfilt = self.exclusion_map)
187 flc = gt.GraphView(self.g, vfilt = gt.label_largest_component(f))
188 188 #results[max(n.values())] = percolation(flc,self.g) #results[max(n.values())] = percolation(flc,self.g)
189 189 # visualize deterioration # visualize deterioration
190 190 print 'Creating visualization #1 of the deterioration.' print 'Creating visualization #1 of the deterioration.'
 
... ... def russian(self, mode_name, n):
198 198 ############## Random Walk for the RW deletion modes ################ ############## Random Walk for the RW deletion modes ################
199 199 ##################################################################### #####################################################################
200 200
201 # takes as input a start vertex, the number of vertices to take out
201 # takes as input a start vertex, the number of vertices to take out
202 202 # and an alternate list of vertices if the random walk reaches a dead end # and an alternate list of vertices if the random walk reaches a dead end
203 203
204 204 def rw(self, vertex, n, alternate_list, mode_name): def rw(self, vertex, n, alternate_list, mode_name):
205 205 # initialise # initialise
206 results = {}
206 results = {}
207 207
208 208 self.exclusion_map[vertex] = 0 #take out start vertex self.exclusion_map[vertex] = 0 #take out start vertex
209 209 # initialise graph filters # initialise graph filters
210 210 # graph without the excluded vertices (i.e. those that have value 0 in the exclusion map) # graph without the excluded vertices (i.e. those that have value 0 in the exclusion map)
211 f = gt.GraphView(self.g, vfilt = self.exclusion_map)
211 f = gt.GraphView(self.g, vfilt = self.exclusion_map)
212 212 # largest component of graph f # largest component of graph f
213 flc = gt.GraphView(self.g, vfilt = gt.label_largest_component(f))
213 flc = gt.GraphView(self.g, vfilt = gt.label_largest_component(f))
214 214 if 1 in n.keys(): if 1 in n.keys():
215 215 print '1 node removed' print '1 node removed'
216 216 print_info(flc,self.glc) print_info(flc,self.glc)
217 217 results[n[1]] = percolation(flc,self.glc) results[n[1]] = percolation(flc,self.glc)
218 218 # visualize deterioration # visualize deterioration
219 219 # visualization.draw_deterioration(self,self.sfdp,mode_name+'_'+str(int(n[1]))+'_pct') # visualization.draw_deterioration(self,self.sfdp,mode_name+'_'+str(int(n[1]))+'_pct')
220
220
221 221 for i in range(max(n.keys())-1): for i in range(max(n.keys())-1):
222 222 neighbours = list(vertex.all_neighbours()) neighbours = list(vertex.all_neighbours())
223 223 flag = 0 #decision flag flag = 0 #decision flag
 
... ... def rw(self, vertex, n, alternate_list, mode_name):
230 230 vertex = neighbour vertex = neighbour
231 231 flag = 1 flag = 1
232 232 break break
233
234 # to be executed if no neighbours exist - choose the next node out of an alternative list
233
234 # to be executed if no neighbours exist - choose the next node out of an alternative list
235 235 if flag == 0: if flag == 0:
236 236 # create a list of already used list members # create a list of already used list members
237 used_list = []
237 used_list = []
238 238 for node in alternate_list: for node in alternate_list:
239 239 vertex = gt.find_vertex(self.g,self.label_map,node)[0] vertex = gt.find_vertex(self.g,self.label_map,node)[0]
240 240 used_list.append(node) used_list.append(node)
241 241 if self.exclusion_map[vertex] != 0: if self.exclusion_map[vertex] != 0:
242 242 break break
243 243 if len(used_list) > 0: if len(used_list) > 0:
244 for used_node in used_list:
245 # remove used members from alternate list. This reduces calculation time in next iteration
246 alternate_list.remove(used_node)
247
244 for used_node in used_list:
245 # remove used members from alternate list. This reduces calculation time in next iteration
246 alternate_list.remove(used_node)
247
248 248 self.exclusion_map[vertex] = 0 #take out vertex self.exclusion_map[vertex] = 0 #take out vertex
249 249 f = gt.GraphView(self.g, vfilt = self.exclusion_map) #update graph (filtered) f = gt.GraphView(self.g, vfilt = self.exclusion_map) #update graph (filtered)
250 250 if i+2 in n.keys(): if i+2 in n.keys():
 
... ... def rw(self, vertex, n, alternate_list, mode_name):
254 254 results[n[i+2]] = percolation(flc,self.glc) results[n[i+2]] = percolation(flc,self.glc)
255 255 # visualize deterioration # visualize deterioration
256 256 # visualization.draw_deterioration(self,self.sfdp,mode_name+'_'+str(int(n[i+2]))+'_pct') # visualization.draw_deterioration(self,self.sfdp,mode_name+'_'+str(int(n[i+2]))+'_pct')
257
258 return results
257
258 return results
259 259
260 260 ############################## ##############################
261 261 ############################## ##############################
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/coria/coria-backend

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/coria/coria-backend

Clone this repository using git:
git clone git://git.rocketgit.com/user/coria/coria-backend

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main