@not_implemented_for('undirected')
def antichains(G):
 TC = nx.transitive_closure(G)
 antichains_stacks = [([], list(reversed(list(nx.topological_sort(G)))))]
 while antichains_stacks:
  (antichain, stack) = antichains_stacks.pop()
  (yield antichain)
  while stack:
   x = stack.pop()
   new_antichain = (antichain + [x])
   new_stack = [t for t in stack if (not ((t in TC[x]) or (x in TC[t])))]
   antichains_stacks.append((new_antichain, new_stack))

@ not_implemented_for ( 'undirected' ) def antichains ( G ) : TC = nx . transitive_closure ( G ) antichains_stacks = [ ( [ ] , list ( reversed ( list ( nx . topological_sort ( G ) ) ) ) ) ] while antichains_stacks : ( antichain , stack ) = antichains_stacks . pop ( ) ( yield antichain ) while stack : x = stack . pop ( ) new_antichain = ( antichain + [ x ] ) new_stack = [ t for t in stack if ( not ( ( t in TC [ x ] ) or ( x in TC [ t ] ) ) ) ] antichains_stacks . append ( ( new_antichain , new_stack ) )
generates antichains from a dag .