Changeset 681 for mds-and-trees
- Timestamp:
- 08/28/17 18:43:30 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mds-and-trees/tree-genealogy.py
r680 r681 519 519 def compute_depth(self): 520 520 self.props["depth"] = [999999999 for x in range(len(self.tree.children))] 521 visited = [0 for x in range(len(self.tree.children))] 521 522 522 523 nodes_to_visit = [0] 524 visited[0] = 1 523 525 self.props["depth"][0] = 0 526 524 527 while True: 525 for child in self.tree.children[nodes_to_visit[0]]: 526 nodes_to_visit.append(child) 527 self.props["depth"][child] = min([self.props["depth"][d] for d in self.tree.parents[child]])+1 528 current_node = nodes_to_visit[0] 529 for child in self.tree.children[current_node]: 530 if visited[child] == 0: 531 visited[child] = 1 532 nodes_to_visit.append(child) 533 self.props["depth"][child] = self.props["depth"][current_node]+1 528 534 nodes_to_visit = nodes_to_visit[1:] 529 535 if len(nodes_to_visit) == 0:
Note: See TracChangeset
for help on using the changeset viewer.