def topological_ordering(digr_ori):
 if (not digr_ori.DIRECTED):
  raise Exception(('%s is not a directed graph' % digr))
 digr = deepcopy(digr_ori)
 ordering = []
 n = len(digr.nodes())
 while (n > 0):
  sink_node = find_sink_node(digr)
  ordering.append((sink_node, n))
  digr.del_node(sink_node)
  n -= 1
 return ordering

def topological_ordering ( digr_ori ) : if ( not digr_ori . DIRECTED ) : raise Exception ( ( '%s is not a directed graph' % digr ) ) digr = deepcopy ( digr_ori ) ordering = [ ] n = len ( digr . nodes ( ) ) while ( n > 0 ) : sink_node = find_sink_node ( digr ) ordering . append ( ( sink_node , n ) ) digr . del_node ( sink_node ) n -= 1 return ordering
returns a topological ordering for a acyclic directed graph .