ó
|£*^c           @   sF   d  Z  d d l Z d d l Z d d g Z d d „ Z d d „ Z d S(   s5   Provides explicit constructions of expander graphs.

iÿÿÿÿNt   margulis_gabber_galil_grapht   chordal_cycle_graphc         C   s1  | d k r t j ƒ  } n1 | j ƒ  s4 | j ƒ  rL d } t j | ƒ ‚ n  | } | j ƒ  x¸ t j t	 |  ƒ d d ƒD]› \ } } xŒ | d | |  | f | d | d |  | f | | d | |  f | | d | d |  f f D]( \ } } | j
 | | f | | f ƒ qç Wqx Wd j |  ƒ | j d <| S(   sÞ  Return the Margulis-Gabber-Galil undirected MultiGraph on `n^2` nodes.

    The undirected MultiGraph is regular with degree `8`. Nodes are integer
    pairs. The second-largest eigenvalue of the adjacency matrix of the graph
    is at most `5 \sqrt{2}`, regardless of `n`.

    Parameters
    ----------
    n : int
        Determines the number of nodes in the graph: `n^2`.
    create_using : graph-like
        A graph-like object that receives the constructed edges. If ``None``,
        then a :class:`~networkx.MultiGraph` instance is used.

    Returns
    -------
    G : graph
        The constructed undirected multigraph.

    Raises
    ------
    NetworkXError
        If the graph is directed or not a multigraph.

    s0   `create_using` must be an undirected multigraph.t   repeati   i   s    margulis_gabber_galil_graph({0})t   nameN(   t   Nonet   nxt
   MultiGrapht   is_directedt   is_multigrapht   NetworkXErrort   cleart	   itertoolst   productt   ranget   add_edget   formatt   graph(   t   nt   create_usingt   msgt   Gt   xt   yt   ut   v(    (    sq   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/expanders.pyR    .   s    
(1>$c   	      C   sû   | d k r t j ƒ  } n1 | j ƒ  s4 | j ƒ  rL d } t j | ƒ ‚ n  | } | j ƒ  x‚ t |  ƒ D]t } | d |  } | d |  } | d k r­ t | |  d |  ƒ n d } x' | | | f D] } | j	 | | ƒ qÃ Wqi Wd j
 |  ƒ | j d <| S(   s/  Return the chordal cycle graph on `p` nodes.

    The returned graph is a cycle graph on `p` nodes with chords joining each
    vertex `x` to its inverse modulo `p`. This graph is a (mildly explicit)
    3-regular expander [1]_.

    ``p`` *must* be a prime number.

    Parameters
    ----------
    p : a prime number

        The number of vertices in the graph. This also indicates where the
        chordal edges in the cycle will be created.

    create_using : graph-like
        A graph-like object that receives the constructed edges. If ``None``,
        then a :class:`~networkx.MultiGraph` instance is used.

    Returns
    -------
    G : graph
        The constructed undirected multigraph.

    Raises
    ------
    NetworkXError

        If the graph provided in ``create_using`` is directed or not a
        multigraph.

    References
    ----------

    .. [1] Theorem 4.4.2 in A. Lubotzky. "Discrete groups, expanding graphs and
           invariant measures", volume 125 of Progress in Mathematics.
           BirkhÃ¤user Verlag, Basel, 1994.

    s0   `create_using` must be an undirected multigraph.i   i    i   s   chordal_cycle_graph({0})R   N(   R   R   R   R   R   R	   R
   R   t   powR   R   R   (	   t   pR   R   R   R   t   leftt   rightt   chordR   (    (    sq   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/expanders.pyR   X   s    (
((   t   __doc__R   t   networkxR   t   __all__R   R    R   (    (    (    sq   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/expanders.pyt   <module>   s
   #*