ó
 ,µ[c           @   s'  d  Z  d d l m Z m Z m Z m Z m Z d d l m Z d d l	 m
 Z
 m Z d d l m Z m Z m Z m Z d d l Z d d d	 d
 d d d d d d d d d g Z d d „ Z e e d „ Z d „  Z d „  Z e e d „ Z d „  Z d „  Z d „  Z d „  Z e Z e Z Z  Z! d S(   s»  View of Graphs as SubGraph, Reverse, Directed, Undirected.

In some algorithms it is convenient to temporarily morph
a graph to exclude some nodes or edges. It should be better
to do that via a view than to remove and then re-add.
In other algorithms it is convenient to temporarily morph
a graph to reverse directed edges, or treat a directed graph
as undirected, etc. This module provides those graph views.

The resulting views are essentially read-only graphs that
report data from the orignal graph object. We provide an
attribute G._graph which points to the underlying graph object.

Note: Since graphviews look like graphs, one can end up with
view-of-view-of-view chains. Be careful with chains because
they become very slow with about 15 nested views.
For the common simple case of node induced subgraphs created
from the graph class, we short-cut the chain by returning a
subgraph of the original graph directly rather than a subgraph
of a subgraph. We are careful not to disrupt any edge filter in
the middle subgraph. In general, determining how to short-cut
the chain is tricky and much harder with restricted_views than
with induced subgraphs.
Often it is easiest to use .copy() to avoid chains.
iÿÿÿÿ(   t   UnionAdjacencyt   UnionMultiAdjacencyt   FilterAtlast   FilterAdjacencyt   FilterMultiAdjacency(   t	   no_filter(   t   NetworkXErrort   NetworkXNotImplemented(   t   Grapht   DiGrapht
   MultiGrapht   MultiDiGraphNt   generic_graph_viewt   subgraph_viewt   reverse_viewt   SubGrapht
   SubDiGrapht   SubMultiGrapht   SubMultiDiGrapht   ReverseViewt   MultiReverseViewt   DiGraphViewt   MultiDiGraphViewt	   GraphViewt   MultiGraphViewc         C   sH  | d  k r |  j ƒ  } n t j d | ƒ } |  j ƒ  | j ƒ  k rT t d ƒ ‚ n  t j | ƒ } |  | _ |  j | _ |  j	 | _	 | j
 ƒ  rê |  j
 ƒ  rÃ |  j | _ |  j | _ |  j | _ qD|  j | _ |  j | _ |  j | _ nZ |  j
 ƒ  r8|  j ƒ  rt |  j |  j ƒ | _ qDt |  j |  j ƒ | _ n |  j | _ | S(   Ni    s-   Multigraph for G must agree with create_using(   t   Nonet	   __class__t   nxt   empty_grapht   is_multigraphR   t   freezet   _grapht   grapht   _nodet   is_directedt   _succt   _predt   _adjR   R    (   t   Gt   create_usingt   newG(    (    s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyR   5   s.    	c            sñ   t  j |  j ƒ  ƒ } | | _ ˆ  | _ |  | _ |  j | _ t |  j | ƒ | _ |  j	 ƒ  ru t
 } ‡  f d †  } n t } ‡  f d †  } |  j ƒ  rÕ | |  j | ˆ  ƒ | _ | |  j | | ƒ | _ | j | _ n | |  j | ˆ  ƒ | _ | S(   Nc            s   ˆ  | |  | ƒ S(   N(    (   t   ut   vt   k(   t   filter_edge(    s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyt   reverse_edgec   s    c            s   ˆ  | |  ƒ S(   N(    (   R)   R*   (   R,   (    s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyR-   g   s    (   R   R   R   t   _NODE_OKt   _EDGE_OKR   R    R   R!   R   R   R   R"   R#   R$   R%   (   R&   t   filter_nodeR,   R(   t   AdjR-   (    (   R,   s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyR   V   s"    			c         C   sV   |  j  ƒ  s! d } t | ƒ ‚ n  t |  ƒ } |  j |  j | _ | _ | j | _ | S(   Ns#   not implemented for undirected type(   R"   R   R   R$   R#   R%   (   R&   t   msgR(   (    (    s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyR   q   s    c         C   s5   d d  l  } d } | j | d t d d ƒt |  ƒ S(   Niÿÿÿÿs3   ReverseView is deprecated. Use reverse_view insteadt   categoryt
   stackleveli   (   t   warningst   warnt   DeprecationWarningR   (   R&   R5   R2   (    (    s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyR   |   s    c         C   s;   d d  l  } d } | j | d t d d ƒt |  | | ƒ S(   Niÿÿÿÿs1   SubGraph is deprecated. Use subgraph_view insteadR3   R4   i   (   R5   R6   R7   R   (   R&   R0   R,   R5   R2   (    (    s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyR   „   s    c         C   s8   d d  l  } d } | j | d t d d ƒt |  t ƒ S(   Niÿÿÿÿs7   GraphView is deprecated. Use generic_graph_view insteadR3   R4   i   (   R5   R6   R7   R   R   (   R&   R5   R2   (    (    s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyR   Œ   s    c         C   s8   d d  l  } d } | j | d t d d ƒt |  t ƒ S(   Niÿÿÿÿs7   GraphView is deprecated. Use generic_graph_view insteadR3   R4   i   (   R5   R6   R7   R   R	   (   R&   R5   R2   (    (    s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyR   ”   s    c         C   s8   d d  l  } d } | j | d t d d ƒt |  t ƒ S(   Niÿÿÿÿs7   GraphView is deprecated. Use generic_graph_view insteadR3   R4   i   (   R5   R6   R7   R   R
   (   R&   R5   R2   (    (    s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyR   œ   s    c         C   s8   d d  l  } d } | j | d t d d ƒt |  t ƒ S(   Niÿÿÿÿs7   GraphView is deprecated. Use generic_graph_view insteadR3   R4   i   (   R5   R6   R7   R   R   (   R&   R5   R2   (    (    s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyR   ¤   s    ("   t   __doc__t   networkx.classes.coreviewsR    R   R   R   R   t   networkx.classes.filtersR   t   networkx.exceptionR   R   t   networkx.classesR   R	   R
   R   t   networkxR   t   __all__R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s:   lib/python2.7/site-packages/networkx/classes/graphviews.pyt   <module>#   s*   ("	!						