U
    ¹mœd	  ã                   @   s@   d Z ddlZddlmZmZ dgZedƒedƒddd„ƒƒZdS )	z=
Algorithm to find a maximal (not maximum) independent set.

é    N)Únot_implemented_forÚpy_random_stateÚmaximal_independent_seté   Zdirectedc                    sÈ   |s|  tˆ ƒ¡h}nt|ƒ}| ˆ ¡s8t |› d�¡‚tj‡ fdd„|D ƒŽ }t ||¡rlt |› d�¡‚t|ƒ}tˆ  ¡ ƒ 	| |¡¡}|rÄ|  t|ƒ¡}| 
|¡ | tˆ j| ƒ|g ¡ qŒ|S )a'  Returns 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.

    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.

    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.

    NetworkXNotImplemented
        If `G` is directed.

    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.

    z" is not a subset of the nodes of Gc                    s   g | ]}t ˆ j| ƒ‘qS © )ÚsetÚadj)Ú.0Úv©ÚGr   úP/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/networkx/algorithms/mis.pyÚ
<listcomp>C   s     z+maximal_independent_set.<locals>.<listcomp>z is not an independent set of G)ÚchoiceÚlistr   ÚissubsetÚnxZNetworkXUnfeasibleÚunionÚintersectionÚnodesÚ
differenceÚappendÚdifference_updater   )r   r   ÚseedZ	neighborsZindep_nodesZavailable_nodesÚnoder   r   r   r      s    2

)NN)Ú__doc__Znetworkxr   Znetworkx.utilsr   r   Ú__all__r   r   r   r   r   Ú<module>   s   