(objects, merged_morphisms)
return component_morphisms
Given a container of morphisms, returns a list of connected
        components formed by these morphisms.  A connected component
        is represented by a diagram consisting of the corresponding
        morphisms.
Given a container of morphisms, returns a list of connected
        components formed by these morphisms.  A connected component
        is represented by a diagram consisting of the corresponding
        morphisms.
Given a container of morphisms returns a list of connected components formed by these morphisms . A connected component is represented by a diagram consisting of the corresponding morphisms .
def _get_connected_components(objects, merged_morphisms):
        """
        Given a container of morphisms, returns a list of connected
        components formed by these morphisms.  A connected component
        is represented by a diagram consisting of the corresponding
        morphisms.
        """
        component_index = {}
        for o in objects:
            component_index[o] = None

        # Get the underlying undirected graph of the diagram.
        adjlist = DiagramGrid._get_undirected_graph(objects, merged_morphisms)

        def traverse_component(object, current_index):
            """
            Does a depth-first search traversal of the component
            containing ``object``.
            """
            component_index[object] = current_index
            for o in adjlist[object]:
                if component_index[o] is None:
                    traverse_component(o, current_index)

        # Traverse all components.
        current_index = 0
        for o in adjlist:
            if component_index[o] is None:
                traverse_component(o, current_index)
                current_index += 1

        # List the objects of the components.
        component_objects = [[] for i in xrange(current_index)]
        for o, idx in component_index.items():
            component_objects[idx].append(o)

        # Finally, list the morphisms belonging to each component.
        #
        # Note: If some objects are isolated, they will not get any
        # morphisms at this stage, and since the layout algorithm
        # relies, we are essentially going to lose this object.
        # Therefore, check if there are isolated objects and, for each
        # of them, provide the trivial identity morphism.  It will get
        # discarded later, but the object will be there.

        component_morphisms = []
        for component in component_objects:
            current_morphisms = {}
            for m in merged_morphisms:
                if (m.domain in component) and (m.codomain in component):
                    current_morphisms[m] = merged_morphisms[m]

            if len(component) == 1:
                # Let's add an identity morphism, for the sake of
                # surely having morphisms in this component.
                current_morphisms[IdentityMorphism(component[0])] = FiniteSet()

            component_morphisms.append(Diagram(current_morphisms))

        return component_morphisms
def _get_connected_components ( objects , merged_morphisms ) : component_index = { } for o in objects : component_index [ o ] = None # Get the underlying undirected graph of the diagram. adjlist = DiagramGrid . _get_undirected_graph ( objects , merged_morphisms ) def traverse_component ( object , current_index ) : """
            Does a depth-first search traversal of the component
            containing ``object``.
            """ component_index [ object ] = current_index for o in adjlist [ object ] : if component_index [ o ] is None : traverse_component ( o , current_index ) # Traverse all components. current_index = 0 for o in adjlist : if component_index [ o ] is None : traverse_component ( o , current_index ) current_index += 1 # List the objects of the components. component_objects = [ [ ] for i in xrange ( current_index ) ] for o , idx in component_index . items ( ) : component_objects [ idx ] . append ( o ) # Finally, list the morphisms belonging to each component. # # Note: If some objects are isolated, they will not get any # morphisms at this stage, and since the layout algorithm # relies, we are essentially going to lose this object. # Therefore, check if there are isolated objects and, for each # of them, provide the trivial identity morphism.  It will get # discarded later, but the object will be there. component_morphisms = [ ] for component in component_objects : current_morphisms = { } for m in merged_morphisms : if ( m . domain in component ) and ( m . codomain in component ) : current_morphisms [ m ] = merged_morphisms [ m ] if len ( component ) == 1 : # Let's add an identity morphism, for the sake of # surely having morphisms in this component. current_morphisms [ IdentityMorphism ( component [ 0 ] ) ] = FiniteSet ( ) component_morphisms . append ( Diagram ( current_morphisms ) ) return component_morphisms