ó
 ,µ[c           @   s«   d  Z  d d l Z d d l Z d d l m Z d d l m Z d j d g ƒ Z	 d d d	 g Z
 e d
 ƒ d d „ ƒ Z e d
 ƒ d d „ ƒ Z e d
 ƒ d d „ ƒ Z d S(   s,   
Generators for random intersection graphs.
iÿÿÿÿN(   t	   bipartite(   t   py_random_states   
s   Aric Hagberg (hagberg@lanl.gov)t!   uniform_random_intersection_grapht   k_random_intersection_grapht!   general_random_intersection_graphi   c         C   s.   t  j |  | | | ƒ } t j | t |  ƒ ƒ S(   s’  Return a uniform random intersection graph.

    Parameters
    ----------
    n : int
        The number of nodes in the first bipartite set (nodes)
    m : int
        The number of nodes in the second bipartite set (attributes)
    p : float
        Probability of connecting nodes between bipartite sets
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.

    See Also
    --------
    gnp_random_graph

    References
    ----------
    .. [1] K.B. Singer-Cohen, Random Intersection Graphs, 1995,
       PhD thesis, Johns Hopkins University
    .. [2] Fill, J. A., Scheinerman, E. R., and Singer-Cohen, K. B.,
       Random intersection graphs when m = !(n):
       An equivalence theorem relating the evolution of the g(n, m, p)
       and g(n, p) models. Random Struct. Algorithms 16, 2 (2000), 156â€“176.
    (   R    t   random_grapht   nxt   projected_grapht   range(   t   nt   mt   pt   seedt   G(    (    s?   lib/python2.7/site-packages/networkx/generators/intersection.pyR      s    c         C   sˆ   t  j |  | ƒ } t |  |  | ƒ } xI t |  ƒ D]; } | j | | ƒ } | j t | g t | ƒ | ƒ ƒ q3 Wt  j | t |  ƒ ƒ S(   s/  Return a intersection graph with randomly chosen attribute sets for
    each node that are of equal size (k).

    Parameters
    ----------
    n : int
        The number of nodes in the first bipartite set (nodes)
    m : int
        The number of nodes in the second bipartite set (attributes)
    k : float
        Size of attribute set to assign to each node.
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.

    See Also
    --------
    gnp_random_graph, uniform_random_intersection_graph

    References
    ----------
    .. [1] Godehardt, E., and Jaworski, J.
       Two models of random intersection graphs and their applications.
       Electronic Notes in Discrete Mathematics 10 (2001), 129--132.
    (   R   t   empty_graphR   t   samplet   add_edges_fromt   zipt   lenR   (   R	   R
   t   kR   R   t   msett   vt   targets(    (    s?   lib/python2.7/site-packages/networkx/generators/intersection.pyR   9   s    'c   	      C   s¹   t  | ƒ | k r! t d ƒ ‚ n  t j |  | ƒ } t |  |  | ƒ } xY t |  ƒ D]K } xB t | | ƒ D]1 \ } } | j ƒ  | k  rj | j | | ƒ qj qj WqT Wt j | t |  ƒ ƒ S(   s  Return a random intersection graph with independent probabilities
    for connections between node and attribute sets.

    Parameters
    ----------
    n : int
        The number of nodes in the first bipartite set (nodes)
    m : int
        The number of nodes in the second bipartite set (attributes)
    p : list of floats of length m
        Probabilities for connecting nodes to each attribute
    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.

    See Also
    --------
    gnp_random_graph, uniform_random_intersection_graph

    References
    ----------
    .. [1] Nikoletseas, S. E., Raptopoulos, C., and Spirakis, P. G.
       The existence and efficient construction of large independent sets
       in general random intersection graphs. In ICALP (2004), J. DÂ´Ä±az,
       J. KarhumÂ¨aki, A. LepistÂ¨o, and D. Sannella, Eds., vol. 3142
       of Lecture Notes in Computer Science, Springer, pp. 1029â€“1040.
    s(   Probability list p must have m elements.(	   R   t
   ValueErrorR   R   R   R   t   randomt   add_edgeR   (	   R	   R
   R   R   R   R   t   uR   t   q(    (    s?   lib/python2.7/site-packages/networkx/generators/intersection.pyR   \   s    (   t   __doc__R   t   networkxR   t   networkx.algorithmsR    t   networkx.utilsR   t   joint
   __author__t   __all__t   NoneR   R   R   (    (    (    s?   lib/python2.7/site-packages/networkx/generators/intersection.pyt   <module>   s   		 	"	