HEX
Server: LiteSpeed
System: Linux ratab.tasjeel.ae 4.18.0-553.30.1.lve.el8.x86_64 #1 SMP Tue Dec 3 01:21:19 UTC 2024 x86_64
User: arhamste (1605)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/ipapython/__pycache__/graph.cpython-36.pyc
3

�d[e�	�@sddlmZGdd�d�ZdS)�)�dequec@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
ddd�ZdS)�Graphz�
    Simple oriented graph structure

    G = (V, E) where G is graph, V set of vertices and E list of edges.
    E = (tail, head) where tail and head are vertices
    cCst�|_g|_t�|_dS)N)�set�vertices�edges�dict�_adj)�self�r
�/usr/lib/python3.6/graph.py�__init__szGraph.__init__cCs|jj|�g|j|<dS)N)r�addr)r	�vertexr
r
r�
add_vertexszGraph.add_vertexcCsH||jkrtd��||jkr$td��|jj||f�|j|j|�dS)Nztail is not a vertexzhead is not a vertex)r�
ValueErrorr�appendr)r	�tail�headr
r
r�add_edges

zGraph.add_edgecCsNy|jj||f�Wn$tk
r8tdj||���YnX|j|j|�dS)Nz'graph does not contain edge: ({0}, {1}))r�remove�KeyErrorr�formatr)r	rrr
r
r�remove_edge"szGraph.remove_edgec
s�y|jj��Wn"tk
r2tdj����YnX|j�=x,|jj�D]}�fdd�|D�|dd�<qHW�fdd�|jD�|_dS)Nz"graph does not contain vertex: {0}csg|]}|�kr|�qSr
r
)�.0�v)rr
r�
<listcomp>6sz'Graph.remove_vertex.<locals>.<listcomp>cs$g|]}�|d|dfkr|�qS)r�r
)r�e)rr
rr:s)rrrrrr�valuesr)r	rZadjr
)rr�
remove_vertex+szGraph.remove_vertexcs�fdd�|jD�S)zU
        Get list of vertices where a vertex is on the right side of an edge
        cs g|]}|d�kr|d�qS)rrr
)rr)rr
rrAsz#Graph.get_tails.<locals>.<listcomp>)r)r	rr
)rr�	get_tails=szGraph.get_tailscs�fdd�|jD�S)zT
        Get list of vertices where a vertex is on the left side of an edge
        cs g|]}|d�kr|d�qS)rrr
)rr)rr
rrGsz#Graph.get_heads.<locals>.<listcomp>)r)r	rr
)rr�	get_headsCszGraph.get_headsNcCsf|stt|j��}t�}t|g�}x>|r`|j�}||kr$|j|�|jt|jj	|g��|�q$W|S)z
        Breadth-first search traversal of the graph from `start` vertex.
        Return a set of all visited vertices
        )
�next�iterrrr�popleftr
�extendr�get)r	�startZvisitedZqueuerr
r
r�bfsIs

 z	Graph.bfs)N)�__name__�
__module__�__qualname__�__doc__rrrrrr r!r(r
r
r
rrs
	rN)�collectionsrrr
r
r
r�<module>s