ó
|£*^c           @   s˜  d  Z  d j d d d g ƒ Z d d l Z d d l Z d d l Z d d l Z d d l m	 Z	 m
 Z
 m Z d d l m Z d	 d
 d d d d d d d d d d d d d d d g Z d e d „ Z d e d „ Z e Z e Z d d „ Z d e d „ Z d d „ Z d d „ Z d  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 d  d* „ Z! d) d d  d+ „ Z" d S(,   s    
Generators for random graphs.

s   
s   Aric Hagberg (hagberg@lanl.gov)s   Pieter Swart (swart@lanl.gov)s    Dan Schult (dschult@colgate.edu)iÿÿÿÿN(   t   empty_grapht
   path_grapht   complete_graph(   t   defaultdictt   fast_gnp_random_grapht   gnp_random_grapht   dense_gnm_random_grapht   gnm_random_grapht   erdos_renyi_grapht   binomial_grapht   newman_watts_strogatz_grapht   watts_strogatz_grapht   connected_watts_strogatz_grapht   random_regular_grapht   barabasi_albert_grapht   powerlaw_cluster_grapht   duplication_divergence_grapht   random_lobstert   random_shell_grapht   random_powerlaw_treet   random_powerlaw_tree_sequencec   	      C   s  t  |  ƒ } d |  | f | _ | d k	 r; t j | ƒ n  | d k sS | d k ri t j |  | d | ƒSd } t j d | ƒ } | rht j	 | ƒ } d } xd| |  k  rdt j d t j ƒ  ƒ } | d t
 | | ƒ } | | k rö | d } n  xI | |  k rA| |  k  rA| |  } | d } | | k rù | d } qù qù W| |  k  r  | j | | ƒ q  q  Wnœ d } x“ | |  k  rt j d t j ƒ  ƒ } | d t
 | | ƒ } x0 | | k rà| |  k  rà| | } | d } q±W| |  k  rq| j | | ƒ qqqqW| S(   s=  Returns a `G_{n,p}` random graph, also known as an ErdÅ‘s-RÃ©nyi graph or
    a binomial graph.

    Parameters
    ----------
    n : int
        The number of nodes.
    p : float
        Probability for edge creation.
    seed : int, optional
        Seed for random number generator (default=None).
    directed : bool, optional (default=False)
        If ``True``, this function returns a directed graph.

    Notes
    -----
    The `G_{n,p}` graph algorithm chooses each of the `[n (n - 1)] / 2`
    (undirected) or `n (n - 1)` (directed) possible edges with probability `p`.

    This algorithm runs in `O(n + m)` time, where `m` is the expected number of
    edges, which equals `p n (n - 1) / 2`. This should be faster than
    :func:`gnp_random_graph` when `p` is small and the expected number of edges
    is small (that is, the graph is sparse).

    See Also
    --------
    gnp_random_graph

    References
    ----------
    .. [1] Vladimir Batagelj and Ulrik Brandes,
       "Efficient generation of large random networks",
       Phys. Rev. E, 71, 036113, 2005.
    s   fast_gnp_random_graph(%s,%s)i    i   t   directediÿÿÿÿg      ð?N(   R    t   namet   Nonet   randomt   seedt   nxR   t   matht   logt   DiGrapht   intt   add_edge(	   t   nt   pR   R   t   Gt   wt   lpt   vt   lr(    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   /   sB    #


c         C   s  | r t  j ƒ  } n t  j ƒ  } | j t |  ƒ ƒ d |  | f | _ | d k rW | S| d k rs t |  d | ƒS| d k	 r� t j	 | ƒ n  | j
 ƒ  r¶ t j t |  ƒ d ƒ } n t j t |  ƒ d ƒ } x0 | D]( } t j ƒ  | k  rÕ | j | Œ  qÕ qÕ W| S(   s   Returns a `G_{n,p}` random graph, also known as an ErdÅ‘s-RÃ©nyi graph or
    a binomial graph.

    The `G_{n,p}` model chooses each of the possible edges with probability
    ``p``.

    The functions :func:`binomial_graph` and :func:`erdos_renyi_graph` are
    aliases of this function.

    Parameters
    ----------
    n : int
        The number of nodes.
    p : float
        Probability for edge creation.
    seed : int, optional
        Seed for random number generator (default=None).
    directed : bool, optional (default=False)
        If ``True``, this function returns a directed graph.

    See Also
    --------
    fast_gnp_random_graph

    Notes
    -----
    This algorithm runs in `O(n^2)` time.  For sparse graphs (that is, for
    small values of `p`), :func:`fast_gnp_random_graph` is a faster algorithm.

    References
    ----------
    .. [1] P. ErdÅ‘s and A. RÃ©nyi, On Random Graphs, Publ. Math. 6, 290 (1959).
    .. [2] E. N. Gilbert, Random Graphs, Ann. Math. Stat., 30, 1141 (1959).
    s   gnp_random_graph(%s,%s)i    i   t   create_usingi   N(   R   R   t   Grapht   add_nodes_fromt   rangeR   R   R   R   R   t   is_directedt	   itertoolst   permutationst   combinationsR   (   R    R!   R   R   R"   t   edgest   e(    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   |   s$    #c   	      C   s.  |  |  d d } | | k r- t  |  ƒ } n t |  ƒ } d |  | f | _ |  d k sd | | k rh | S| d k	 r„ t j | ƒ n  d } d } d } d } x‹ t r)t j | | ƒ | | k  rï | j | | ƒ | d 7} | | k rï | Sn  | d 7} | d 7} | |  k rŸ | d 7} | d } qŸ qŸ Wd S(   sF  Returns a `G_{n,m}` random graph.

    In the `G_{n,m}` model, a graph is chosen uniformly at random from the set
    of all graphs with `n` nodes and `m` edges.

    This algorithm should be faster than :func:`gnm_random_graph` for dense
    graphs.

    Parameters
    ----------
    n : int
        The number of nodes.
    m : int
        The number of edges.
    seed : int, optional
        Seed for random number generator (default=None).

    See Also
    --------
    gnm_random_graph()

    Notes
    -----
    Algorithm by Keith M. Briggs Mar 31, 2006.
    Inspired by Knuth's Algorithm S (Selection sampling technique),
    in section 3.4.2 of [1]_.

    References
    ----------
    .. [1] Donald E. Knuth, The Art of Computer Programming,
        Volume 2/Seminumerical algorithms, Third Edition, Addison-Wesley, 1997.
    i   i   s   dense_gnm_random_graph(%s,%s)i    N(	   R   R    R   R   R   R   t   Truet	   randrangeR   (	   R    t   mR   t   mmaxR"   t   uR%   t   tt   k(    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   ¼   s0    !	
 


c   
      C   s5  | r t  j ƒ  } n t  j ƒ  } | j t |  ƒ ƒ d |  | f | _ | d k	 rc t j | ƒ n  |  d k rs | S|  |  d } | s” | d :} n  | | k r° t	 |  d | ƒS| j
 ƒ  } d } xl | | k  r0t j | ƒ } t j | ƒ }	 | |	 k sÅ | j | |	 ƒ rqÅ qÅ | j | |	 ƒ | d } qÅ W| S(   sV  Returns a `G_{n,m}` random graph.

    In the `G_{n,m}` model, a graph is chosen uniformly at random from the set
    of all graphs with `n` nodes and `m` edges.

    This algorithm should be faster than :func:`dense_gnm_random_graph` for
    sparse graphs.

    Parameters
    ----------
    n : int
        The number of nodes.
    m : int
        The number of edges.
    seed : int, optional
        Seed for random number generator (default=None).
    directed : bool, optional (default=False)
        If True return a directed graph

    See also
    --------
    dense_gnm_random_graph

    s   gnm_random_graph(%s,%s)i   g       @R'   i    N(   R   R   R(   R)   R*   R   R   R   R   R   t   nodest   choicet   has_edgeR   (
   R    R3   R   R   R"   t	   max_edgest   nlistt
   edge_countR5   R%   (    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   ù   s0    c         C   s†  | d k	 r t j | ƒ n  | |  k r: t j d ƒ ‚ n  t |  ƒ } d |  | | f | _ | j ƒ  } | } xi t d | d d ƒ D]P } | | | d | !} x2 t t	 | ƒ ƒ D] }	 | j
 | |	 | |	 ƒ q´ Wq† W| j ƒ  }
 x™ |
 D]‘ \ } } t j ƒ  | k  rí t j | ƒ } xa | | k s;| j | | ƒ rjt j | ƒ } | j | ƒ |  d k rPqqW| j
 | | ƒ qí qí W| S(   s½  Return a Newmanâ€“Wattsâ€“Strogatz small-world graph.

    Parameters
    ----------
    n : int
        The number of nodes.
    k : int
        Each node is joined with its ``k`` nearest neighbors in a ring
        topology.
    p : float
        The probability of adding a new edge for each edge.
    seed : int, optional
        The seed for the random number generator (the default is ``None``).

    Notes
    -----
    First create a ring over ``n`` nodes.  Then each node in the ring is
    connected with its ``k`` nearest neighbors (or ``k - 1`` neighbors if ``k``
    is odd).  Then shortcuts are created by adding new edges as follows: for
    each edge ``(u, v)`` in the underlying "``n``-ring with ``k`` nearest
    neighbors" with probability ``p`` add a new edge ``(u, w)`` with
    randomly-chosen existing node ``w``.  In contrast with
    :func:`watts_strogatz_graph`, no edges are removed.

    See Also
    --------
    watts_strogatz_graph()

    References
    ----------
    .. [1] M. E. J. Newman and D. J. Watts,
       Renormalization group analysis of the small-world network model,
       Physics Letters A, 263, 341, 1999.
       http://dx.doi.org/10.1016/S0375-9601(99)00757-4
    s"   k>=n, choose smaller k or larger ns%   newman_watts_strogatz_graph(%s,%s,%s)i   i   i    N(   R   R   R   R   t   NetworkXErrorR    R   R8   R*   t   lenR   R/   R9   R:   t   degree(   R    R7   R!   R   R"   R<   t   fromvt   jt   tovt   iR0   R5   R%   R#   (    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR
   2  s,    $ !c         C   s«  | |  k r t  j d ƒ ‚ n  | d k	 r: t j | ƒ n  t  j ƒ  } d |  | | f | _ t t |  ƒ ƒ } xJ t d | d d ƒ D]1 } | | | d | !} | j	 t
 | | ƒ ƒ q† Wxé t d | d d ƒ D]Ð } | | | d | !} x² t
 | | ƒ D]¡ \ } }	 t j ƒ  | k  rþ t j | ƒ }
 xq |
 | k sL| j | |
 ƒ r{t j | ƒ }
 | j | ƒ |  d k r.Pq.q.W| j | |	 ƒ | j | |
 ƒ qþ qþ WqÓ W| S(   s"  Return a Wattsâ€“Strogatz small-world graph.

    Parameters
    ----------
    n : int
        The number of nodes
    k : int
        Each node is joined with its ``k`` nearest neighbors in a ring
        topology.
    p : float
        The probability of rewiring each edge
    seed : int, optional
        Seed for random number generator (default=None)

    See Also
    --------
    newman_watts_strogatz_graph()
    connected_watts_strogatz_graph()

    Notes
    -----
    First create a ring over ``n`` nodes.  Then each node in the ring is joined
    to its ``k`` nearest neighbors (or ``k - 1`` neighbors if ``k`` is odd).
    Then shortcuts are created by replacing some edges as follows: for each
    edge ``(u, v)`` in the underlying "``n``-ring with ``k`` nearest neighbors"
    with probability ``p`` replace it with a new edge ``(u, w)`` with uniformly
    random choice of existing node ``w``.

    In contrast with :func:`newman_watts_strogatz_graph`, the random rewiring
    does not increase the number of edges. The rewired graph is not guaranteed
    to be connected as in :func:`connected_watts_strogatz_graph`.

    References
    ----------
    .. [1] Duncan J. Watts and Steven H. Strogatz,
       Collective dynamics of small-world networks,
       Nature, 393, pp. 440--442, 1998.
    s"   k>=n, choose smaller k or larger ns   watts_strogatz_graph(%s,%s,%s)i   i   i    N(   R   R>   R   R   R   R(   R   t   listR*   t   add_edges_fromt   zipR9   R:   R@   t   remove_edgeR   (   R    R7   R!   R   R"   R8   RB   t   targetsR5   R%   R#   (    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   t  s,    '!id   c         C   sr   t  |  | | | ƒ } d } xP t j | ƒ sm t  |  | | | ƒ } | d } | | k r t j d ƒ ‚ q q W| S(   sÆ  Returns a connected Wattsâ€“Strogatz small-world graph.

    Attempts to generate a connected graph by repeated generation of
    Wattsâ€“Strogatz small-world graphs.  An exception is raised if the maximum
    number of tries is exceeded.

    Parameters
    ----------
    n : int
        The number of nodes
    k : int
        Each node is joined with its ``k`` nearest neighbors in a ring
        topology.
    p : float
        The probability of rewiring each edge
    tries : int
        Number of attempts to generate a connected graph.
    seed : int, optional
         The seed for random number generator.

    See Also
    --------
    newman_watts_strogatz_graph()
    watts_strogatz_graph()

    i   s    Maximum number of tries exceeded(   R   R   t   is_connectedR>   (   R    R7   R!   t   triesR   R"   R6   (    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   º  s    
c            sù   ˆ ˆ d d k r& t  j d ƒ ‚ n  d ˆ k o= ˆ k  n sT t  j d ƒ ‚ n  ˆ d k rj t ˆ ƒ S| d k	 r† t j | ƒ n  d „  ‰  ‡  ‡ ‡ f d †  } | ƒ  } x | d k rÈ | ƒ  } q° Wt  j ƒ  } d ˆ ˆ f | _ | j | ƒ | S(	   s³  Returns a random ``d``-regular graph on ``n`` nodes.

    The resulting graph has no self-loops or parallel edges.

    Parameters
    ----------
    d : int
      The degree of each node.
    n : integer
      The number of nodes. The value of ``n * d`` must be even.
    seed : hashable object
        The seed for random number generator.

    Notes
    -----
    The nodes are numbered from ``0`` to ``n - 1``.

    Kim and Vu's paper [2]_ shows that this algorithm samples in an
    asymptotically uniform way from the space of random graphs when
    `d = O(n^{1 / 3 - \epsilon})`.

    Raises
    ------

    NetworkXError
        If ``n * d`` is odd or ``d`` is greater than or equal to ``n``.

    References
    ----------
    .. [1] A. Steger and N. Wormald,
       Generating random regular graphs quickly,
       Probability and Computing 8 (1999), 377-396, 1999.
       http://citeseer.ist.psu.edu/steger99generating.html

    .. [2] Jeong Han Kim and Van H. Vu,
       Generating random regular graphs,
       Proceedings of the thirty-fifth ACM symposium on Theory of computing,
       San Diego, CA, USA, pp 213--222, 2003.
       http://portal.acm.org/citation.cfm?id=780542.780576
    i   i    s   n * d must be evens+   the 0 <= d < n inequality must be satisfiedc         S   sr   | s
 t  Sxa | D]Y } xP | D]H } | | k r4 Pn  | | k rP | | } } n  | | f |  k r t  Sq Wq Wt S(   N(   R1   t   False(   R/   t   potential_edgest   s1t   s2(    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyt	   _suitable  s    c    	         s3  t  ƒ  }  t t ˆ ƒ ƒ ˆ } x| r.t d „  ƒ } t j | ƒ t | ƒ } x� t | | ƒ D]| \ } } | | k rˆ | | } } n  | | k r¼ | | f |  k r¼ |  j | | f ƒ q` | | c d 7<| | c d 7<q` Wˆ  |  | ƒ só d  Sg  | j
 ƒ  D]% \ } } t | ƒ D] } | ^ qq } q" W|  S(   Nc           S   s   d S(   Ni    (    (    (    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyt   <lambda>.  s    i   (   t   setRE   R*   R   R   t   shufflet   iterRG   t   addR   t   items(	   R/   t   stubsRM   t   stubiterRN   RO   t   nodet	   potentialt   _(   RP   t   dR    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyt   _try_creation'  s$    		#s   random_regular_graph(%s, %s)N(	   R   R>   R    R   R   R   R(   R   RF   (   R\   R    R   R]   R/   R"   (    (   RP   R\   R    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   ß  s"    )
		c         C   sB   t  ƒ  } x2 t | ƒ | k  r= t j |  ƒ } | j | ƒ q W| S(   s”    Return m unique elements from seq.

    This differs from random.sample which can return repeated
    elements if seq holds repeated elements.
    (   RR   R?   R   R9   RU   (   t   seqR3   RI   t   x(    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyt   _random_subsetN  s
    	c         C   sû   | d k  s | |  k r4 t  j d | |  f ƒ ‚ n  | d k	 rP t j | ƒ n  t | ƒ } d |  | f | _ t t | ƒ ƒ } g  } | } xg | |  k  rö | j	 t
 | g | | ƒ ƒ | j | ƒ | j | g | ƒ t | | ƒ } | d 7} q� W| S(   sý  Returns a random graph according to the BarabÃ¡siâ€“Albert preferential
    attachment model.

    A graph of ``n`` nodes is grown by attaching new nodes each with ``m``
    edges that are preferentially attached to existing nodes with high degree.

    Parameters
    ----------
    n : int
        Number of nodes
    m : int
        Number of edges to attach from a new node to existing nodes
    seed : int, optional
        Seed for random number generator (default=None).

    Returns
    -------
    G : Graph

    Raises
    ------
    NetworkXError
        If ``m`` does not satisfy ``1 <= m < n``.

    References
    ----------
    .. [1] A. L. BarabÃ¡si and R. Albert "Emergence of scaling in
       random networks", Science 286, pp 509-512, 1999.
    i   sE   BarabÃ¡siâ€“Albert network must have m >= 1 and m < n, m = %d, n = %ds   barabasi_albert_graph(%s,%s)N(   R   R>   R   R   R   R    R   RE   R*   RF   RG   t   extendR`   (   R    R3   R   R"   RI   t   repeated_nodest   source(    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   Z  s"    	c         C   s÷  | d k  s |  | k  r4 t  j d | |  f ƒ ‚ n  | d k sL | d k  rb t  j d | ƒ ‚ n  | d k	 r~ t j | ƒ n  t | ƒ } d | _ | j ƒ  } | } xK| |  k  ròt | | ƒ } | j	 ƒ  } | j
 | | ƒ | j | ƒ d }	 xÜ |	 | k  rÐt j ƒ  | k  ršg  | j | ƒ D], }
 | j | |
 ƒ r#|
 | k r#|
 ^ q#} | ršt j | ƒ }
 | j
 | |
 ƒ | j |
 ƒ |	 d }	 qõ qšn  | j	 ƒ  } | j
 | | ƒ | j | ƒ |	 d }	 qõ W| j | g | ƒ | d 7} q¨ W| S(   sï  Holme and Kim algorithm for growing graphs with powerlaw
    degree distribution and approximate average clustering.

    Parameters
    ----------
    n : int
        the number of nodes
    m : int
        the number of random edges to add for each new node
    p : float,
        Probability of adding a triangle after adding a random edge
    seed : int, optional
        Seed for random number generator (default=None).

    Notes
    -----
    The average clustering has a hard time getting above a certain
    cutoff that depends on ``m``.  This cutoff is often quite low.  The
    transitivity (fraction of triangles to possible triangles) seems to
    decrease with network size.

    It is essentially the BarabÃ¡siâ€“Albert (BA) growth model with an
    extra step that each random edge is followed by a chance of
    making an edge to one of its neighbors too (and thus a triangle).

    This algorithm improves on BA in the sense that it enables a
    higher average clustering to be attained if desired.

    It seems possible to have a disconnected graph with this algorithm
    since the initial ``m`` nodes may not be all linked to a new node
    on the first iteration like the BA model.

    Raises
    ------
    NetworkXError
        If ``m`` does not satisfy ``1 <= m <= n`` or ``p`` does not
        satisfy ``0 <= p <= 1``.

    References
    ----------
    .. [1] P. Holme and B. J. Kim,
       "Growing scale-free networks with tunable clustering",
       Phys. Rev. E, 65, 026107, 2002.
    i   s.   NetworkXError must have m>1 and m<n, m=%d,n=%di    s&   NetworkXError p must be in [0,1], p=%fs   Powerlaw-Cluster GraphN(   R   R>   R   R   R   R    R   R8   R`   t   popR   t   appendt	   neighborsR:   R9   Ra   (   R    R3   R!   R   R"   Rb   Rc   t   possible_targetst   targett   countt   nbrt   neighborhood(    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   •  sH    .	
	c   	      C   sL  | d k s | d k  r9 d j  | ƒ } t j | ƒ ‚ n  |  d k  r] d } t j | ƒ ‚ n  | d k	 ry t j | ƒ n  t j ƒ  } d | j d <| j d d ƒ d } x� | |  k  rGt j	 | j
 ƒ  ƒ } | j | ƒ t } xB | j | ƒ D]1 } t j ƒ  | k  rï | j | | ƒ t } qï qï W| s:| j | ƒ q« | d 7} q« W| S(	   sc  Returns an undirected graph using the duplication-divergence model.

    A graph of ``n`` nodes is created by duplicating the initial nodes
    and retaining edges incident to the original nodes with a retention
    probability ``p``.

    Parameters
    ----------
    n : int
        The desired number of nodes in the graph.
    p : float
        The probability for retaining the edge of the replicated node.
    seed : int, optional
        A seed for the random number generator of ``random`` (default=None).

    Returns
    -------
    G : Graph

    Raises
    ------
    NetworkXError
        If `p` is not a valid probability.
        If `n` is less than 2.

    References
    ----------
    .. [1] I. Ispolatov, P. L. Krapivsky, A. Yuryev,
       "Duplication-divergence model of protein interaction network",
       Phys. Rev. E, 71, 061911, 2005.

    i   i    s$   NetworkXError p={0} is not in [0,1].i   s$   n must be greater than or equal to 2s   Duplication-Divergence GraphR   N(   t   formatR   R>   R   R   R   R(   t   graphR   R9   R8   t   add_nodeRL   Rf   R1   t   remove_node(	   R    R!   R   t   msgR"   RD   t   random_nodet   flagRj   (    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   î  s0    !c         C   sã   | d k	 r t j | ƒ n  t d t j ƒ  |  d ƒ } t | ƒ } d |  | | f | _ | d } xv t | ƒ D]h }  t j ƒ  | k  rs | d 7} | j |  | ƒ t j ƒ  | k  rÛ | d 7} | j | d | ƒ qÛ qs qs W| S(   sS  Returns a random lobster graph.

     A lobster is a tree that reduces to a caterpillar when pruning all
     leaf nodes. A caterpillar is a tree that reduces to a path graph
     when pruning all leaf nodes; setting ``p2`` to zero produces a caterillar.

     Parameters
     ----------
     n : int
         The expected number of nodes in the backbone
     p1 : float
         Probability of adding an edge to the backbone
     p2 : float
         Probability of adding an edge one level beyond backbone
     seed : int, optional
         Seed for random number generator (default=None).
    i   g      à?s   random_lobster(%d,%s,%s)i   N(   R   R   R   R   R   R   R*   R   (   R    t   p1t   p2R   t   llent   Lt   current_node(    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   2  s    


c         C   s�  t  d ƒ } d | _ | d k	 r1 t j | ƒ n  g  } g  } d } x‚ |  D]z \ } } } t | | ƒ }	 | j | |	 ƒ t j t	 | |	 ƒ d | ƒ}
 | j |
 ƒ | | 7} t j
 j | |
 ƒ } qJ WxÁ t t | ƒ d ƒ D]© } | | j ƒ  } | | d j ƒ  } | | } d } xl | | k  r‡t j | ƒ } t j | ƒ } | | k s| j | | ƒ rjqq| j | | ƒ | d } qWqß W| S(   s+  Returns a random shell graph for the constructor given.

    Parameters
    ----------
    constructor : list of three-tuples
        Represents the parameters for a shell, starting at the center
        shell.  Each element of the list must be of the form ``(n, m,
        d)``, where ``n`` is the number of nodes in the shell, ``m`` is
        the number of edges in the shell, and ``d`` is the ratio of
        inter-shell (next) edges to intra-shell edges. If ``d`` is zero,
        there will be no intra-shell edges, and if ``d`` is one there
        will be all possible intra-shell edges.
    seed : int, optional
        Seed for random number generator (default=None).

    Examples
    --------
    >>> constructor = [(10, 20, 0.8), (20, 40, 0.8)]
    >>> G = nx.random_shell_graph(constructor)

    i    s   random_shell_graph(constructor)t   first_labeli   N(   R    R   R   R   R   R   Re   R   t   convert_node_labels_to_integersR   t	   operatorst   unionR*   R?   R8   R9   R:   R   (   t   constructorR   R"   t   glistt   intra_edgest   nnodesR    R3   R\   t   inter_edgest   gt   git   nlist1t   nlist2t   total_edgesR=   R5   R%   (    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   U  s:    		

i   c         C   sr   d d l  m } y" t |  d | d | d | ƒ} Wn t j d | ƒ ‚ n X| | ƒ } d |  | f | _ | S(   sø  Returns a tree with a power law degree distribution.

    Parameters
    ----------
    n : int
        The number of nodes.
    gamma : float
        Exponent of the power law.
    seed : int, optional
        Seed for random number generator (default=None).
    tries : int
        Number of attempts to adjust the sequence to make it a tree.

    Raises
    ------
    NetworkXError
        If no valid sequence is found within the maximum number of
        attempts.

    Notes
    -----
    A trial power law degree sequence is chosen and then elements are
    swapped with new elements from a powerlaw distribution until the
    sequence makes a tree (by checking, for example, that the number of
    edges is one smaller than the number of nodes).

    iÿÿÿÿ(   t   degree_sequence_treet   gammaR   RK   s5   Exceeded max (%d) attempts for a valid tree sequence.s   random_powerlaw_tree(%s,%s)(   t   networkx.generators.degree_seqR†   R   R   R>   R   (   R    R‡   R   RK   R†   t   sR"   (    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   �  s    	c   
      C   s&  | d k	 r t j | ƒ n  t j j |  d | ƒ} g  | D]* } t |  t t t	 | ƒ ƒ d ƒ ƒ ^ q; } t j j | d | ƒ} g  | D]* } t |  t t t	 | ƒ ƒ d ƒ ƒ ^ qŠ } xR | D]J } |  t
 | ƒ d d k rå | St j d |  d ƒ }	 | j ƒ  | |	 <qÁ Wt j d | ƒ ‚ t S(   s	  Returns a degree sequence for a tree with a power law distribution.

    Parameters
    ----------
    n : int,
        The number of nodes.
    gamma : float
        Exponent of the power law.
    seed : int, optional
        Seed for random number generator (default=None).
    tries : int
        Number of attempts to adjust the sequence to make it a tree.

    Raises
    ------
    NetworkXError
        If no valid sequence is found within the maximum number of
        attempts.

    Notes
    -----
    A trial power law degree sequence is chosen and then elements are
    swapped with new elements from a power law distribution until
    the sequence makes a tree (by checking, for example, that the number of
    edges is one smaller than the number of nodes).

    t   exponenti    g       @g      ð?i   s5   Exceeded max (%d) attempts for a valid tree sequence.N(   R   R   R   R   t   utilst   powerlaw_sequencet   mint   maxR   t   roundt   sumt   randintRd   R>   RL   (
   R    R‡   R   RK   t   zR‰   t   zseqt   swapt   degt   index(    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyR   º  s    77(#   t   __doc__t   joint
   __author__R,   R   R   t   networkxR   t   networkx.generators.classicR    R   R   t   collectionsR   t   __all__R   RL   R   R   R	   R   R   R   R
   R   R   R   R`   R   R   R   R   R   R   R   (    (    (    su   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/generators/random_graphs.pyt   <module>   sX   		M==9BF%o	;YD#;*