§
    bŠtj•  ã                   óˆ   — d Z ddlZddlmZ dgZ ed¦  «         ed¦  «        ej        d„ ¦   «         ¦   «         ¦   «         ZdS )zŸProvides a function for computing the extendability of a graph which is
undirected, simple, connected and bipartite and contains at least one perfect matching.é    N)Únot_implemented_forÚmaximal_extendabilityÚdirectedÚ
multigraphc           
      ór  ‡‡‡	‡
— t          j        | ¦  «        st          j        d¦  «        ‚t           j                             | ¦  «        st          j        d¦  «        ‚t           j                             | ¦  «        \  ŠŠt           j                             | ¦  «        Š	t          j        | ‰	¦  «        st          j        d¦  «        ‚ˆ	fd„‰‰	                     ¦   «         z  D ¦   «         Š
ˆˆˆ
fd„| j	        D ¦   «         }t          j
        ¦   «         }|                     | ¦  «         |                     |¦  «         t          j        |¦  «        st          j        d¦  «        ‚t          d¦  «        }‰D ]>}‰D ]9}t          d„ t          j        |||¦  «        D ¦   «         ¦  «        }||k     r|n|}Œ:Œ?|S )	ux  Computes the extendability of a graph.

    The extendability of a graph is defined as the maximum $k$ for which `G`
    is $k$-extendable. Graph `G` is $k$-extendable if and only if `G` has a
    perfect matching and every set of $k$ independent edges can be extended
    to a perfect matching in `G`.

    Parameters
    ----------
    G : NetworkX Graph
        A fully-connected bipartite graph without self-loops

    Returns
    -------
    extendability : int

    Raises
    ------
    NetworkXError
       If the graph `G` is disconnected.
       If the graph `G` is not bipartite.
       If the graph `G` does not contain a perfect matching.
       If the residual graph of `G` is not strongly connected.

    Notes
    -----
    Definition:
    Let `G` be a simple, connected, undirected and bipartite graph with a perfect
    matching M and bipartition (U,V). The residual graph of `G`, denoted by $G_M$,
    is the graph obtained from G by directing the edges of M from V to U and the
    edges that do not belong to M from U to V.

    Lemma [1]_ :
    Let M be a perfect matching of `G`. `G` is $k$-extendable if and only if its residual
    graph $G_M$ is strongly connected and there are $k$ vertex-disjoint directed
    paths between every vertex of U and every vertex of V.

    Assuming that input graph `G` is undirected, simple, connected, bipartite and contains
    a perfect matching M, this function constructs the residual graph $G_M$ of G and
    returns the minimum value among the maximum vertex-disjoint directed paths between
    every vertex of U and every vertex of V in $G_M$. By combining the definitions
    and the lemma, this value represents the extendability of the graph `G`.

    Time complexity O($n^3$ $m^2$)) where $n$ is the number of vertices
    and $m$ is the number of edges.

    References
    ----------
    .. [1] "A polynomial algorithm for the extendability problem in bipartite graphs",
          J. Lakhal, L. Litzler, Information Processing Letters, 1998.
    .. [2] "On n-extendible graphs", M. D. Plummer, Discrete Mathematics, 31:201â€“210, 1980
          https://doi.org/10.1016/0012-365X(80)90037-0

    zGraph G is not connectedzGraph G is not bipartitez+Graph G does not contain a perfect matchingc                 ó$   •— g | ]}|‰|         f‘ŒS © r	   )Ú.0ÚnodeÚmaximum_matchings     €úi/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/algorithms/bipartite/extendability.pyú
<listcomp>z)maximal_extendability.<locals>.<listcomp>R   s$   ø€ Ð	QÐ	QÐ	Q¨Tˆ4Ð! $Ô'Ð
(Ð	QÐ	QÐ	Qó    c                 óN   •— g | ]!\  }}|‰v r||f‰v s
|‰v r
||f‰vr||fn||f‘Œ"S r	   r	   )r
   ÚxÚyÚUÚVÚpms      €€€r   r   z)maximal_extendability.<locals>.<listcomp>U   sf   ø€ ð ð ð áˆAˆqð ˜�6�6˜q !˜f¨˜l˜l°°Q°°¸A¸q¸6ÈÐ;KÐ;KˆˆAˆˆÐSTÐVWÐRXðð ð r   z1The residual graph of G is not strongly connectedÚinfc              3   ó   K  — | ]}d V — ŒdS )é   Nr	   )r
   Ú_s     r   ú	<genexpr>z(maximal_extendability.<locals>.<genexpr>g   s"   è è € ÐPÐP !˜AÐPÐPÐPÐPÐPÐPr   )ÚnxÚis_connectedÚNetworkXErrorÚ	bipartiteÚis_bipartiteÚsetsÚhopcroft_karp_matchingÚis_perfect_matchingÚkeysÚedgesÚDiGraphÚadd_nodes_fromÚadd_edges_fromÚis_strongly_connectedÚfloatÚsumÚnode_disjoint_paths)ÚGÚdirected_edgesÚ
residual_GÚkÚuÚvÚ	num_pathsr   r   r   r   s          @@@@r   r   r   
   sá  øøøø€ õt Œ?˜1ÑÔð ;ÝÔÐ9Ñ:Ô:Ð:åŒ<×$Ò$ QÑ'Ô'ð ;ÝÔÐ9Ñ:Ô:Ð:åŒ<×Ò˜QÑÔ�D€A€qå”|×:Ò:¸1Ñ=Ô=ÐåÔ! !Ð%5Ñ6Ô6ð NÝÔÐLÑMÔMÐMð 
RÐ	QÐ	QÐ	Q°QÐ9I×9NÒ9NÑ9PÔ9PÑ5PÐ	QÑ	QÔ	Q€Bðð ð ð ð ð à”Gðñ ô €Nõ ”‘”€JØ×Ò˜aÑ Ô Ð Ø×Ò˜nÑ-Ô-Ð-åÔ# JÑ/Ô/ð TÝÔÐRÑSÔSÐSõ 	ˆe‰Œ€AØð 2ð 2ˆØð 	2ð 	2ˆAÝÐPÐP¥rÔ'=¸jÈ!ÈQÑ'OÔ'OÐPÑPÔPÑPÔPˆIØ˜’]�]��¨	ˆAˆAð	2ð €Hr   )Ú__doc__Únetworkxr   Únetworkx.utilsr   Ú__all__Ú_dispatchabler   r	   r   r   ú<module>r8      s“   ðð[ð [ð Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .à"Ð
#€ð Ð�ZÑ Ô ØÐ�\Ñ"Ô"ØÔð\ð \ñ Ôñ #Ô"ñ !Ô ð\ð \ð \r   