o
    ˷eJ                     @   sP  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  qe 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      h | ]
\}}|d kr|qS )	supported .0ndr   r   {/var/www/ideatree/venv/lib/python3.10/site-packages/../../../share/doc/networkx-2.8.6/examples/algorithms/plot_subgraphs.py	<setcomp>       z%graph_partitioning.<locals>.<setcomp>	node_typedatac                 S   r   )unsupportedr   r   r   r   r	   r
      r   c                 3   s@    | ]\}}| v r|  D ]\}}|v r|||fV  qqd S Nitemsr   r   nbrsnbrr   supported_nodesunsupported_nodesr   r	   	<genexpr>       z%graph_partitioning.<locals>.<genexpr>c                 3   s@    | ]\}}|v r|  D ]\}}| v r|||fV  qqd S r   r   r   r   r   r	   r   "   r   c                 S      g | ]\}}|qS r   r   )r   _cr   r   r	   
<listcomp>0       z&graph_partitioning.<locals>.<listcomp>
node_color   r"   figsize333333?kalpha
edge_colorr       	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/   r2   remove_edges_fromadjr   nxDiGraphadd_edges_fromsetedgesspring_layoutpltfiguredraw_networkx_edgesdraw_networkx_nodesdraw_networkx_labelsaxistitleshowconnected_componentsto_undirected)r0   plotting	G_minus_H_node_colors_posncl	subgraphsr   )r0   r3   r   r   r	   graph_partitioning   sD   	






rL   Ininputb)r   r    )ACEFr   gBDr   rOutoutputm))rM   rP   )rP   rU   )rU   rQ   )rU   rV   )rV   rR   )rQ   rS   )rR   rS   )rS   rX   c                 C   r   r   r   r   r   ncr   r   r	   r   n   r   r   r    r   r!   r#   r%   r&   r'   g?)r(   r    r+   r,   r.   zThe original graph.)rF   c                 C   r   r   r   r[   r   r   r	   r      r   r*   zOne of the subgraphs.c                 C   r   r   r   r[   r   r   r	   r      r   zThe reconstructed graph.)T) __doc__networkxr6   matplotlib.pyplotpyplotr<   rL   r7   G_exadd_nodes_fromr8   r/   node_color_listspectral_layoutposr=   r>   r?   r@   rA   rB   rC   subgraphs_of_G_exremoved_edgesr1   r;   rI   node_color_list_cG_ex_rcomposer:   is_isomorphicr   r   r   r	   <module>   s\    
H









