@not_implemented_for('undirected')
def transitive_reduction(G):
 if (not is_directed_acyclic_graph(G)):
  raise nx.NetworkXError('Transitive reduction only uniquely defined on directed acyclic graphs.')
 TR = nx.DiGraph()
 TR.add_nodes_from(G.nodes())
 for u in G:
  u_edges = set(G[u])
  for v in G[u]:
   u_edges -= {y for (x, y) in nx.dfs_edges(G, v)}
  TR.add_edges_from(((u, v) for v in u_edges))
 return TR

@ not_implemented_for ( 'undirected' ) def transitive_reduction ( G ) : if ( not is_directed_acyclic_graph ( G ) ) : raise nx . NetworkXError ( 'Transitive reduction only uniquely defined on directed acyclic graphs.' ) TR = nx . DiGraph ( ) TR . add_nodes_from ( G . nodes ( ) ) for u in G : u_edges = set ( G [ u ] ) for v in G [ u ] : u_edges -= { y for ( x , y ) in nx . dfs_edges ( G , v ) } TR . add_edges_from ( ( ( u , v ) for v in u_edges ) ) return TR
returns transitive reduction of a directed graph the transitive reduction of g = is a graph g- = such that for all v .