U
    9%eJ                  
   @   sf  d Z ddlZddlmZ d4ddZe Zej	dgddd	 ej	d
dddgddd	 ej	ddgddd	 ej	dgddd	 e
ddddddddg dd  ejd!d"D ZeeZejd#d$ ejeed%d&d' ejeed(ed) ejeed*d+ ed, ed- e  eedd.\ZZeD ]ZeeZejd#d$ ejeed%d&d' d/d  ejd!d"D Zejeeed0 ejeed*d+ ed, ed1 e  q$e ZeD ]ZeeeZqe
e  eeest d2d  ejd!d"D ZeeZejd#d$ ejeed%d&d' ejeed(ed) ejeed*d+ ed, ed3 e  dS )5a3  
=========
Subgraphs
=========
Example of partitioning a directed graph with nodes labeled as
supported and unsupported nodes into a list of subgraphs
that contain only entirely supported or entirely unsupported nodes.
Adopted from 
https://github.com/lobpcg/python_examples/blob/master/networkx_example.py
    NTc                    s  dd  j ddD dd  j ddD   fdd j D  fdd j D  t }|t j	tj	  |rd	d
 j ddD }t
}tjdd tj|ddd tj||d tj|dd td td t  t
|}tjdd  fdd
|j D }tj||ddd tj|||d tj||dd td td t  fdd
t D }||fS )zPartition a directed graph into a list of subgraphs that contain
    only entirely supported or entirely unsupported nodes.
    c                 S   s   h | ]\}}|d kr|qS )	supported .0ndr   r   /var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/../../../share/doc/networkx-3.1/examples/algorithms/plot_subgraphs.py	<setcomp>   s      z%graph_partitioning.<locals>.<setcomp>	node_typedatac                 S   s   h | ]\}}|d kr|qS )unsupportedr   r   r   r   r   r	      s      c                 3   s>   | ]6\}}| kr|  D ]\}}|kr|||fV  qqd S Nitemsr   r   ZnbrsZnbrr   supported_nodesunsupported_nodesr   r   	<genexpr>   s   
 z%graph_partitioning.<locals>.<genexpr>c                 3   s>   | ]6\}}|kr|  D ]\}}| kr|||fV  qqd S r   r   r   r   r   r   r   "   s   
 c                 S   s   g | ]\}}|qS r   r   )r   _cr   r   r   
<listcomp>0   s     z&graph_partitioning.<locals>.<listcomp>
node_color   r   Zfigsize333333?kalphaZ
edge_colorr      Z	font_sizeoffz*The stripped graph with the edges removed.c                    s   g | ]} j | d  qS r!   )nodes)r   r   )Gr   r   r   <   s     zThe removed edges.c                    s   g | ]}  | qS r   )subgraphcopy)r   r   )Hr   r   r   H   s    )r%   r(   Zremove_edges_fromZadjr   nxDiGraphadd_edges_fromsetedgesspring_layoutpltfiguredraw_networkx_edgesdraw_networkx_nodesdraw_networkx_labelsaxistitleshowZconnected_componentsZto_undirected)r&   plottingZ	G_minus_HZ_node_colors_posnclZ	subgraphsr   )r&   r)   r   r   r   graph_partitioning   sD    	






r;   Ininputb)r
   r   ACEFr   gBDr   rOutoutputm)r<   r?   )r?   rD   )rD   r@   )rD   rE   )rE   rA   )r@   rB   )rA   rB   )rB   rG   c                 C   s   g | ]\}}|qS r   r   r   r   ncr   r   r   r   n   s     r   r   r   r   r   r   r   r   g?)r    r   r"   r#   r$   zThe original graph.)r8   c                 C   s   g | ]\}}|qS r   r   rJ   r   r   r   r      s     r!   zOne of the subgraphs.c                 C   s   g | ]\}}|qS r   r   rJ   r   r   r   r      s     zThe reconstructed graph.)T)!__doc__Znetworkxr*   Zmatplotlib.pyplotZpyplotr0   r;   r+   ZG_exZadd_nodes_fromr,   r%   Znode_color_listZspectral_layoutposr1   r2   r3   r4   r5   r6   r7   Zsubgraphs_of_G_exZremoved_edgesr'   r/   r9   Znode_color_list_cZG_ex_rZcomposer.   Zis_isomorphicAssertionErrorr   r   r   r   <module>   sj   
H








