Changeset 623 for mds-and-trees
- Timestamp:
- 10/11/16 17:19:04 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mds-and-trees/tree-genealogy.py
r622 r623 178 178 # ------------------------------------ 179 179 180 def xmin_crowd(x1, x2, y): 181 if BALANCE == "RANDOM": 182 return (x1 if random.randrange(2) == 0 else x2) 183 elif BALANCE == "MIN": 184 x1_closest = 999999 185 x2_closest = 999999 186 for pos in positions: 187 pos = positions[pos] 188 if pos[1] == y: 189 x1_closest = min(x1_closest, abs(x1-pos[0])) 190 x2_closest = min(x2_closest, abs(x2-pos[0])) 191 return (x1 if x1_closest > x2_closest else x2) 192 elif BALANCE == "DENSITY": 193 x1_dist = 0 194 x2_dist = 0 195 ymin = y-10 196 ymax = y+10 197 for pos in positions: 198 pos = positions[pos] 199 if pos[1] > ymin or pos[1] < ymax: 200 dysq = (pos[1]-y)**2 201 dx1 = pos[0]-x1 202 dx2 = pos[0]-x2 203 204 205 x1_dist += math.sqrt(dysq + dx1**2) 206 x2_dist += math.sqrt(dysq + dx2**2) 207 return (x1 if x1_dist > x2_dist else x2) 180 181 def xmin_crowd_random(x1, x2, y): 182 return (x1 if random.randrange(2) == 0 else x2) 183 184 def xmin_crowd_min(x1, x2, y): 185 x1_closest = 999999 186 x2_closest = 999999 187 for pos in positions: 188 pos = positions[pos] 189 if pos[1] == y: 190 x1_closest = min(x1_closest, abs(x1-pos[0])) 191 x2_closest = min(x2_closest, abs(x2-pos[0])) 192 return (x1 if x1_closest > x2_closest else x2) 193 def xmin_crowd_density(x1, x2, y): 194 x1_dist = 0 195 x2_dist = 0 196 ymin = y-10 197 ymax = y+10 198 for pos in positions: 199 pos = positions[pos] 200 if pos[1] > ymin or pos[1] < ymax: 201 dysq = (pos[1]-y)**2 202 dx1 = pos[0]-x1 203 dx2 = pos[0]-x2 204 205 206 x1_dist += math.sqrt(dysq + dx1**2) 207 x2_dist += math.sqrt(dysq + dx2**2) 208 return (x1 if x1_dist > x2_dist else x2) 208 209 209 210 # ------------------------------------ … … 220 221 positions[firstnode] = [0, 0] 221 222 222 #visited = {} 223 #visited[firstnode] = True 224 223 xmin_crowd = None 224 if BALANCE == "RANDOM": 225 xmin_crowd =xmin_crowd_random 226 elif BALANCE == "MIN": 227 xmin_crowd = xmin_crowd_min 228 elif BALANCE == "DENSITY": 229 xmin_crowd = xmin_crowd_density 230 else: 231 raise ValueError("Error, the value of BALANCE does not match any expected value.") 225 232 226 233 nodes_to_visit = [firstnode] 227 234 228 ccc= 0229 timet= ttime.time()235 node_counter = 0 236 start_time = ttime.time() 230 237 231 238 while True: 232 239 233 ccc+= 1234 if ccc%1000 == 0 :235 print(str( ccc) + " " + str(ttime.time()-timet))236 timet= ttime.time()240 node_counter += 1 241 if node_counter%1000 == 0 : 242 print(str(node_counter) + " " + str(ttime.time()-start_time)) 243 start_time = ttime.time() 237 244 238 245 current_node = nodes_to_visit[0] … … 270 277 else: 271 278 positions[c] = [cx, cy] 272 273 274 #if c in inv_nodes:275 # prepos_children_reccurent(c)276 279 277 280 nodes_to_visit = nodes_to_visit[1:]
Note: See TracChangeset
for help on using the changeset viewer.