コード例 #1
0
def change_edge_src(graph: gr.OrderedDiGraph,
                    node_a: Union[nd.Node, gr.OrderedMultiDiConnectorGraph],
                    node_b: Union[nd.Node, gr.OrderedMultiDiConnectorGraph]):
    """ Changes the sources of edges from node A to node B.

        The function finds all edges in the graph that have node A as their
        source. It then creates a new edge for each one found, using the same
        destination nodes and data, but node B as the source. Afterwards, it
        deletes the edges
        found and inserts the new ones into the graph.

        :param graph: The graph upon which the edge transformations will be
                      applied.
        :param node_a: The original source of the edges to be transformed.
        :param node_b: The new source of the edges to be transformed.
    """

    # Create new outgoing edges from node B, by copying the outgoing edges from
    # node A and setting their source to node B.
    edges = list(graph.out_edges(node_a))
    for e in edges:
        # Delete the outgoing edges from node A from the graph.
        graph.remove_edge(e)
        # Insert the new edges to the graph.
        if isinstance(e, gr.MultiConnectorEdge):
            graph.add_edge(node_b, e.src_conn, e.dst, e.dst_conn, e.data)
        else:
            graph.add_edge(node_b, e.dst, e.data)
コード例 #2
0
ファイル: merge_arrays.py プロジェクト: am-ivanov/dace
    def expressions(cls):
        # Matching
        #   o  o
        #   |  |
        # /======\

        g = OrderedDiGraph()
        g.add_node(cls.array1)
        g.add_node(cls.array2)
        g.add_node(cls.map_entry)
        g.add_edge(cls.array1, cls.map_entry, None)
        g.add_edge(cls.array2, cls.map_entry, None)
        return [g]
コード例 #3
0
ファイル: merge_arrays.py プロジェクト: am-ivanov/dace
    def expressions(cls):
        # Matching
        # \======/
        #   |  |
        #   o  o

        g = OrderedDiGraph()
        g.add_node(cls.array1)
        g.add_node(cls.array2)
        g.add_node(cls.map_exit)
        g.add_edge(cls.map_exit, cls.array1, None)
        g.add_edge(cls.map_exit, cls.array2, None)
        return [g]