paleo/graph.py
def nested_list_till_joints(self, history, frontiers):
        """Returns current history and encountered joint"""
        if len(frontiers) == 0:
            return history, []

        # If all frontiers are joints, stop DFS.
        # The returned path does not include the joints.
        all_joints = True
        for node in frontiers:
            all_joints = all_joints and (node in self.joints)
        if all_joints:
            return history, frontiers

        if len(frontiers) == 1:
            # Simply chain the layer and continue
            history.append(node)
            for x in node.outbounds:
                assert self.indegrees[x] > 0
                self.indegrees[x] -= 1
            frontiers = node.outbounds
            return self.nested_list_till_joints(history, frontiers)
        else:
            # When the frontier has more than one nodes, we explore from each
            # frontier individually until they reach a common joint.
            supernode = []
            merged_joints = set()
            for node in frontiers:
                # The search will stop at joints.
                sub_list, joints = self.nested_list_till_joints([], [node])
                if len(sub_list) > 0:
                    supernode.append(sub_list)
                for joint in joints:
                    if self.indegrees[joint] == 0:
                        merged_joints.add(joint)
            if len(supernode) > 0:
                history.append(tuple(supernode))

            # Reached joints becomes the new frontiers.
            for joint in merged_joints:
                self.joints.remove(joint)
            frontiers = list(merged_joints)
            return self.nested_list_till_joints(history, frontiers)
Returns current history and encountered joint
Returns current history and encountered joint
Returns current history and encountered joint
def nested_list_till_joints(self, history, frontiers):
        if len(frontiers) == 0:
            return history, []
        all_joints = True
        for node in frontiers:
            all_joints = all_joints and (node in self.joints)
        if all_joints:
            return history, frontiers
        if len(frontiers) == 1:
            history.append(node)
            for x in node.outbounds:
                assert self.indegrees[x] > 0
                self.indegrees[x] -= 1
            frontiers = node.outbounds
            return self.nested_list_till_joints(history, frontiers)
        else:
            supernode = []
            merged_joints = set()
            for node in frontiers:
                sub_list, joints = self.nested_list_till_joints([], [node])
                if len(sub_list) > 0:
                    supernode.append(sub_list)
                for joint in joints:
                    if self.indegrees[joint] == 0:
                        merged_joints.add(joint)
            if len(supernode) > 0:
                history.append(tuple(supernode))
            for joint in merged_joints:
                self.joints.remove(joint)
            frontiers = list(merged_joints)
            return self.nested_list_till_joints(history, frontiers)
def nested_list_till_joints ( self , history , frontiers ) : if len ( frontiers ) == 0 : return history , [ ] all_joints = True for node in frontiers : all_joints = all_joints and ( node in self . joints ) if all_joints : return history , frontiers if len ( frontiers ) == 1 : history . append ( node ) for x in node . outbounds : assert self . indegrees [ x ] > 0 self . indegrees [ x ] -= 1 frontiers = node . outbounds return self . nested_list_till_joints ( history , frontiers ) else : supernode = [ ] merged_joints = set ( ) for node in frontiers : sub_list , joints = self . nested_list_till_joints ( [ ] , [ node ] ) if len ( sub_list ) > 0 : supernode . append ( sub_list ) for joint in joints : if self . indegrees [ joint ] == 0 : merged_joints . add ( joint ) if len ( supernode ) > 0 : history . append ( tuple ( supernode ) ) for joint in merged_joints : self . joints . remove ( joint ) frontiers = list ( merged_joints ) return self . nested_list_till_joints ( history , frontiers )
Returns current history and encountered joint
Returns current history and encountered joint
"""Returns current history and encountered joint""" # If all frontiers are joints, stop DFS. # The returned path does not include the joints. # Simply chain the layer and continue # When the frontier has more than one nodes, we explore from each # frontier individually until they reach a common joint. # The search will stop at joints. # Reached joints becomes the new frontiers.
self
history
frontiers