§
    bŠtj6Q  ã                   ó  — d Z ddlZddlmZmZmZ g d¢Z G d„ d¦  «        Z G d„ d¦  «        Z	d	„ Z
d
„ Zd„ Zd„ Z ed¦  «         ed¦  «         ej        d¬¦  «        	 dd„¦   «         ¦   «         ¦   «         Z ed¦  «         ed¦  «         ej        d¬¦  «        	 dd„¦   «         ¦   «         ¦   «         Z ed¦  «         ej        d¬¦  «        	 dd„¦   «         ¦   «         Z ej        d¬¦  «        	 dd„¦   «         ZdS )zB
Algebraic connectivity and Fiedler vectors of undirected graphs.
é    N)Únot_implemented_forÚnp_random_stateÚreverse_cuthill_mckee_ordering)Úalgebraic_connectivityÚfiedler_vectorÚspectral_orderingÚspectral_bisectionc                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )Ú
_PCGSolveraÑ  Preconditioned conjugate gradient method.

    To solve Ax = b:
        M = A.diagonal() # or some other preconditioner
        solver = _PCGSolver(lambda x: A * x, lambda x: M * x)
        x = solver.solve(b)

    The inputs A and M are functions which compute
    matrix multiplication on the argument.
    A - multiply by the matrix A in Ax=b
    M - multiply by M, the preconditioner surrogate for A

    Warning: There is no limit on number of iterations.
    c                 ó"   — || _         || _        d S ©N)Ú_AÚ_M)ÚselfÚAÚMs      úc/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/linalg/algebraicconnectivity.pyÚ__init__z_PCGSolver.__init__$   s   € ØˆŒØˆŒˆˆó    c                 óø   — dd l }|                     |¦  «        }|                     |j        d¬¦  «        }t	          |j        d         ¦  «        D ])}|                      |d d …|f         |¦  «        |d d …|f<   Œ*|S ©Nr   ÚF©Úorderé   )ÚnumpyÚasarrayÚndarrayÚshapeÚrangeÚ_solve©r   ÚBÚtolÚnpÚXÚjs         r   Úsolvez_PCGSolver.solve(   s…   € ØÐÐÐð �JŠJ�q‰MŒMˆØ�JŠJ�q”w cˆJÑ*Ô*ˆÝ�q”w˜q”zÑ"Ô"ð 	0ð 	0ˆAØ—k’k ! A A A q D¤'¨3Ñ/Ô/ˆAˆaˆaˆa�ˆd‰GˆGØˆr   c                 ó(  — dd l }dd l}| j        }| j        }||j        j                             |¦  «        z  }|                     |j        ¦  «        }| 	                    ¦   «         } ||¦  «        }	|j        j         
                    ||	¦  «        }
|	 	                    ¦   «         }	  ||¦  «        }|
|j        j         
                    ||¦  «        z  }|j        j                             |||¬¦  «        }|j        j                             ||| ¬¦  «        }|j        j                             |¦  «        |k     r|S  ||¦  «        }	|j        j         
                    ||	¦  «        }||
z  |}
}|j        j                             ||	|¬¦  «        }Œí)Nr   T)Úa)r   Úscipyr   r   ÚlinalgÚblasÚdasumÚzerosr   ÚcopyÚddotÚdaxpy)r   Úbr$   r%   Úspr   r   ÚxÚrÚzÚrzÚpÚApÚalphaÚbetas                  r   r!   z_PCGSolver._solve2   s}  € ØÐÐÐØÐÐÐàŒGˆØŒGˆØˆrŒyŒ~×#Ò# AÑ&Ô&Ñ&ˆà�HŠH�Q”WÑÔˆØ�FŠF‰HŒHˆØˆAˆa‰DŒDˆØŒYŒ^× Ò   AÑ&Ô&ˆØ�FŠF‰HŒHˆð
	3Ø��1‘”ˆBØ˜œœ×,Ò,¨Q°Ñ3Ô3Ñ3ˆEØ”	”×$Ò$ Q¨¨UÐ$Ñ3Ô3ˆAØ”	”×$Ò$ R¨¨u¨fÐ$Ñ5Ô5ˆAØŒyŒ~×#Ò# AÑ&Ô&¨Ò,Ð,Ø�Ø��!‘”ˆAØ”9”>×&Ò& q¨!Ñ,Ô,ˆDØ˜b‘y $�"ˆDØ”	”×$Ò$ Q¨¨TÐ$Ñ2Ô2ˆAð
	3r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r(   r!   © r   r   r   r      sK   € € € € € ðð ðð ð ðð ð ð3ð 3ð 3ð 3ð 3r   r   c                   ó    — e Zd ZdZd„ Zdd„ZdS )Ú	_LUSolverzÈLU factorization.

    To solve Ax = b:
        solver = _LUSolver(A)
        x = solver.solve(b)

    optional argument `tol` on solve method is ignored but included
    to match _PCGsolver API.
    c                 ód   — dd l }|j        j                             |dddddœ¬¦  «        | _        d S )Nr   ÚMMD_AT_PLUS_Aç        T)ÚEquilÚSymmetricMode)Ú
permc_specÚdiag_pivot_threshÚoptions)r+   Úsparser,   ÚspluÚ_LU)r   r   r4   s      r   r   z_LUSolver.__init__X   sG   € ØÐÐÐà”9Ô#×(Ò(ØØ&Ø!Ø"°TÐ:Ð:ð	 )ñ 
ô 
ˆŒˆˆr   Nc                 ó   — dd l }|                     |¦  «        }|                     |j        d¬¦  «        }t	          |j        d         ¦  «        D ]-}| j                             |d d …|f         ¦  «        |d d …|f<   Œ.|S r   )r   r   r   r   r    rN   r(   r"   s         r   r(   z_LUSolver.solveb   sƒ   € ØÐÐÐà�JŠJ�q‰MŒMˆØ�JŠJ�q”w cˆJÑ*Ô*ˆÝ�q”w˜q”zÑ"Ô"ð 	.ð 	.ˆAØ”h—n’n Q q q q¨! t¤WÑ-Ô-ˆAˆaˆaˆa�ˆd‰GˆGØˆr   r   )r=   r>   r?   r@   r   r(   rA   r   r   rC   rC   M   sA   € € € € € ðð ð
ð 
ð 
ðð ð ð ð ð r   rC   c                 ó2  ‡ ‡— ‰                       ¦   «         rat          j        ¦   «         }|                     ‰ ¦  «         |                     ˆfd„‰                      d¬¦  «        D ¦   «         ‰¬¦  «         |Š ‰                      ¦   «         s#ˆfd„‰                      d¬¦  «        D ¦   «         }n!ˆ ˆfd„‰                      ¦   «         D ¦   «         }t          j        ¦   «         }|                     ‰ ¦  «         |                     d„ |D ¦   «         ¦  «         |S )z5Compute edge weights and eliminate zero-weight edges.c              3   ó^   •K  — | ]'\  }}}||k    ¯|||                      ‰d ¦  «        fV — Œ(dS ©ç      ð?N)Úget©Ú.0ÚuÚvÚeÚweights       €r   ú	<genexpr>z$_preprocess_graph.<locals>.<genexpr>r   sC   øè è € ÐTÐT©G¨A¨q°!ÈQÐRSÊVÈVˆa��A—E’E˜& #Ñ&Ô&Ð'ÈVÈVÈVÈVÐTÐTr   T)Údata)rZ   c           	   3   óx   •K  — | ]4\  }}}||k    ¯||t          |                     ‰d ¦  «        ¦  «        fV — Œ5dS rR   ©ÚabsrT   rU   s       €r   r[   z$_preprocess_graph.<locals>.<genexpr>w   s[   øè è € ð 
ð 
Ù07°°1°aÐQRÐVWÒQWÐQWˆQ�•3�q—u’u˜V SÑ)Ô)Ñ*Ô*Ð+ÐQWÐQWÐQWÐQWð
ð 
r   c              3   ó¢   •K  — | ]I\  }}||k    ¯||t          ˆfd „‰|         |                              ¦   «         D ¦   «         ¦  «        fV — ŒJdS )c              3   ó^   •K  — | ]'}t          |                     ‰d ¦  «        ¦  «        V — Œ(dS rR   r^   )rV   rY   rZ   s     €r   r[   z._preprocess_graph.<locals>.<genexpr>.<genexpr>|   s9   øè è € ÐIÐI°1•s˜1Ÿ5š5 ¨Ñ-Ô-Ñ.Ô.ÐIÐIÐIÐIÐIÐIr   N)ÚsumÚvalues)rV   rW   rX   ÚGrZ   s      €€r   r[   z$_preprocess_graph.<locals>.<genexpr>{   so   øè è € ð 
ð 
á��1Ø�AŠvˆvð �•3ÐIÐIÐIÐI¸¸!¼¸Q¼¿ºÑ8HÔ8HÐIÑIÔIÑIÔIÐJàˆvˆvˆvð
ð 
r   c              3   ó4   K  — | ]\  }}}|d k    ¯|||fV — ŒdS )r   NrA   )rV   rW   rX   rY   s       r   r[   z$_preprocess_graph.<locals>.<genexpr>‚   s2   è è € ÐGÐG©G¨A¨q°!ÀÀQÂÀ˜q ! Q˜iÀÀÀÀÐGÐGr   )Úis_directedÚnxÚ
MultiGraphÚadd_nodes_fromÚadd_weighted_edges_fromÚedgesÚis_multigraphÚGraph)rd   rZ   ÚHrk   s   ``  r   Ú_preprocess_graphro   l   sG  øø€ à‡}‚}�„ð ÝŒM‰OŒOˆØ	×Ò˜ÑÔÐØ	×!Ò!ØTÐTÐTÐT°q·w²wÀD°wÑ7IÔ7IÐTÑTÔTØð 	"ñ 	
ô 	
ð 	
ð ˆØ�?Š?ÑÔð 	
ð
ð 
ð 
ð 
Ø;<¿7º7È¸7Ñ;MÔ;Mð
ñ 
ô 
ˆˆð
ð 
ð 
ð 
ð 
àŸš™	œ	ð
ñ 
ô 
ˆõ
 	Œ‰
Œ
€AØ×Ò�QÑÔÐØ×ÒÐGÐG°uÐGÑGÔGÑGÔGÐGØ€Hr   c                 óV  — ddl }|                      |¦  «        } t          | ¦  «        }t          |¦  «        }t	          t          |t          |¦  «        ¦  «        ¦  «        }|                     |t          ¬¦  «        }t          |¦  «        D ]\  }}||||         <   Œ||dz
  dz  z  }|S )zEEstimate the Fiedler vector using the reverse Cuthill-McKee ordering.r   N©Údtyper   ç       @)
r   Úsubgraphr   ÚlenÚdictÚzipr    r   ÚfloatÚ	enumerate)	rd   Únodelistr%   r   ÚnÚindexr5   ÚirW   s	            r   Ú_rcm_estimater~   †   sª   € àÐÐÐà	�
Š
�8ÑÔ€AÝ*¨1Ñ-Ô-€EÝˆH‰Œ€AÝ•�X�u Q™xœxÑ(Ô(Ñ)Ô)€EØ
�
Š
�1�Eˆ
Ñ"Ô"€AÝ˜%Ñ Ô ð ð ‰ˆˆ1Øˆˆ%�Œ(‰ˆØˆ!ˆa‰%�3‰Ñ€AØ€Hr   c                 ó  ‡ ‡‡‡‡— ddl Šddl}|j        d         Š|r…‰                     ‰                      ¦   «         ¦  «        Š|j                             d‰z  df‰‰f¬¦  «                             ¦   «         Š‰‰ z  ‰z  Š ‰d‰j         	                    ‰d¦  «        z  z  Š|rˆˆfd„}nˆˆfd„}|d	k    rC‰                      ¦   «          
                    t          ¦  «        Št          ˆ fd
„ˆfd„¦  «        }nŒ|dk    ro|j                             ‰ t          d¬¦  «        }|j        dd…         |j        dd…         z
                       ¦   «         }	‰j        ||	|	f<   t#          |¦  «        }nt%          j        d|› �¦  «        ‚t)          ‰ ¦  «                             d¬¦  «                             ¦   «                              ¦   «         }
 ||¦  «         ‰                     |j        d¬¦  «        }	 ‰j                             |¦  «        d         }‰ |z  |dd…dd…f<   |j        |z  }|j                             |d¬¦  «        \  }}||z  }|j        j                             ||dd…df         z  |d         |dd…df         z  z
  ¦  «        |
z  }||k     rn[|                     ||¦  «        |dd…dd…f<   |j                             |j        |z  ¦  «        |j        z  j        } ||¦  «         �Œ|‰                      |¦  «        fS )aÙ  Compute the Fiedler vector of L using the TraceMIN-Fiedler algorithm.

    The Fiedler vector of a connected undirected graph is the eigenvector
    corresponding to the second smallest eigenvalue of the Laplacian matrix
    of the graph. This function starts with the Laplacian L, not the Graph.

    Parameters
    ----------
    L : Laplacian of a possibly weighted or normalized, but undirected graph

    X : Initial guess for a solution. Usually a matrix of random numbers.
        This function allows more than one column in X to identify more than
        one eigenvector if desired.

    normalized : bool
        Whether the normalized Laplacian matrix is used.

    tol : float
        Tolerance of relative residual in eigenvalue computation.
        Warning: There is no limit on number of iterations.

    method : string
        Should be 'tracemin_pcg' or 'tracemin_lu'.
        Otherwise exception is raised.

    Returns
    -------
    sigma, X : Two NumPy arrays of floats.
        The lowest eigenvalues and corresponding eigenvectors of L.
        The size of input X determines the size of these outputs.
        As this is for Fiedler vectors, the zero eigenvalue (and
        constant eigenvector) are avoided.
    r   Nr   ©r   rS   é   c                 ó´   •— ‰                      | ¦  «        } t          | j        d         ¦  «        D ]&}| dd…|fxx         | dd…|f         ‰z  ‰z  z  cc<   Œ'dS ©z(Make X orthogonal to the nullspace of L.r   N)r   r    r   )r&   r'   rY   r%   s     €€r   Úprojectz"_tracemin_fiedler.<locals>.projectÆ   sn   ø€ à—
’
˜1‘”ˆAÝ˜1œ7 1œ:Ñ&Ô&ð -ð -�Ø�!�!�!�Q�$��”˜A˜a˜a˜a ˜dœG a™K¨1Ñ,Ñ,��‘�ð-ð -r   c                 óÒ   •— ‰                      | ¦  «        } t          | j        d         ¦  «        D ]5}| dd…|fxx         | dd…|f                              ¦   «         ‰z  z  cc<   Œ6dS rƒ   )r   r    r   rb   )r&   r'   r{   r%   s     €€r   r„   z"_tracemin_fiedler.<locals>.projectÎ   sr   ø€ à—
’
˜1‘”ˆAÝ˜1œ7 1œ:Ñ&Ô&ð -ð -�Ø�!�!�!�Q�$��”˜1˜Q˜Q˜Q ˜Tœ7Ÿ;š;™=œ=¨1Ñ,Ñ,��‘�ð-ð -r   Útracemin_pcgc                 ó   •— ‰| z  S r   rA   )r5   ÚLs    €r   ú<lambda>z#_tracemin_fiedler.<locals>.<lambda>Ö   s   ø€  a¨!¡e€ r   c                 ó   •— ‰| z  S r   rA   )r5   ÚDs    €r   r‰   z#_tracemin_fiedler.<locals>.<lambda>Ö   s   ø€ °q¸1±u€ r   Útracemin_luT)rr   r0   éÿÿÿÿzUnknown linear system solver: )Úaxisr   r   )Úoverwrite_a)!r   r+   r   ÚsqrtÚdiagonalrL   Ú	dia_arrayÚtocsrr,   ÚnormÚastyperx   r   Ú	csc_arrayÚindptrÚargmaxÚinfrC   rg   ÚNetworkXErrorr_   rb   ÚflattenÚmaxr   ÚqrÚTÚeighr-   r.   r(   Úinvr   )rˆ   r&   Ú
normalizedr$   Úmethodr4   r„   Úsolverr   r}   ÚLnormÚWrn   ÚsigmaÚYÚresr‹   rY   r{   r%   s   `               @@@@r   Ú_tracemin_fiedlerr©   •   sB  øøøøø€ ðD ÐÐÐØÐÐÐà	Œ�Œ
€Aàð (ð �GŠG�A—J’J‘L”LÑ!Ô!ˆØŒI×Ò  Q¡¨ 
°1°a°&ÐÑ9Ô9×?Ò?ÑAÔAˆØ�‰E�A‰IˆØ	ˆS�2”9—>’> ! QÑ'Ô'Ñ'Ñ'ˆàð -ð	-ð 	-ð 	-ð 	-ð 	-ð 	-ð 	-ð	-ð 	-ð 	-ð 	-ð 	-ð 	-ð �ÒÐØ�JŠJ‰LŒL×Ò¥Ñ&Ô&ˆÝ˜O˜O˜O˜O¨_¨_¨_¨_Ñ=Ô=ˆˆØ	�=Ò	 Ð	 àŒI×Ò ­°TÐÑ:Ô:ˆð
 ŒX�a�b�bŒ\˜AœH S b SœMÑ)×1Ò1Ñ3Ô3ˆØ”&ˆˆ!ˆQˆ$‰Ý˜1‘”ˆˆåÔÐHÀÐHÐHÑIÔIÐIõ �‰FŒF�JŠJ˜AˆJÑÔ×&Ò&Ñ(Ô(×,Ò,Ñ.Ô.€EØ€GˆA�J„J€JØ
�
Š
�1”7 #ˆ
Ñ&Ô&€AðàŒI�LŠL˜‰OŒO˜AÔˆà�a‘%ˆˆ!ˆ!ˆ!ˆQˆQˆQˆ$‰ØŒC�!‰GˆØ”9—>’> !°�>Ñ6Ô6‰ˆˆqà�‰EˆàŒiŒn×"Ò" 1 q¨¨¨¨A¨¤w¡;°°q´¸A¸a¸a¸aÀ¸d¼GÑ1CÑ#CÑDÔDÀuÑLˆØ�Š9ˆ9Øð —,’,˜q #Ñ&Ô&ˆˆ!ˆ!ˆ!ˆQˆQˆQˆ$‰ØŒY�]Š]˜1œ3 ™7Ñ#Ô# a¤cÑ)Ô,ˆØˆ�‰
Œ
ˆ
ñ%ð( �"—*’*˜Q‘-”-ÐÐr   c                 óŽ   ‡ ‡— ddl Š‰ dk    rdŠ ‰ dv rˆ ˆfd„}n+‰ dk    s‰ dk    rˆ ˆfd	„}nt          j        d
‰ ›d�¦  «        ‚|S )z>Returns a function that solves the Fiedler eigenvalue problem.r   NÚtraceminr†   )r†   rŒ   c                 ó  •— ‰dk    rdnt          d| j        d         dz
  ¦  «        }‰	                     |                     || j        d         f¬¦  «        ¦  «        j        }t          | |||‰¦  «        \  }}|d         |d d …df         fS )Nr†   r   é   r   )Úsize)Úminr   r   Únormalrž   r©   )
rˆ   r5   r¡   r$   ÚseedÚqr&   r¦   r¢   r%   s
           €€r   Úfind_fiedlerz'_get_fiedler_func.<locals>.find_fiedler  sŠ   ø€ Ø˜~Ò-Ð-��µ3°q¸!¼'À!¼*Àq¹.Ñ3IÔ3IˆAØ—
’
˜4Ÿ;š;¨Q°´¸´
¨O˜;Ñ<Ô<Ñ=Ô=Ô?ˆAÝ(¨¨A¨z¸3ÀÑGÔG‰HˆE�1Ø˜”8˜Q˜q˜q˜q !˜tœWÐ$Ð$r   ÚlanczosÚlobpcgc           	      ó¬  •— dd l }|j                             | t          ¬¦  «        } | j        d         }|rb|j                             d‰                     |                      ¦   «         ¦  «        z  df||f¬¦  «                             ¦   «         }|| z  |z  } ‰dk    s|dk     r;|j        j	         
                    | dd|d	¬
¦  «        \  }}	|d         |	d d …df         fS ‰                     ‰                     |¦  «        j        ¦  «        }	|j                             d|                      ¦   «         z  df||f¬¦  «                             ¦   «         }
‰                     |¦  «        }|r||                     ¦   «         z  }|j        j	                             | |	|
‰                     |¦  «        j        ||d¬¦  «        \  }}	|d         |	d d …df         fS )Nr   rq   rS   r€   r´   é
   r�   ÚSMT)Úwhichr$   Úreturn_eigenvectorsr   F)r   r§   r$   ÚmaxiterÚlargest)r+   rL   r–   rx   r   r’   r�   r‘   Útocscr,   Úeigshr   Ú
atleast_2drž   r“   Úonesrµ   )rˆ   r5   r¡   r$   r±   r4   r{   r‹   r¦   r&   r   r§   r¢   r%   s               €€r   r³   z'_get_fiedler_func.<locals>.find_fiedler  sÞ  ø€ ØÐÐÐà”	×#Ò# A­UÐ#Ñ3Ô3ˆAØ”˜”
ˆAØð Ø”I×'Ò'Ø˜2Ÿ7š7 1§:¢:¡<¤<Ñ0Ô0Ñ0°!Ð4¸QÀ¸Fð (ñ ô ç’%‘'”'ð ð ˜‘E˜A‘I�Ø˜Ò"Ð" a¨"¢f fð œ9Ô+×1Ò1Ø�q ¨#À4ð 2ñ ô ‘��qð ˜Q”x  1 1 1 a 4¤Ð(Ð(à—J’J˜rŸ}š}¨QÑ/Ô/Ô1Ñ2Ô2�Ø”I×'Ò'¨¨q¯zªz©|¬|Ñ);¸QÐ(?ÈÈ1ÀvÐ'ÑNÔN×TÒTÑVÔV�Ø—G’G˜A‘J”J�Øð &Ø˜Ÿš™œÑ%�AØœ9Ô+×2Ò2Ø�q˜A §¢¨qÑ!1Ô!1Ô!3¸ÀaÐQVð 3ñ ô ‘��qð ˜Q”x  1 1 1 a 4¤Ð(Ð(r   zunknown method ú.)r   rg   rš   )r¢   r³   r%   s   ` @r   Ú_get_fiedler_funcrÂ      s®   øø€ àÐÐÐà�ÒÐØˆØÐ0Ð0Ð0ð	%ð 	%ð 	%ð 	%ð 	%ð 	%ð 	%ð 
�9Ò	Ð	 ¨(Ò 2Ð 2ð	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)õ< ÔÐ<°Ð<Ð<Ð<Ñ=Ô=Ð=àÐr   Údirectedé   rZ   )Ú
edge_attrsFç:Œ0âŽyE>r†   c                 ó®  — t          | ¦  «        dk     rt          j        d¦  «        ‚t          | |¦  «        } t          j        | ¦  «        sdS t          j        | ¦  «        }|j        d         dk    r|sdt          |d         ¦  «        z  ndS t          |¦  «        }|dk    rdnt          | | ¦  «        } ||||||¦  «        \  }	}
t          |	¦  «        S )	a 	  Returns the algebraic connectivity of an undirected graph.

    The algebraic connectivity of a connected undirected graph is the second
    smallest eigenvalue of its Laplacian matrix.

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

    weight : object, optional (default: None)
        The data key used to determine the weight of each edge. If None, then
        each edge has unit weight.

    normalized : bool, optional (default: False)
        Whether the normalized Laplacian matrix is used.

    tol : float, optional (default: 1e-8)
        Tolerance of relative residual in eigenvalue computation.

    method : string, optional (default: 'tracemin_pcg')
        Method of eigenvalue computation. It must be one of the tracemin
        options shown below (TraceMIN), 'lanczos' (Lanczos iteration)
        or 'lobpcg' (LOBPCG).

        The TraceMIN algorithm uses a linear system solver. The following
        values allow specifying the solver to be used.

        =============== ========================================
        Value           Solver
        =============== ========================================
        'tracemin_pcg'  Preconditioned conjugate gradient method
        'tracemin_lu'   LU factorization
        =============== ========================================

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

    Returns
    -------
    algebraic_connectivity : float
        Algebraic connectivity.

    Raises
    ------
    NetworkXNotImplemented
        If G is directed.

    NetworkXError
        If G has less than two nodes.

    Notes
    -----
    Edge weights are interpreted by their absolute values. For MultiGraph's,
    weights of parallel edges are summed. Zero-weighted edges are ignored.

    See Also
    --------
    laplacian_matrix

    Examples
    --------
    For undirected graphs algebraic connectivity can tell us if a graph is connected or not
    `G` is connected iff  ``algebraic_connectivity(G) > 0``:

    >>> G = nx.complete_graph(5)
    >>> nx.algebraic_connectivity(G) > 0
    True
    >>> G.add_node(10)  # G is no longer connected
    >>> nx.algebraic_connectivity(G) > 0
    False

    r�   úgraph has less than two nodes.rF   r   rs   )r   r   rµ   N)
ru   rg   rš   ro   Úis_connectedÚlaplacian_matrixr   rx   rÂ   r~   )rd   rZ   r¡   r$   r¢   r±   rˆ   r³   r5   r¦   Úfiedlers              r   r   r   3  sÛ   € õ` ˆ1�v„v�‚z€zÝÔÐ?Ñ@Ô@Ð@Ý˜!˜VÑ$Ô$€AÝŒ?˜1ÑÔð Øˆså
Ô˜AÑÔ€AØ„wˆq„z�Q‚€Ø+5Ð>ˆs•U˜1˜Tœ7‘^”^Ñ#Ð#¸3Ð>å$ VÑ,Ô,€LØ˜(Ò"Ð"ˆˆ­°a¸Ñ(;Ô(;€AØ!�\ ! Q¨
°C¸Ñ>Ô>�N€Eˆ7Ý�‰<Œ<Ðr   c                 óº  — ddl }t          | ¦  «        dk     rt          j        d¦  «        ‚t	          | |¦  «        } t          j        | ¦  «        st          j        d¦  «        ‚t          | ¦  «        dk    r|                     ddg¦  «        S t          |¦  «        }t          j        | ¦  «        }|dk    rdnt          | | ¦  «        }	 |||	|||¦  «        \  }
}|S )	a´	  Returns the Fiedler vector of a connected undirected graph.

    The Fiedler vector of a connected undirected graph is the eigenvector
    corresponding to the second smallest eigenvalue of the Laplacian matrix
    of the graph.

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

    weight : object, optional (default: None)
        The data key used to determine the weight of each edge. If None, then
        each edge has unit weight.

    normalized : bool, optional (default: False)
        Whether the normalized Laplacian matrix is used.

    tol : float, optional (default: 1e-8)
        Tolerance of relative residual in eigenvalue computation.

    method : string, optional (default: 'tracemin_pcg')
        Method of eigenvalue computation. It must be one of the tracemin
        options shown below (TraceMIN), 'lanczos' (Lanczos iteration)
        or 'lobpcg' (LOBPCG).

        The TraceMIN algorithm uses a linear system solver. The following
        values allow specifying the solver to be used.

        =============== ========================================
        Value           Solver
        =============== ========================================
        'tracemin_pcg'  Preconditioned conjugate gradient method
        'tracemin_lu'   LU factorization
        =============== ========================================

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

    Returns
    -------
    fiedler_vector : NumPy array of floats.
        Fiedler vector.

    Raises
    ------
    NetworkXNotImplemented
        If G is directed.

    NetworkXError
        If G has less than two nodes or is not connected.

    Notes
    -----
    Edge weights are interpreted by their absolute values. For MultiGraph's,
    weights of parallel edges are summed. Zero-weighted edges are ignored.

    See Also
    --------
    laplacian_matrix

    Examples
    --------
    Given a connected graph the signs of the values in the Fiedler vector can be
    used to partition the graph into two components.

    >>> G = nx.barbell_graph(5, 0)
    >>> nx.fiedler_vector(G, normalized=True, seed=1)
    array([-0.32864129, -0.32864129, -0.32864129, -0.32864129, -0.26072899,
            0.26072899,  0.32864129,  0.32864129,  0.32864129,  0.32864129])

    The connected components are the two 5-node cliques of the barbell graph.
    r   Nr�   rÈ   zgraph is not connected.rS   g      ð¿rµ   )
r   ru   rg   rš   ro   rÉ   ÚarrayrÂ   rÊ   r~   )rd   rZ   r¡   r$   r¢   r±   r%   r³   rˆ   r5   r¦   rË   s               r   r   r   “  sä   € ð` ÐÐÐå
ˆ1�v„v�‚z€zÝÔÐ?Ñ@Ô@Ð@Ý˜!˜VÑ$Ô$€AÝŒ?˜1ÑÔð :ÝÔÐ8Ñ9Ô9Ð9å
ˆ1�v„v�‚{€{Ø�xŠx˜˜d˜Ñ$Ô$Ð$å$ VÑ,Ô,€LÝ
Ô˜AÑÔ€AØ˜(Ò"Ð"ˆˆ­°a¸Ñ(;Ô(;€AØ!�\ ! Q¨
°C¸Ñ>Ô>�N€Eˆ7Ø€Nr   c                 ó,  — t          | ¦  «        dk    rt          j        d¦  «        ‚t          | |¦  «        } t	          |¦  «        }g }t          j        | ¦  «        D ]¶}t          |¦  «        }	|	dk    rŠt          j        | |¦  «        }
|dk    rdnt          | |¦  «        } ||
||||¦  «        \  }}t          |t          |	¦  «        |¦  «        }| 
                    d„ t          |¦  «        D ¦   «         ¦  «         Œ¡| 
                    |¦  «         Œ·|S )a¤  Compute the spectral_ordering of a graph.

    The spectral ordering of a graph is an ordering of its nodes where nodes
    in the same weakly connected components appear contiguous and ordered by
    their corresponding elements in the Fiedler vector of the component.

    Parameters
    ----------
    G : NetworkX graph
        A graph.

    weight : object, optional (default: None)
        The data key used to determine the weight of each edge. If None, then
        each edge has unit weight.

    normalized : bool, optional (default: False)
        Whether the normalized Laplacian matrix is used.

    tol : float, optional (default: 1e-8)
        Tolerance of relative residual in eigenvalue computation.

    method : string, optional (default: 'tracemin_pcg')
        Method of eigenvalue computation. It must be one of the tracemin
        options shown below (TraceMIN), 'lanczos' (Lanczos iteration)
        or 'lobpcg' (LOBPCG).

        The TraceMIN algorithm uses a linear system solver. The following
        values allow specifying the solver to be used.

        =============== ========================================
        Value           Solver
        =============== ========================================
        'tracemin_pcg'  Preconditioned conjugate gradient method
        'tracemin_lu'   LU factorization
        =============== ========================================

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

    Returns
    -------
    spectral_ordering : NumPy array of floats.
        Spectral ordering of nodes.

    Raises
    ------
    NetworkXError
        If G is empty.

    Notes
    -----
    Edge weights are interpreted by their absolute values. For MultiGraph's,
    weights of parallel edges are summed. Zero-weighted edges are ignored.

    See Also
    --------
    laplacian_matrix
    r   zgraph is empty.r�   rµ   Nc              3   ó"   K  — | ]
\  }}}|V — Œd S r   rA   )rV   r5   ÚcrW   s       r   r[   z$spectral_ordering.<locals>.<genexpr>B  s(   è è € Ð<Ð<™w˜q ! Q˜Ð<Ð<Ð<Ð<Ð<Ð<r   )ru   rg   rš   ro   rÂ   Úconnected_componentsrÊ   r~   rw   r    ÚextendÚsorted)rd   rZ   r¡   r$   r¢   r±   r³   r   Ú	componentr®   rˆ   r5   r¦   rË   Ú	sort_infos                  r   r   r   õ  s  € õ@ ˆ1�v„v�‚{€{ÝÔÐ0Ñ1Ô1Ð1Ý˜!˜VÑ$Ô$€Aå$ VÑ,Ô,€LØ€EÝÔ,¨QÑ/Ô/ð 	$ð 	$ˆ	Ý�9‰~Œ~ˆØ�!Š8ˆ8ÝÔ# A yÑ1Ô1ˆAØ (Ò*Ð*��µ¸aÀÑ0KÔ0KˆAØ)˜\¨!¨Q°
¸CÀÑFÔF‰NˆE�7Ý˜G¥U¨4¡[¤[°)Ñ<Ô<ˆIØ�LŠLÐ<Ð<­&°Ñ*;Ô*;Ð<Ñ<Ô<Ñ<Ô<Ð<Ð<à�LŠL˜Ñ#Ô#Ð#Ð#à€Lr   c                 ó*  — ddl }t          j        | |||||¦  «        }|                     t	          | ¦  «        ¦  «        }|dk    }	t          ||	                               ¦   «         ¦  «        t          ||	                              ¦   «         ¦  «        fS )a?  Bisect the graph using the Fiedler vector.

    This method uses the Fiedler vector to bisect a graph.
    The partition is defined by the nodes which are associated with
    either positive or negative values in the vector.

    Parameters
    ----------
    G : NetworkX Graph

    weight : str, optional (default: weight)
        The data key used to determine the weight of each edge. If None, then
        each edge has unit weight.

    normalized : bool, optional (default: False)
        Whether the normalized Laplacian matrix is used.

    tol : float, optional (default: 1e-8)
        Tolerance of relative residual in eigenvalue computation.

    method : string, optional (default: 'tracemin_pcg')
        Method of eigenvalue computation. It must be one of the tracemin
        options shown below (TraceMIN), 'lanczos' (Lanczos iteration)
        or 'lobpcg' (LOBPCG).

        The TraceMIN algorithm uses a linear system solver. The following
        values allow specifying the solver to be used.

        =============== ========================================
        Value           Solver
        =============== ========================================
        'tracemin_pcg'  Preconditioned conjugate gradient method
        'tracemin_lu'   LU factorization
        =============== ========================================

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

    Returns
    -------
    bisection : tuple of sets
        Sets with the bisection of nodes

    Examples
    --------
    >>> G = nx.barbell_graph(3, 0)
    >>> nx.spectral_bisection(G)
    ({0, 1, 2}, {3, 4, 5})

    References
    ----------
    .. [1] M. E. J Newman 'Networks: An Introduction', pages 364-370
       Oxford University Press 2011.
    r   N)r   rg   r   rÍ   ÚlistÚsetÚtolist)
rd   rZ   r¡   r$   r¢   r±   r%   rX   ÚnodesÚpos_valss
             r   r	   r	   I  s‰   € ðv ÐÐÐå
Ô˜!˜V Z°°f¸dÑCÔC€AØ�HŠH•T˜!‘W”WÑÔ€EØ�AŠv€Håˆu�h�YÔ×&Ò&Ñ(Ô(Ñ)Ô)­3¨u°X¬×/EÒ/EÑ/GÔ/GÑ+HÔ+HÐHÐHr   )rZ   FrÆ   r†   N)r@   Únetworkxrg   Únetworkx.utilsr   r   r   Ú__all__r   rC   ro   r~   r©   rÂ   Ú_dispatchabler   r   r   r	   rA   r   r   ú<module>rà      sR  ððð ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ðð ð €ð63ð 63ð 63ð 63ð 63ñ 63ô 63ð 63ðrð ð ð ð ñ ô ð ð>ð ð ð4ð ð ðh ð h ð h ðV0ð 0ð 0ðf Ð�ZÑ Ô Ø€�ÑÔØ€Ô˜XÐ&Ñ&Ô&àPTðZð Zð Zñ 'Ô&ñ Ôñ !Ô ðZðz Ð�ZÑ Ô Ø€�ÑÔØ€Ô˜XÐ&Ñ&Ô&àPTð\ð \ð \ñ 'Ô&ñ Ôñ !Ô ð\ð~ €�ÑÔØ€Ô˜XÐ&Ñ&Ô&àPTðOð Oð Oñ 'Ô&ñ ÔðOðd €Ô˜XÐ&Ñ&Ô&àPTð@Ið @Ið @Iñ 'Ô&ð@Ið @Ið @Ir   