# Changeset 623

Ignore:
Timestamp:
10/11/16 17:19:04 (5 years ago)
Message:

Some minor changes

File:
1 edited

Unmodified
Added
Removed
• ## mds-and-trees/tree-genealogy.py

 r622 # ------------------------------------ def xmin_crowd(x1, x2, y): if BALANCE == "RANDOM": return (x1 if random.randrange(2) == 0 else x2) elif BALANCE == "MIN": x1_closest = 999999 x2_closest = 999999 for pos in positions: pos = positions[pos] if pos[1] == y: x1_closest = min(x1_closest, abs(x1-pos[0])) x2_closest = min(x2_closest, abs(x2-pos[0])) return (x1 if x1_closest > x2_closest else x2) elif BALANCE == "DENSITY": x1_dist = 0 x2_dist = 0 ymin = y-10 ymax = y+10 for pos in positions: pos = positions[pos] if pos[1] > ymin or pos[1] < ymax: dysq = (pos[1]-y)**2 dx1 = pos[0]-x1 dx2 = pos[0]-x2 x1_dist += math.sqrt(dysq + dx1**2) x2_dist += math.sqrt(dysq + dx2**2) return (x1 if x1_dist > x2_dist else x2) def xmin_crowd_random(x1, x2, y): return (x1 if random.randrange(2) == 0 else x2) def xmin_crowd_min(x1, x2, y): x1_closest = 999999 x2_closest = 999999 for pos in positions: pos = positions[pos] if pos[1] == y: x1_closest = min(x1_closest, abs(x1-pos[0])) x2_closest = min(x2_closest, abs(x2-pos[0])) return (x1 if x1_closest > x2_closest else x2) def xmin_crowd_density(x1, x2, y): x1_dist = 0 x2_dist = 0 ymin = y-10 ymax = y+10 for pos in positions: pos = positions[pos] if pos[1] > ymin or pos[1] < ymax: dysq = (pos[1]-y)**2 dx1 = pos[0]-x1 dx2 = pos[0]-x2 x1_dist += math.sqrt(dysq + dx1**2) x2_dist += math.sqrt(dysq + dx2**2) return (x1 if x1_dist > x2_dist else x2) # ------------------------------------ positions[firstnode] = [0, 0] #visited = {} #visited[firstnode] = True xmin_crowd = None if BALANCE == "RANDOM": xmin_crowd =xmin_crowd_random elif BALANCE == "MIN": xmin_crowd = xmin_crowd_min elif BALANCE == "DENSITY": xmin_crowd = xmin_crowd_density else: raise ValueError("Error, the value of BALANCE does not match any expected value.") nodes_to_visit = [firstnode] ccc = 0 timet = ttime.time() node_counter = 0 start_time = ttime.time() while True: ccc += 1 if ccc%1000 == 0 : print(str(ccc) + " "  + str(ttime.time()-timet)) timet = ttime.time() node_counter += 1 if node_counter%1000 == 0 : print(str(node_counter) + " "  + str(ttime.time()-start_time)) start_time = ttime.time() current_node = nodes_to_visit[0] else: positions[c] = [cx, cy] #if c in inv_nodes: #    prepos_children_reccurent(c) nodes_to_visit = nodes_to_visit[1:]
Note: See TracChangeset for help on using the changeset viewer.