cfpq_data.graphs.utils.add_reverse_edges#

add_reverse_edges(graph: MultiDiGraph, *, mapping: Dict[Any, Any] | None = None) MultiDiGraph[source]#

Returns a graph with added reverse edges (with suffix '_r' by default).

Parameters:
  • graph (MultiDiGraph) -- Initial graph.

  • mapping (Dict[Any, Any]) -- Edge labels mapping for reverse edges that must be added.

Examples

>>> from cfpq_data import *
>>> g = labeled_cycle_graph(2)
>>> list(g.edges(data=True))
[(0, 1, {'label': 'a'}), (1, 0, {'label': 'a'})]
>>> new_g = add_reverse_edges(g)
>>> list(new_g.edges(data=True))
[(0, 1, {'label': 'a'}), (0, 1, {'label': 'a_r'}), (1, 0, {'label': 'a_r'}), (1, 0, {'label': 'a'})]
Returns:

g -- A graph with added reverse edges.

Return type:

MultiDiGraph