
    h                     p    S r SSKrSS/r\R                  " SS9S 5       r\R                  " SS9S 5       rg)	z$
Utilities for connectivity package
    N!build_auxiliary_node_connectivity!build_auxiliary_edge_connectivityT)returns_graphc                    U R                  5       n0 n[        R                  " 5       n[        U 5       HF  u  pEXBU'   UR	                  U S3US9  UR	                  U S3US9  UR                  U S3U S3SS9  MH     / nU R                  5        HH  u  pxUR                  X'    S3X(    S345        U(       a  M+  UR                  X(    S3X'    S345        MJ     UR                  USS9  X#R                  S'   U$ )a  Creates a directed graph D from an undirected graph G to compute flow
based node connectivity.

For an undirected graph G having `n` nodes and `m` edges we derive a
directed graph D with `2n` nodes and `2m+n` arcs by replacing each
original node `v` with two nodes `vA`, `vB` linked by an (internal)
arc in D. Then for each edge (`u`, `v`) in G we add two arcs (`uB`, `vA`)
and (`vB`, `uA`) in D. Finally we set the attribute capacity = 1 for each
arc in D [1]_.

For a directed graph having `n` nodes and `m` arcs we derive a
directed graph D with `2n` nodes and `m+n` arcs by replacing each
original node `v` with two nodes `vA`, `vB` linked by an (internal)
arc (`vA`, `vB`) in D. Then for each arc (`u`, `v`) in G we add one
arc (`uB`, `vA`) in D. Finally we set the attribute capacity = 1 for
each arc in D.

A dictionary with a mapping between nodes in the original graph and the
auxiliary digraph is stored as a graph attribute: D.graph['mapping'].

References
----------
.. [1] Kammer, Frank and Hanjo Taubig. Graph Connectivity. in Brandes and
    Erlebach, 'Network Analysis: Methodological Foundations', Lecture
    Notes in Computer Science, Volume 3418, Springer-Verlag, 2005.
    https://doi.org/10.1007/978-3-540-31955-9_7

A)idB   capacitymapping)
is_directednxDiGraph	enumerateadd_nodeadd_edgeedgesappendadd_edges_fromgraph)	Gdirectedr   Hinoder   sourcetargets	            ^/var/www/html/shao/venv/lib/python3.13/site-packages/networkx/algorithms/connectivity/utils.pyr   r   
   s   < }}HG


AQ<	

aS7t
$	

aS7t
$	

aS7qcGa
0	   E''))+/@-BCDxLLW_-Q/GO3DA1FGH $ UQ' !GGIH    c                    U R                  5       (       aT  [        R                  " 5       nUR                  U R	                  5       5        UR                  U R                  5       SS9  U$ [        R                  " 5       nUR                  U R	                  5       5        U R                  5        H  u  p#UR                  X#4X24/SS9  M     U$ )a*  Auxiliary digraph for computing flow based edge connectivity

If the input graph is undirected, we replace each edge (`u`,`v`) with
two reciprocal arcs (`u`, `v`) and (`v`, `u`) and then we set the attribute
'capacity' for each arc to 1. If the input graph is directed we simply
add the 'capacity' attribute. Part of algorithm 1 in [1]_ .

References
----------
.. [1] Abdol-Hossein Esfahanian. Connectivity Algorithms. (this is a
    chapter, look for the reference of the book).
    http://www.cse.msu.edu/~cse835/Papers/Graph_connectivity_revised.pdf
r
   r   )r   r   r   add_nodes_fromnodesr   r   )r   r   r   r   s       r   r   r   ?   s     	}}JJL	#	Q/JJL	#ggiNFv.0@AAN (r    )__doc__networkxr   __all___dispatchabler   r    r    r   <module>r)      sY    .0S
T %1 &1h % &r    