Changeset 701
 Timestamp:
 09/20/17 15:29:50 (7 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

mdsandtrees/treegenealogy.py
r700 r701 397 397 print("Calculating measures...") 398 398 self.compute_depth() 399 self.compute_maxdepth() 399 400 self.compute_adepth() 400 401 self.compute_children() … … 493 494 # order by maximum depth of the parent guarantees that co child is evaluated before its parent 494 495 visiting_order = [i for i in range(0, len(self.tree.parents))] 495 visiting_order = sorted(visiting_order, key=lambda q: 496 0 if q == 0 else max([self.props["depth"][d] for d in self.tree.parents[q]]))496 visiting_order = sorted(visiting_order, key=lambda q:\ 497 0 if q == 0 else self.props["maxdepth"][q]) 497 498 498 499 start_time = timelib.time() … … 586 587 self.normalize_prop('depth') 587 588 589 def compute_maxdepth(self): 590 self.props["maxdepth"] = [999999999 for x in range(len(self.tree.children))] 591 visited = [0 for x in range(len(self.tree.children))] 592 593 nodes_to_visit = [0] 594 visited[0] = 1 595 self.props["maxdepth"][0] = 0 596 while True: 597 current_node = nodes_to_visit[0] 598 599 for child in self.tree.children[current_node]: 600 if visited[child] == 0: 601 visited[child] = 1 602 nodes_to_visit.append(child) 603 self.props["maxdepth"][child] = self.props["maxdepth"][current_node]+1 604 elif self.props["maxdepth"][child] < self.props["maxdepth"][current_node]+1: 605 self.props["maxdepth"][child] = self.props["maxdepth"][current_node]+1 606 if child not in nodes_to_visit: 607 nodes_to_visit.append(child) 608 609 nodes_to_visit = nodes_to_visit[1:] 610 if len(nodes_to_visit) == 0: 611 break 612 613 self.normalize_prop('maxdepth') 614 588 615 def compute_adepth(self): 589 616 self.props["adepth"] = [0 for x in range(len(self.tree.children))] … … 591 618 # order by maximum depth of the parent guarantees that co child is evaluated before its parent 592 619 visiting_order = [i for i in range(0, len(self.tree.parents))] 593 visiting_order = sorted(visiting_order, key=lambda q: 594 0 if q == 0 else max([self.props["depth"][d] for d in self.tree.parents[q]]))[::1] 620 visiting_order = sorted(visiting_order, key=lambda q: self.props["maxdepth"][q])[::1] 595 621 596 622 for node in visiting_order: … … 672 698 if id not in self.ids: 673 699 return None 700 674 701 return self.ids[id] 675 702
Note: See TracChangeset
for help on using the changeset viewer.