ó
 ,µ[c           @   sÂ  d  Z  d Z d d d d d d d d	 d
 d d d d d d d d d d d d d d d g Z d d l Z d d l m Z m Z m Z m	 Z	 d d l
 m Z d d „ Z d d „ Z d d  „ Z d d! „ Z d d" „ Z d d# „ Z d d$ „ Z d d% „ Z d d& „ Z d d' „ Z d d( „ Z d) „  Z d d* „ Z d d+ „ Z d d, „ Z d d- „ Z d d. „ Z d d/ „ Z d0 „  Z d d1 „ Z  d d2 „ Z! d d3 „ Z" d d4 „ Z# d d5 „ Z$ d d6 „ Z% d S(7   sI   
Various small and named graphs, together with some compact generators.

s=   Aric Hagberg (hagberg@lanl.gov)
Pieter Swart (swart@lanl.gov)t   make_small_grapht	   LCF_grapht
   bull_grapht   chvatal_grapht   cubical_grapht   desargues_grapht   diamond_grapht   dodecahedral_grapht   frucht_grapht   heawood_grapht   hoffman_singleton_grapht   house_grapht   house_x_grapht   icosahedral_grapht   krackhardt_kite_grapht   moebius_kantor_grapht   octahedral_grapht   pappus_grapht   petersen_grapht   sedgewick_maze_grapht   tetrahedral_grapht   truncated_cube_grapht   truncated_tetrahedron_grapht   tutte_graphiÿÿÿÿN(   t   empty_grapht   cycle_grapht
   path_grapht   complete_graph(   t   NetworkXErrorc         C   s7   t  d | ƒ } | j ƒ  r* t d ƒ ‚ n  t |  | ƒ S(   sd   
    Return a small undirected graph described by graph_description.

    See make_small_graph.
    i    s   Directed Graph not supported(   R   t   is_directedR   R    (   t   graph_descriptiont   create_usingt   G(    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyt   make_small_undirected_graph0   s    c         C   sX  |  d } |  d } |  d } t  | | ƒ } | j ƒ  } | d k r® |  d } t | ƒ | k rp t d ƒ ‚ n  | j g  | D]' } | | D] }	 |	 d | f ^ q‹ q} ƒ n | d k rK|  d }
 x„ |
 D]y } | d d } | d d } | d k  s%| | d k s%| d k  s%| | d k r4t d ƒ ‚ qË | j | | ƒ qË Wn  | | _ | S(   sQ  
    Return the small graph described by graph_description.

    graph_description is a list of the form [ltype,name,n,xlist]

    Here ltype is one of "adjacencylist" or "edgelist",
    name is the name of the graph and n the number of nodes.
    This constructs a graph of n nodes with integer labels 0,..,n-1.

    If ltype="adjacencylist"  then xlist is an adjacency list
    with exactly n entries, in with the j'th entry (which can be empty)
    specifies the nodes connected to vertex j.
    e.g. the "square" graph C_4 can be obtained by

    >>> G=nx.make_small_graph(["adjacencylist","C_4",4,[[2,4],[1,3],[2,4],[1,3]]])

    or, since we do not need to add edges twice,

    >>> G=nx.make_small_graph(["adjacencylist","C_4",4,[[2,4],[3],[4],[]]])

    If ltype="edgelist" then xlist is an edge list
    written as [[v1,w2],[v2,w2],...,[vk,wk]],
    where vj and wj integers in the range 1,..,n
    e.g. the "square" graph C_4 can be obtained by

    >>> G=nx.make_small_graph(["edgelist","C_4",4,[[1,2],[3,4],[2,3],[4,1]]])

    Use the create_using argument to choose the graph class/type.
    i    i   i   t   adjacencylisti   s   invalid graph_descriptiont   edgelist(   R   t   nodest   lenR   t   add_edges_fromt   add_edget   name(   R   R   t   ltypeR(   t   nR    R$   t   adjlistt   vt   uR#   t   et   v1t   v2(    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR    <   s(    



>
8	c         C   sÝ   |  d k r t  d | ƒ St |  | ƒ } | j ƒ  rC t d ƒ ‚ n  d | _ t t | ƒ ƒ } | t | ƒ } | d k  r~ | SxX t | ƒ D]J } | | t | ƒ } | | |  }	 | | | |  }
 | j	 |	 |
 ƒ q‹ W| S(   s\  
    Return the cubic graph specified in LCF notation.

    LCF notation (LCF=Lederberg-Coxeter-Fruchte) is a compressed
    notation used in the generation of various cubic Hamiltonian
    graphs of high symmetry. See, for example, dodecahedral_graph,
    desargues_graph, heawood_graph and pappus_graph below.

    n (number of nodes)
      The starting graph is the n-cycle with nodes 0,...,n-1.
      (The null graph is returned if n < 0.)

    shift_list = [s1,s2,..,sk], a list of integer shifts mod n,

    repeats
      integer specifying the number of times that shifts in shift_list
      are successively applied to each v_current in the n-cycle
      to generate an edge between v_current and v_current+shift mod n.

    For v1 cycling through the n-cycle a total of k*repeats
    with shift cycling through shiftlist repeats times connect
    v1 with v1+shift mod n

    The utility graph $K_{3,3}$

    >>> G = nx.LCF_graph(6, [3, -3], 3)

    The Heawood graph

    >>> G = nx.LCF_graph(14, [5, -5], 7)

    See http://mathworld.wolfram.com/LCFNotation.html for a description
    and references.

    i    s   Directed Graph not supportedR   i   (
   R   R   R   R   R(   t   sortedt   listR%   t   rangeR'   (   R*   t
   shift_listt   repeatsR   R    R$   t   n_extra_edgest   it   shiftR/   R0   (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   s   s     $	c         C   sR   d d d d d g d d d g d d d g d g d g g g } t  | |  ƒ } | S(   s   Return the Bull graph. R"   s
   Bull Graphi   i   i   i   i   (   R!   (   R   t   descriptionR    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   ³   s    6c         C   s‘   d d d d d d d g d d	 d
 g d d d g d d
 d g d	 d g d d g d d g d d g d g d d g g  g  g g } t  | |  ƒ } | S(   s   Return the ChvÃ¡tal graph.R"   s   Chvatal Graphi   i   i   i   i
   i   i   i   i   i	   i   (   R!   (   R   R9   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   ¿   s    3$c         C   s…   d d d d d d g d d d g d d d	 g d d d
 g d d
 d g d d d	 g d d
 d g d d d	 g g g } t  | |  ƒ } | S(   s,   Return the 3-regular Platonic Cubical graph.R"   s   Platonic Cubical Graphi   i   i   i   i   i   i   i   (   R!   (   R   R9   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   Í   s    09c         C   s.   t  d d d d d g d |  ƒ } d | _ | S(   s    Return the Desargues graph.i   i   iûÿÿÿi	   i÷ÿÿÿs   Desargues Graph(   R   R(   (   R   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   Ú   s    !	c         C   sO   d d d d d g d d d g d d d g d d g g g } t  | |  ƒ } | S(   s   Return the Diamond graph. R"   s   Diamond Graphi   i   i   i   (   R!   (   R   R9   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   á   s    3c         C   s@   t  d d d d d d d d d d d g
 d |  ƒ } d | _ | S(	   s)    Return the Platonic Dodecahedral graph. i   i
   i   i   iüÿÿÿiùÿÿÿi   s   Dodecahedral Graph(   R   R(   (   R   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   í   s    3	c         C   sŒ   t  d |  ƒ } | j d d g d d g d d g d d g d d g d	 d
 g d d
 g d d g d d g d d g d
 d g g ƒ d | _ | S(   s–   Return the Frucht Graph.

    The Frucht Graph is the smallest cubical graph whose
    automorphism group consists only of the identity element.

    i   i    i   i   i   i   i	   i   i   i
   i   i   s   Frucht Graph(   R   R&   R(   (   R   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   ô   s
    E+	c         C   s(   t  d d d g d |  ƒ } d | _ | S(   s)    Return the Heawood graph, a (3,6) cage. i   i   iûÿÿÿi   s   Heawood Graph(   R   R(   (   R   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR	     s    	c       	   C   sC  t  j ƒ  }  xt d ƒ D]
} xt d ƒ D]ó } |  j d | | f d | | d d f ƒ |  j d | | f d | | d d f ƒ |  j d | | f d | | d d f ƒ |  j d | | f d | | d d f ƒ xB t d ƒ D]4 } |  j d | | f d | | | | d f ƒ qç Wq, Wq Wt  j |  ƒ }  d |  _ |  S(   s#   Return the Hoffman-Singleton Graph.i   t   pentagoni   t	   pentagrami   s   Hoffman-Singleton Graph(   t   nxt   GraphR3   R'   t   convert_node_labels_to_integersR(   (   R    R7   t   jt   k(    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR
   
  s    ****(	c      	   C   sX   d d d d d g d d g d d d g d d d g d d g g g } t  | |  ƒ } | S(   s5   Return the House graph (square with triangle on top).R"   s   House Graphi   i   i   i   i   (   R!   (   R   R9   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR     s    <c      
   C   sd   d d d d d d g d d d g d d d d g d d d d g d d g g g } t  | |  ƒ } | S(   s<   Return the House graph with a cross inside the house square.R"   s   House-with-X-inside Graphi   i   i   i   i   (   R!   (   R   R9   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   '  s    Hc         C   s£   d d d d d d d d g d d d	 d g d
 d	 d d g d d	 d d g d d	 d d g d	 d g g  d d d d g d g d g d g g  g g } t  | |  ƒ } | S(   s&   Return the Platonic Icosahedral graph.R"   s   Platonic Icosahedral Graphi   i   i   i   i	   i   i   i   i
   i   i   (   R!   (   R   R9   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   3  s    ?*c         C   s¯   d d d d d d d g d d d	 d
 g d d d g d d d d	 d d
 g d d d
 g d d d d
 d g d d d	 d d g d d
 d g d d g d g g
 g } t  | |  ƒ } | S(   s=  
    Return the Krackhardt Kite Social Network.

    A 10 actor social network introduced by David Krackhardt
    to illustrate: degree, betweenness, centrality, closeness, etc.
    The traditional labeling is:
    Andre=1, Beverley=2, Carol=3, Diane=4,
    Ed=5, Fernando=6, Garth=7, Heather=8, Ike=9, Jane=10.

    R"   s   Krackhardt Kite Social Networki
   i   i   i   i   i   i   i   i   i	   (   R!   (   R   R9   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   A  s    KHc         C   s(   t  d d d g d |  ƒ } d | _ | S(   s    Return the Moebius-Kantor graph.i   i   iûÿÿÿi   s   Moebius-Kantor Graph(   R   R(   (   R   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   W  s    	c      	   C   s[   d d d d d d d g d d d g d d g d d g d g g  g g } t  | |  ƒ } | S(   s%   Return the Platonic Octahedral graph.R"   s   Platonic Octahedral Graphi   i   i   i   i   (   R!   (   R   R9   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   ^  s    ?c          C   s1   t  d d d d d d d g d ƒ }  d |  _ |  S(   s    Return the Pappus graph.i   i   i   iùÿÿÿiûÿÿÿi   s   Pappus Graph(   R   R(   (   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   j  s    $	c         C   s   d d d d d d g d d d	 g d d
 d g d d d g d
 d d g d d d g d d d g d d d g d
 d d	 g d d	 d g g
 g } t  | |  ƒ } | S(   s   Return the Petersen graph.R"   s   Petersen Graphi
   i   i   i   i   i   i   i   i   i	   (   R!   (   R   R9   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   q  s    T-c         C   s½   t  d |  ƒ } | j t d ƒ ƒ | j d d g d d g d d g g ƒ | j d d g d d g g ƒ | j d d	 g d d g g ƒ | j d	 d g d	 d g d	 d g g ƒ d
 | _ | S(   sÈ   
    Return a small maze with a cycle.

    This is the maze used in Sedgewick,3rd Edition, Part 5, Graph
    Algorithms, Chapter 18, e.g. Figure 18.2 and following.
    Nodes are numbered 0,..,7
    i    i   i   i   i   i   i   i   i   s   Sedgewick Maze(   R   t   add_nodes_fromR3   R&   R(   (   R   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   ~  s    ((	c         C   s   t  d |  ƒ } d | _ | S(   s1    Return the 3-regular Platonic Tetrahedral graph.i   s   Platonic Tetrahedral graph(   R   R(   (   R   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR     s    	c         C   sÙ   d d d d d d g d d g d	 d g d
 d g d g d d g d d g d d g d g d d g d d g d g d g d d g d g d d g d d g d g d g d g d g d g d g g  g g } t  | |  ƒ } | S(   s*   Return the skeleton of the truncated cube.R"   s   Truncated Cube Graphi   i   i   i   i   i   i   i   i	   i   i   i   i   i   i   i
   i   i   i   i   i   i   i   (   R!   (   R   R9   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   —  s    '!c      	   C   s>   t  d |  ƒ } | j d d d d d d d g ƒ d | _ | S(   s:   Return the skeleton of the truncated Platonic tetrahedron.i   i    i   i	   i   i   i   i   i   i   i   i   i
   s   Truncated Tetrahedron Graph(   i    i   (   i    i	   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i
   (   R   R&   R(   (   R   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   ¨  s    "	c      1   C   s~  d d d d d d g d d g d	 d
 g d d g d d g d d g d d g d d g d d g d	 d g d g d d g d d g d d g d g d d g d  d! g d d" g d g d# d g d$ d% g d d& g d' g d( d g d) d* g d d+ g d g d, g d d* g d- g d+ d g d* g g  g  d d g d. g d d g d g g  g  d% d! g d/ g d" d g d! g g  g  g. g } t  | |  ƒ } | S(0   s   Return the Tutte graph.R"   s   Tutte's Graphi.   i   i   i   i   i   i   i   i   i   i   i"   i   i   i   i   i	   i   i
   i'   i&   i(   i   i   i$   i   i#   i   i   i   i-   i,   i   i   i*   i   i)   i   i   i!   i    i   i   i%   i+   (   R!   (   R   R9   R    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyR   ±  s    0-'**$-(&   t   __doc__t
   __author__t   __all__t   networkxR<   t   networkx.generators.classicR   R   R   R   t   networkx.exceptionR   t   NoneR!   R    R   R   R   R   R   R   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s8   lib/python2.7/site-packages/networkx/generators/small.pyt   <module>   sj   	"7@			