3
Médm  ã               @   s(   d Z ddlZddgZdd„ Zdd„ ZdS )z$
Utilities for connectivity package
é    NÚ!build_auxiliary_node_connectivityÚ!build_auxiliary_edge_connectivityc       	      C   sô   | j ƒ }i }tjƒ }x`t| ƒD ]T\}}|||< |j|› d|d |j|› d|d |j|› d|› ddd qW g }x\| jƒ D ]P\}}|j|| › d|| › dfƒ |s„|j|| › d|| › dfƒ q„W |j|dd ||j	d< |S )aT  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: 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

    ÚA)ÚidÚBé   )ÚcapacityÚmapping)
Úis_directedÚnxÚDiGraphÚ	enumerateÚadd_nodeZadd_edgeÚedgesÚappendÚadd_edges_fromÚgraph)	ÚGZdirectedr	   ÚHÚiÚnoder   ÚsourceÚtarget© r   úX/var/www/html/virt/lib/python3.6/site-packages/networkx/algorithms/connectivity/utils.pyr   	   s      "&
c             C   s‚   | j ƒ r4tjƒ }|j| jƒ ƒ |j| jƒ dd |S tjƒ }|j| jƒ ƒ x.| jƒ D ]"\}}|j||f||fgdd qTW |S dS )aR  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   N)r
   r   r   Zadd_nodes_fromZnodesr   r   )r   r   r   r   r   r   r   r   =   s    )Ú__doc__Znetworkxr   Ú__all__r   r   r   r   r   r   Ú<module>   s   4