ó žÃÒYc@sFdZddlZdjdgƒZddgZd„Zd„ZdS( s$ Utilities for connectivity package iÿÿÿÿNs s%Jordi Torrents t!build_auxiliary_node_connectivityt!build_auxiliary_edge_connectivityc Cs'|jƒ}i}tjƒ}xpt|ƒD]b\}}|||<|jd|d|ƒ|jd|d|ƒ|jd|d|ddƒq+Wg}xi|jƒD][\}}|jd||d||fƒ|s¤|jd||d||fƒq¤q¤W|j|ddƒ||j d<|S( sUCreates 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: H.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. http://www.informatik.uni-augsburg.de/thi/personen/kammer/Graph_Connectivity.pdf s%dAtids%dBtcapacityis%sBs%sAtmapping( t is_directedtnxtDiGrapht enumeratetadd_nodetadd_edgetedgestappendtadd_edges_fromtgraph( tGtdirectedRtHtitnodeR tsourcettarget((s|/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/utils.pyR s    "#* cCs±|jƒrHtjƒ}|j|jƒƒ|j|jƒddƒ|Stjƒ}|j|jƒƒx?|jƒD]1\}}|j||f||fgddƒqtW|SdS(sRAuxiliary 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 RiN(RRRtadd_nodes_fromtnodesR R (RRRR((s|/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/utils.pyRAs   )(t__doc__tnetworkxRtjoint __author__t__all__RR(((s|/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/connectivity/utils.pyts    4