U
    9vf                     @   s*   d Z ddlmZ ddlZdgZdd ZdS )z 
Generators for interval graph.
    )SequenceNinterval_graphc           
      C   s   t | } | D ]@}t|tr&t|dks.td|d |d krtd| qt }dd | D }|| |r|	  \}}}|D ](}|\}}	||kr|	|kr|
|| qqn|S )ao  Generates an interval graph for a list of intervals given.

    In graph theory, an interval graph is an undirected graph formed from a set
    of closed intervals on the real line, with a vertex for each interval
    and an edge between vertices whose intervals intersect.
    It is the intersection graph of the intervals.

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

    Parameters
    ----------
    intervals : a sequence of intervals, say (l, r) where l is the left end,
    and r is the right end of the closed interval.

    Returns
    -------
    G : networkx graph

    Examples
    --------
    >>> intervals = [(-2, 3), [1, 4], (2, 3), (4, 6)]
    >>> G = nx.interval_graph(intervals)
    >>> sorted(G.edges)
    [((-2, 3), (1, 4)), ((-2, 3), (2, 3)), ((1, 4), (2, 3)), ((1, 4), (4, 6))]

    Raises
    ------
    :exc:`TypeError`
        if `intervals` contains None or an element which is not
        collections.abc.Sequence or not a length of 2.
    :exc:`ValueError`
        if `intervals` contains an interval such that min1 > max1
        where min1,max1 = interval
       zZEach interval must have length 2, and be a collections.abc.Sequence such as tuple or list.r      z*Interval must have lower value first. Got c                 S   s   g | ]}t |qS  )tuple).0intervalr   r   F/tmp/pip-unpacked-wheel-_lngutwb/networkx/generators/interval_graph.py
<listcomp>=   s     z"interval_graph.<locals>.<listcomp>)list
isinstancer   len	TypeError
ValueErrornxZGraphZadd_nodes_frompopZadd_edge)
Z	intervalsr	   graphZtupled_intervalsZmin1Zmax1Z	interval1Z	interval2Zmin2Zmax2r   r   r
   r      s(    $
)__doc__collections.abcr   Znetworkxr   __all__r   r   r   r   r
   <module>   s   