a
    dJ                     @   sV  d Z ddlZddlmZ d*ddZe Zej	dgddd	 ej	g d
ddd	 ej	ddgddd	 ej	dgddd	 e
g d 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d& ejeed d! ed" ed' e  qe ZeD ]ZeeeZqe
e  eeesJ 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  dS )+a3  
=========
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/stable-diffusion-webui/venv/lib/python3.9/site-packages/../../../share/doc/networkx-3.1/examples/algorithms/plot_subgraphs.py	<setcomp>       z%graph_partitioning.<locals>.<setcomp>	node_typedatac                 S   s   h | ]\}}|d kr|qS )unsupportedr   r   r   r   r   r	      r
   c                 3   s>   | ]6\}}| v r|  D ]\}}|v 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\}}|v r|  D ]\}}| v 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   r
   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   <   r
   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_posZ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   Zncr   r   r   r   n   r
   r   r   r   r   r   r   r   r    g?)r!   r   r#   r$   r%   zThe original graph.)r9   c                 C   s   g | ]\}}|qS r   r   rJ   r   r   r   r      r
   r"   zOne of the subgraphs.c                 C   s   g | ]\}}|qS r   r   rJ   r   r   r   r      r
   zThe reconstructed graph.)T) __doc__Znetworkxr+   Zmatplotlib.pyplotZpyplotr1   r;   r,   ZG_exZadd_nodes_fromr-   r&   Znode_color_listZspectral_layoutposr2   r3   r4   r5   r6   r7   r8   Zsubgraphs_of_G_exZremoved_edgesr(   r0   r:   Znode_color_list_cZG_ex_rZcomposer/   Zis_isomorphicr   r   r   r   <module>   sZ   
H








