ó
ś£Õ\c           @   s[   d  Z  d d l Z d j d d d g  Z d d d	 g Z d
 d  Z d   Z d   Z d S(   sJ   Generate graphs with a given degree sequence or expected degree sequence.
i’’’’Ns   
s   Aric Hagberg (hagberg@lanl.gov)s   Pieter Swart (swart@lanl.gov)sY   Dan Schult (dschult@colgate.edu)Joel Miller (joel.c.miller.research@gmail.com)Ben Edwardst   is_valid_degree_sequencet%   is_valid_degree_sequence_erdos_gallait%   is_valid_degree_sequence_havel_hakimit   hhc         C   sO   | d k r t  |   } n0 | d k r6 t |   } n d } t j |   | S(   sI  Returns True if the sequence is a valid degree sequence.

    A degree sequence is valid if some graph can realize it.

    Parameters
    ----------
    sequence : list or iterable container
        A sequence of integer node degrees

    method : "eg" | "hh"
        The method used to validate the degree sequence.
        "eg" corresponds to the ErdÅs-Gallai algorithm, and
        "hh" to the Havel-Hakimi algorithm.

    Returns
    -------
    valid : bool
        True if the sequence is a valid degree sequence and False if not.

    Examples
    --------
    >>> G = nx.path_graph(4)
    >>> sequence = G.degree().values()
    >>> nx.is_valid_degree_sequence(sequence)
    True

    References
    ----------
    ErdÅs-Gallai
        [EG1960]_, [choudum1986]_

    Havel-Hakimi
        [havel1955]_, [hakimi1962]_, [CL1996]_
    t   egR   s   `method` must be 'eg' or 'hh'(   R   R   t   nxt   NetworkXException(   t   sequencet   methodt   validt   msg(    (    sU   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/graphical.pyR       s    #c         C   s  t  |   } t |  d k r" t St j j |  s8 t St |  d k  rN t St |  d rb t Sx | r| j	   | d d k  r t S| j
   } | d k r„ t S| t |  k r» t SxB t t |  d t |  | d d  D] } | | c d 8<qę Wqe Wt S(   s  Returns True if the sequence is a valid degree sequence.

    A degree sequence is valid if some graph can realize it.
    Validation proceeds via the Havel-Hakimi algorithm.

    Worst-case run time is: `O(n^(log n))`

    Parameters
    ----------
    sequence : list or iterable container
        A sequence of integer node degrees

    Returns
    -------
    valid : bool
        True if the sequence is a valid degree sequence and False if not.

    References
    ----------
    [havel1955]_, [hakimi1962]_, [CL1996]_
    i    i   i   i’’’’(   t   listt   lent   TrueR   t   utilst   is_list_of_intst   Falset   mint   sumt   sortt   popt   range(   R   t   st   dt   i(    (    sU   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/graphical.pyR   B   s*    	
  1c      	   C   s*  t  |  d t } t |  } | d k r. t St j j |  sD t St |  d k  rZ t St |  d rn t Sg  t	 d t |   D]$ } | | | | d k  r | ^ q } xu | D]m } t | d | ! } | | d t g  t	 | |  D] } t | | | g  ^ qģ  } | | k rµ t Sqµ Wt S(   s   Returns True if the sequence is a valid degree sequence.

    A degree sequence is valid if some graph can realize it.
    Validation proceeds via the ErdÅs-Gallai algorithm.

    Worst-case run time is: `O(n^2)`

    Parameters
    ----------
    sequence : list or iterable container
        A sequence of integer node degrees 

    Returns
    -------
    valid : bool
        True if the sequence is a valid degree sequence and False if not.

    References
    ----------
    [EG1960]_, [choudum1986]_
    t   reversei    i   i   (
   t   sortedR   R   R   R   R   R   R   R   R   (   R   t   deg_seqt   nR   t   sigkt   kt   sum_degt   sum_min(    (    sU   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/graphical.pyR   y   s$    @3(	   t   __doc__t   networkxR   t   joint
   __author__t   __all__R    R   R   (    (    (    sU   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/graphical.pyt   <module>   s   		-	7