graphit/graph_utils/graph_utilities.py
def graph_directional_to_undirectional(graph):
    """
    Convert a directional to an undirectional graph

    Returns a deep copy of the full graph with all directional edges
    duplicated as undirectional ones.
    Undirectional edges share the same data dictionary. In converting
    directional to undirectional edges their data dictionaries will
    be merged.

    .. Note:: dictionary merging may result in undesirable results due
              to data overwrite.

    :param graph: Graph to convert
    :type graph:  :graphit:Graph

    :return:      Directional graph
    :rtype:       :graphit:Graph
    """

    if not graph.directed:
        logging.info('Graph already configured as undirected graph')

    graph_copy = graph.copy(deep=True)
    graph_copy.directed = False
    graph_copy.edges.clear()

    edges = list(graph.edges.keys())
    while len(edges):
        edge = edges.pop()
        attr = copy.deepcopy(graph.edges[edge])

        # Look for reverse edge. Update common attributes.
        reverse_edge = edge[::-1]
        if reverse_edge in edges:
            attr.update(graph.edges[reverse_edge])
            edges.remove(reverse_edge)

        # Add undirectional edge
        graph_copy.add_edge(*edge, **attr)

    return graph_copy

    Convert a directional to an undirectional graph

    Returns a deep copy of the full graph with all directional edges
    duplicated as undirectional ones.
    Undirectional edges share the same data dictionary. In converting
    directional to undirectional edges their data dictionaries will
    be merged.

    .. Note:: dictionary merging may result in undesirable results due
              to data overwrite.

    :param graph: Graph to convert
    :type graph:  :graphit:Graph

    :return:      Directional graph
    :rtype:       :graphit:Graph
    
Convert a directional to an undirectional graph
Returns a deep copy of the full graph with all directional edges
duplicated as undirectional ones.
Undirectional edges share the same data dictionary. In converting
directional to undirectional edges their data dictionaries will
be merged.

: dictionary merging may result in undesirable results due
to data overwrite.
Convert a directional to an undirectional graph Returns a deep copy of the full graph with all directional edges duplicated as undirectional ones . Undirectional edges share the same data dictionary . In converting directional to undirectional edges their data dictionaries will be merged . : dictionary merging may result in undesirable results due to data overwrite .
def graph_directional_to_undirectional(graph):
    if not graph.directed:
        logging.info('Graph already configured as undirected graph')
    graph_copy = graph.copy(deep=True)
    graph_copy.directed = False
    graph_copy.edges.clear()
    edges = list(graph.edges.keys())
    while len(edges):
        edge = edges.pop()
        attr = copy.deepcopy(graph.edges[edge])
        reverse_edge = edge[::-1]
        if reverse_edge in edges:
            attr.update(graph.edges[reverse_edge])
            edges.remove(reverse_edge)
        graph_copy.add_edge(*edge, **attr)
    return graph_copy
def graph_directional_to_undirectional ( graph ) : if not graph . directed : logging . info ( 'Graph already configured as undirected graph' ) graph_copy = graph . copy ( deep = True ) graph_copy . directed = False graph_copy . edges . clear ( ) edges = list ( graph . edges . keys ( ) ) while len ( edges ) : edge = edges . pop ( ) attr = copy . deepcopy ( graph . edges [ edge ] ) reverse_edge = edge [ : : - 1 ] if reverse_edge in edges : attr . update ( graph . edges [ reverse_edge ] ) edges . remove ( reverse_edge ) graph_copy . add_edge ( * edge , ** attr ) return graph_copy
Convert a directional to an undirectional graph
Returns a deep copy of the full graph with all directional edges
duplicated as undirectional ones.
Convert a directional to an undirectional graph Returns a deep copy of the full graph with all directional edges duplicated as undirectional ones .
"""
    Convert a directional to an undirectional graph

    Returns a deep copy of the full graph with all directional edges
    duplicated as undirectional ones.
    Undirectional edges share the same data dictionary. In converting
    directional to undirectional edges their data dictionaries will
    be merged.

    .. Note:: dictionary merging may result in undesirable results due
              to data overwrite.

    :param graph: Graph to convert
    :type graph:  :graphit:Graph

    :return:      Directional graph
    :rtype:       :graphit:Graph
    """ # Look for reverse edge. Update common attributes. # Add undirectional edge
None
:graphit:Graph
graph
Graph to convert
Graph to convert