ó
 ,ľ[c           @   s_   d  Z  d d l Z d d l m Z d d g Z e d  e d  d d	    Z d
   Z d S(   sT   Functions related to the Mycielski Operation and the Mycielskian family
of graphs.

i˙˙˙˙N(   t   not_implemented_fort   mycielskiant   mycielski_grapht   directedt
   multigraphi   c            sÜ   |  j      t j |   } xş t |  D]Ź } | j      | j t   d     t | j    } | j   f d   | D  | j   f d   | D  | j d    | j   f d   t    D  q( W| S(   s_  Returns the Mycielskian of a simple, undirected graph G

    The Mycielskian of graph preserves a graph's triangle free
    property while increasing the chromatic number by 1.

    The Mycielski Operation on a graph, :math:`G=(V, E)`, constructs a new
    graph with :math:`2|V| + 1` nodes and :math:`3|E| + |V|` edges.

    The construction is as follows:

    Let :math:`V = {0, ..., n-1}`. Construct another vertex set
    :math:`U = {n, ..., 2n}` and a vertex, `w`.
    Construct a new graph, `M`, with vertices :math:`U \bigcup V \bigcup w`.
    For edges, :math:`(u, v) \in E` add edges :math:`(u, v), (u, v + n)`, and
    :math:`(u + n, v)` to M. Finally, for all vertices :math:`u \in U`, add
    edge :math:`(u, w)` to M.

    The Mycielski Operation can be done multiple times by repeating the above
    process iteratively.

    More information can be found at https://en.wikipedia.org/wiki/Mycielskian

    Parameters
    ----------
    G : graph
        A simple, undirected NetworkX graph
    iterations : int
        The number of iterations of the Mycielski operation to
        perform on G. Defaults to 1. Must be a non-negative integer.

    Returns
    -------
    M : graph
        The Mycielskian of G after the specified number of iterations.

    Notes
    ------
    Graph, node, and edge data are not necessarily propagated to the new graph.

    i   c         3   s%   |  ] \ } } | |   f Vq d  S(   N(    (   t   .0t   ut   v(   t   n(    s<   lib/python2.7/site-packages/networkx/generators/mycielski.pys	   <genexpr>F   s    c         3   s%   |  ] \ } } |   | f Vq d  S(   N(    (   R   R   R   (   R   (    s<   lib/python2.7/site-packages/networkx/generators/mycielski.pys	   <genexpr>G   s    c         3   s#   |  ] } |   d    f Vq d S(   i   N(    (   R   R   (   R   (    s<   lib/python2.7/site-packages/networkx/generators/mycielski.pys	   <genexpr>I   s    (	   t   number_of_nodest   nxt   convert_node_labels_to_integerst   ranget   add_nodes_fromt   listt   edgest   add_edges_fromt   add_node(   t   Gt
   iterationst   Mt   it	   old_edges(    (   R   s<   lib/python2.7/site-packages/networkx/generators/mycielski.pyR      s    ,'c         C   sU   |  d k  r t  j d   n  |  d k r7 t  j d  St t  j d  |  d  Sd S(   s  Generator for the n_th Mycielski Graph.

    The Mycielski family of graphs is an infinite set of graphs.
    :math:`M_1` is the singleton graph, :math:`M_2` is two vertices with an
    edge, and, for :math:`i > 2`, :math:`M_i` is the Mycielskian of
    :math:`M_{i-1}`.

    More information can be found at
    http://mathworld.wolfram.com/MycielskiGraph.html

    Parameters
    ----------
    n : int
        The desired Mycielski Graph.

    Returns
    -------
    M : graph
        The n_th Mycielski Graph

    Notes
    -----
    The first graph in the Mycielski sequence is the singleton graph.
    The Mycielskian of this graph is not the :math:`P_2` graph, but rather the
    :math:`P_2` graph with an extra, isolated vertex. The second Mycielski
    graph is the :math:`P_2` graph, so the first two are hard coded.
    The remaining graphs are generated using the Mycielski operation.

    i   s   must satisfy n >= 0i   N(   R
   t   NetworkXErrort   empty_graphR   t
   path_graph(   R   (    (    s<   lib/python2.7/site-packages/networkx/generators/mycielski.pyR   N   s
    (   t   __doc__t   networkxR
   t   networkx.utilsR    t   __all__R   R   (    (    (    s<   lib/python2.7/site-packages/networkx/generators/mycielski.pyt   <module>   s   		9