ó
|£*^c           @   sf   d  Z  d Z d d l m Z d d l Z d d l m Z d d g Z e d ƒ d	 „  ƒ Z	 d
 „  Z
 d S(   s   
Dominance algorithms.
s&   ysitu <ysitu@users.noreply.github.com>iÿÿÿÿ(   t   reduceN(   t   not_implemented_fort   immediate_dominatorst   dominance_frontierst
   undirectedc            s  | |  k r t  j d ƒ ‚ n  i | | 6‰ t t  j |  | ƒ ƒ } d „  t | ƒ Dƒ ‰  | j ƒ  | j ƒ  ‡  ‡ f d †  } t } xv | rı t } xc | D][ } t	 | ‡ f d †  |  j
 | Dƒ ƒ } | ˆ k sã ˆ | | k r› | ˆ | <t } q› q› Wqˆ Wˆ S(   s1  Returns the immediate dominators of all nodes of a directed graph.

    Parameters
    ----------
    G : a DiGraph or MultiDiGraph
        The graph where dominance is to be computed.

    start : node
        The start node of dominance computation.

    Returns
    -------
    idom : dict keyed by nodes
        A dict containing the immediate dominators of each node reachable from
        ``start``.

    Raises
    ------
    NetworkXNotImplemented
        If ``G`` is undirected.

    NetworkXError
        If ``start`` is not in ``G``.

    Notes
    -----
    Except for ``start``, the immediate dominators are the parents of their
    corresponding nodes in the dominator tree.

    Examples
    --------
    >>> G = nx.DiGraph([(1, 2), (1, 3), (2, 5), (3, 4), (4, 5)])
    >>> sorted(nx.immediate_dominators(G, 1).items())
    [(1, 1), (2, 1), (3, 1), (4, 3), (5, 1)]

    References
    ----------
    .. [1] K. D. Cooper, T. J. Harvey, and K. Kennedy.
           A simple, fast dominance algorithm.
           Software Practice & Experience, 4:110, 2001.
    s   start is not in Gc         S   s   i  |  ] \ } } | | “ q S(    (    (   t   .0t   it   u(    (    sq   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/dominance.pys
   <dictcomp>B   s   	 c            sa   xZ |  | k r\ x" ˆ  |  ˆ  | k  r3 ˆ |  }  q Wx" ˆ  |  ˆ  | k rX ˆ | } q7 Wq W|  S(   N(    (   R   t   v(   t   dfnt   idom(    sq   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/dominance.pyt	   intersectF   s    c         3   s!   |  ] } | ˆ  k r | Vq d  S(   N(    (   R   R   (   R
   (    sq   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/dominance.pys	   <genexpr>R   s    (   t   nxt   NetworkXErrort   listt   dfs_postorder_nodest	   enumeratet   popt   reverset   Truet   FalseR    t   pred(   t   Gt   startt   orderR   t   changedR   t   new_idom(    (   R	   R
   sq   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/dominance.pyR      s"    +

	&
c         C   sô   t  j |  | ƒ } d „  | Dƒ } xË | D]Ã } t |  j | ƒ t | |  j | k ƒ d k r) t ƒ  } xO |  j | D]@ } x7 | | | k rµ | | k rµ | j | ƒ | | } q Wqv W| j | ƒ x" | D] } | | j | ƒ qÎ Wq) q) W| S(   sÊ  Returns the dominance frontiers of all nodes of a directed graph.

    Parameters
    ----------
    G : a DiGraph or MultiDiGraph
        The graph where dominance is to be computed.

    start : node
        The start node of dominance computation.

    Returns
    -------
    df : dict keyed by nodes
        A dict containing the dominance frontiers of each node reachable from
        ``start`` as lists.

    Raises
    ------
    NetworkXNotImplemented
        If ``G`` is undirected.

    NetworkXError
        If ``start`` is not in ``G``.

    Examples
    --------
    >>> G = nx.DiGraph([(1, 2), (1, 3), (2, 5), (3, 4), (4, 5)])
    >>> sorted((u, sorted(df)) for u, df in nx.dominance_frontiers(G, 1).items())
    [(1, []), (2, [5]), (3, [5]), (4, [5]), (5, [])]

    References
    ----------
    .. [1] K. D. Cooper, T. J. Harvey, and K. Kennedy.
           A simple, fast dominance algorithm.
           Software Practice & Experience, 4:110, 2001.
    c         S   s   i  |  ] } g  | “ q S(    (    (   R   R   (    (    sq   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/dominance.pys
   <dictcomp>�   s   	 i   (	   R   R   t   lenR   t   intt   sett   addt   discardt   append(   R   R   R
   t   dfR   t   pR   (    (    sq   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/dominance.pyR   Z   s    %0	(   t   __doc__t
   __author__t	   functoolsR    t   networkxR   t   networkx.utilsR   t   __all__R   R   (    (    (    sq   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/dominance.pyt   <module>   s   I