Ë
    ÷Ç:j  ã                   óä   — d Z ddlZddlmZ g d¢Zej                  d„ «       Z ed«      ej                  d„ «       «       Z ed«       ed«       ej                  d	d	¬
«      dd„«       «       «       Z	y)z5Functions for computing and verifying regular graphs.é    N)Únot_implemented_for)Ú
is_regularÚis_k_regularÚk_factorc                 óÒ  ‡‡‡— t        | «      dk(  rt        j                  d«      ‚t        j                  j	                  | «      }| j                  «       s/| j                  |«      Št        ˆfd„| j                  D «       «      S | j                  |«      Šˆfd„| j                  D «       }| j                  |«      Šˆfd„| j                  D «       }t        |«      xr t        |«      S )aê  Determines whether a graph is regular.

    A regular graph is a graph where all nodes have the same degree. A regular
    digraph is a graph where all nodes have the same indegree and all nodes
    have the same outdegree.

    Parameters
    ----------
    G : NetworkX graph

    Returns
    -------
    bool
        Whether the given graph or digraph is regular.

    Examples
    --------
    >>> G = nx.DiGraph([(1, 2), (2, 3), (3, 4), (4, 1)])
    >>> nx.is_regular(G)
    True

    r   zGraph has no nodes.c              3   ó.   •K  — | ]  \  }}‰|k(  –— Œ y ­w©N© )Ú.0Ú_ÚdÚd1s      €úp/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/networkx/algorithms/regular.pyú	<genexpr>zis_regular.<locals>.<genexpr>&   s   øè ø€ Ò0™t˜q !�2˜•7Ñ0ùó   ƒc              3   ó.   •K  — | ]  \  }}‰|k(  –— Œ y ­wr	   r
   )r   r   r   Úd_ins      €r   r   zis_regular.<locals>.<genexpr>)   s   øè ø€ Ò8¡D A q�d˜a•iÑ8ùr   c              3   ó.   •K  — | ]  \  }}‰|k(  –— Œ y ­wr	   r
   )r   r   r   Úd_outs      €r   r   zis_regular.<locals>.<genexpr>+   s   øè ø€ Ò;¡d a¨�u •zÑ;ùr   )
ÚlenÚnxÚNetworkXPointlessConceptÚutilsÚarbitrary_elementÚis_directedÚdegreeÚallÚ	in_degreeÚ
out_degree)ÚGÚn1Ú
in_regularÚout_regularr   r   r   s       @@@r   r   r   	   s¬   ú€ ô0 ˆ1ƒv�‚{Ü×)Ñ)Ð*?Ó@Ð@Ü	�‰×	#Ñ	# AÓ	&€BØ�=‰=Œ?Ø�X‰X�b‹\ˆÜÓ0 q§x¡xÔ0Ó0Ð0à�{‰{˜2‹ˆÛ8¨A¯K©KÔ8ˆ
Ø—‘˜RÓ ˆÛ;¨a¯l©lÔ;ˆÜ�:‹Ò3¤3 {Ó#3Ð3ó    Údirectedc                 ó@   ‡— t        ˆfd„| j                  D «       «      S )a‚  Determines whether the graph ``G`` is a k-regular graph.

    A k-regular graph is a graph where each vertex has degree k.

    Parameters
    ----------
    G : NetworkX graph

    Returns
    -------
    bool
        Whether the given graph is k-regular.

    Examples
    --------
    >>> G = nx.Graph([(1, 2), (2, 3), (3, 4), (4, 1)])
    >>> nx.is_k_regular(G, k=3)
    False

    c              3   ó.   •K  — | ]  \  }}|‰k(  –— Œ y ­wr	   r
   )r   Únr   Úks      €r   r   zis_k_regular.<locals>.<genexpr>F   s   øè ø€ Ò+™$˜!˜Qˆq�A�vÑ+ùr   )r   r   )r    r)   s    `r   r   r   /   s   ø€ ô. Ó+ !§(¡(Ô+Ó+Ð+r$   Ú
multigraphT)Úpreserve_edge_attrsÚreturns_graphc                 ó  ‡‡‡‡‡— t        ˆfd„| j                  D «       «      rt        j                  d«      ‚| j	                  «       }g }| j                  D �]+  \  }}‰|dz  k\  Št        |«      D �cg c]  }||f‘Œ c}Š‰r$t        |d|z  ‰z
  «      D �cg c]  }||f‘Œ }}g ŠnCt        d|z  d|z  ‰z   «      D �cg c]  }||f‘Œ }}t        |d|z  «      D �cg c]  }||f‘Œ c}Š|j                  t        ‰‰«      «       t        ‰||   j                  «       «      D ]  \  }	\  }
} |j                  |	|
fi |¤Ž Œ |j                  ˆˆˆfd„|D «       «       |j                  |«       |j                  |‰|‰f«       �Œ. t        j                  |d|¬«      Št        j                  |‰«      st        j                  d«      ‚|j                  ˆfd	„|j                  D «       «       |D ]€  \  }Š}Š|j!                  |«       t#        |«      }‰D ]A  }	|j$                  |	   j                  «       D ]  \  }
}|
|vsŒ |j                  ||
fi |¤Ž  ŒA ŒC |j'                  ‰|z   ‰z   «       Œ‚ |S c c}w c c}w c c}w c c}w )
u<  Compute a `k`-factor of a graph.

    A `k`-factor of a graph is a spanning `k`-regular subgraph.
    A spanning `k`-regular subgraph of `G` is a subgraph that contains
    each node of `G` and a subset of the edges of `G` such that each
    node has degree `k`.

    Parameters
    ----------
    G : NetworkX graph
        An undirected graph.

    k : int
        The degree of the `k`-factor.

    matching_weight: string, optional (default="weight")
        Edge attribute name corresponding to the edge weight.
        If not present, the edge is assumed to have weight 1.
        Used for finding the max-weighted perfect matching.

    Returns
    -------
    NetworkX graph
        A `k`-factor of `G`.

    Examples
    --------
    >>> G = nx.Graph([(1, 2), (2, 3), (3, 4), (4, 1)])
    >>> KF = nx.k_factor(G, k=1)
    >>> KF.edges()
    EdgeView([(1, 2), (3, 4)])

    References
    ----------
    .. [1] "An algorithm for computing simple k-factors.",
       Meijer, Henk, Yurai NÃºÃ±ez-RodrÃ­guez, and David Rappaport,
       Information processing letters, 2009.
    c              3   ó.   •K  — | ]  \  }}|‰k  –— Œ y ­wr	   r
   )r   r   r   r)   s      €r   r   zk_factor.<locals>.<genexpr>t   s   øè ø€ Ò
&‘T�Q˜ˆ1ˆq�5Ñ
&ùr   z/Graph contains a vertex with degree less than kg       @é   c              3   ó<   •K  — | ]  }‰r‰n‰D ]  }||f–— Œ
 Œ y ­wr	   r
   )r   ÚuÚvÚinnerÚis_largeÚouters      €€€r   r   zk_factor.<locals>.<genexpr>�   s%   øè ø€ ÒV AÁ¹ÈuÒV°!˜!˜QœÐV˜ÑVùs   ƒT)ÚmaxcardinalityÚweightz7Cannot find k-factor because no perfect matching existsc              3   óB   •K  — | ]  }|‰vsŒ|d d d…   ‰vsŒ|–— Œ y ­w)Néÿÿÿÿr
   )r   ÚeÚms     €r   r   zk_factor.<locals>.<genexpr>š   s&   øè ø€ ÒN˜a¨a°qªj¸Q¹tÀ¸t¹WÈAÒ=MœÑNùs   ƒ	�
˜)Úanyr   r   ÚNetworkXUnfeasibleÚcopyÚrangeÚadd_edges_fromÚzipÚitemsÚadd_edgeÚremove_nodeÚappendÚmax_weight_matchingÚis_perfect_matchingÚremove_edges_fromÚedgesÚadd_nodeÚsetÚ_adjÚremove_nodes_from)r    r)   Úmatching_weightÚgÚgadgetsÚnoder   ÚiÚcoreÚouter_nÚneighborÚattrsÚcore_setr3   r4   r;   r5   s    `           @@@@r   r   r   I   s‰  ü€ ôV Ó
&˜QŸX™XÔ
&Ô&Ü×#Ñ#Ð$UÓVÐVà	�‰‹€AØ€Gð Ÿ™ó 3‰ˆˆfØ˜ ™Ñ$ˆô %*¨&£MÖ2˜q�$˜’Ò2ˆÙÜ',¨V°Q¸±ZÀ!±^Ó'DÖE !�T˜1’IÐEˆDÐEØ‰Eä',¨Q°©Z¸¸V¹Àa¹Ó'HÖI !�T˜1’IÐIˆDÐIÜ(-¨f°a¸&±jÓ(AÖB 1�d˜A’YÒBˆEð 	
×Ñœ˜U EÓ*Ô+Ü*-¨e°Q°t±W·]±]³_Ó*Eò 	3Ñ&ˆGÑ&�h ØˆA�J‰J�w Ñ2¨EÓ2ð	3ð 	
×ÑÕV¨ÔVÔVà	�‰�dÔØ�‰˜˜e T¨5Ð1Ö2ð+3ô0 	×Ñ˜q°¸oÔN€AÜ×!Ñ! ! QÔ'Ü×#Ñ#ØEó
ð 	
ð
 ×ÑÓN 1§7¡7ÔNÔNð %,ò 2Ñ ˆˆe�T˜5Ø	�
‰
�4ÔÜ�t“9ˆØò 	ˆGØ#$§6¡6¨'¡?×#8Ñ#8Ó#:ò ‘�˜%Ø 8Ò+Ø�A—J‘J˜t XÑ7°Ò7Ùñð	ð
 	
×Ñ˜E D™L¨5Ñ0Õ1ð2ð €HùòQ 3ùâEùò JùÚBs   Á3I4ÂI9Â>I>ÃJ)r7   )
Ú__doc__Únetworkxr   Únetworkx.utilsr   Ú__all__Ú_dispatchabler   r   r   r
   r$   r   ú<module>r]      s•   ðÙ ;ã Ý .â
4€ð ×Ññ"4ó ð"4ñJ �ZÓ Ø×Ññ,ó ó !ð,ñ0 �ZÓ Ù�\Ó"Ø€×Ñ d¸$Ô?ò[ó @ó #ó !ñ[r$   