ó
|£*^c           @   sL   d  Z  d j d d g ƒ Z d g Z d d l Z d d l Z d d „ Z d S(   s=   
Algorithm to find a maximal (not maximum) independent set.

s   
s    Leo Lopes <leo.lopes@monash.edu>s'   LoÃ¯c SÃ©guin-C. <loicseguin@gmail.com>t   maximal_independent_setiÿÿÿÿNc         C   s1  | s' t  t j |  j ƒ  ƒ g ƒ } n t  | ƒ } | j |  ƒ sX t j d | ƒ ‚ n  t  j g  | D] } t  |  j | ƒ ƒ ^ qe Œ  } t  j	 | | ƒ r± t j d | ƒ ‚ n  t
 | ƒ } t  |  j ƒ  ƒ j | j | ƒ ƒ } xI | r,t j t
 | ƒ ƒ } | j | ƒ | j |  j | ƒ | g ƒ qä W| S(   sa  Return a random maximal independent set guaranteed to contain
    a given set of nodes.

    An independent set is a set of nodes such that the subgraph
    of G induced by these nodes contains no edges. A maximal
    independent set is an independent set such that it is not possible
    to add a new node and still get an independent set.
    
    Parameters
    ----------
    G : NetworkX graph 

    nodes : list or iterable
       Nodes that must be part of the independent set. This set of nodes
       must be independent.

    Returns
    -------
    indep_nodes : list 
       List of nodes that are part of a maximal independent set.

    Raises
    ------
    NetworkXUnfeasible
       If the nodes in the provided list are not part of the graph or
       do not form an independent set, an exception is raised.

    Examples
    --------
    >>> G = nx.path_graph(5)
    >>> nx.maximal_independent_set(G) # doctest: +SKIP
    [4, 0, 2]
    >>> nx.maximal_independent_set(G, [1]) # doctest: +SKIP
    [1, 3]
    
    Notes
    -----
    This algorithm does not solve the maximum independent set problem.

    s$   %s is not a subset of the nodes of Gs!   %s is not an independent set of G(   t   sett   randomt   choicet   nodest   issubsett   nxt   NetworkXUnfeasiblet   uniont	   neighborst   intersectiont   listt
   differencet   appendt   difference_update(   t   GR   t   vR	   t   indep_nodest   available_nodest   node(    (    sk   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/mis.pyR       s"    )!1$	!(	   t   __doc__t   joint
   __author__t   __all__R   t   networkxR   t   NoneR    (    (    (    sk   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/mis.pyt   <module>   s   		