U
    ¹mœdJ  ã                
   @   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�q²e 
e ¡ ¡ e ee¡�sæt ‚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	ƒ ¡ |�rŽd	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 )z€Partition 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   ú{/home/sam/Atlas/atlas_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figsizeç333333Ó?Ú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øÿ








