U
    Ñtœd  ã                   @   s”   d dl mZmZmZ d dlmZmZ d dlmZm	Z	m
Z
 dZdd„ Zddd	„Zdd
d„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )é    )Ú	GraphBaseÚVertexÚEdge)Ú	VertexSeqÚEdgeSeq)Údisjoint_unionÚunionÚintersection)
Ú__iadd__Ú__add__Ú__and__Ú__isub__Ú__sub__Ú__mul__Ú__or__Ú_disjoint_unionÚ_unionÚ_intersectionc                 C   s   t |tƒr|g}t| g| ƒS )z¬Creates the disjoint union of two (or more) graphs.

    @param other: graph or list of graphs to be united with the current one.
    @return: the disjoint union graph
    )Ú
isinstancer   r   ©ÚgraphÚother© r   úQ/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/igraph/operators/methods.pyr      s    
r   Úautoc                 C   s"   t |tƒr|g}t| g| |dS )a
  Creates the union of two (or more) graphs.

    @param other: graph or list of graphs to be united with the current one.
    @param byname: whether to use vertex names instead of ids. See
      L{igraph.operators.union} for details.
    @return: the union graph
    ©Úbyname)r   r   r   ©r   r   r   r   r   r   r   '   s    
r   c                 C   s"   t |tƒr|g}t| g| |dS )a*  Creates the intersection of two (or more) graphs.

    @param other: graph or list of graphs to be intersected with
      the current one.
    @param byname: whether to use vertex names instead of ids. See
      L{igraph.operators.intersection} for details.
    @return: the intersection graph
    r   )r   r   r	   r   r   r   r   r   4   s    	
r   c                 C   s   t |ttfƒr|  |¡ | S t |tƒrBt|ƒdkrB|  |g¡ | S t |tƒrŒ|sT| S t |d tƒrp|  |¡ | S t |d tƒrŒ|  |¡ | S tS )z>In-place addition (disjoint union).

    @see: L{__add__}
    é   r   )	r   ÚintÚstrÚadd_verticesÚtupleÚlenÚ	add_edgesÚlistÚNotImplementedr   r   r   r   r
   B   s     



r
   c                 C   sø   ddl m} t|ttfƒr.|  ¡ }| |¡ nÆt|tƒrZt|ƒdkrZ|  ¡ }| 	|g¡ nšt|t
ƒrÜt|ƒdkrÒt|d tƒr’|  ¡ }| 	|¡ qÚt|d tƒr´|  ¡ }| |¡ qÚt|d |ƒrÌ|  |¡S tS qô|  ¡ S nt||ƒrð|  |¡S tS |S )a  Copies the graph and extends the copy depending on the type of
    the other object given.

    @param other: if it is an integer, the copy is extended by the given
      number of vertices. If it is a string, the copy is extended by a
      single vertex whose C{name} attribute will be equal to the given
      string. If it is a tuple with two elements, the copy
      is extended by a single edge. If it is a list of tuples, the copy
      is extended by multiple edges. If it is a L{Graph}, a disjoint
      union is performed.
    r   ©ÚGraphr   )Úigraphr(   r   r   r    Úcopyr!   r"   r#   r$   r%   r   r&   )r   r   r(   Úgr   r   r   r   Y   s.    




r   c                 C   s(   ddl m} t||ƒr |  |¡S tS dS )z‡Graph intersection operator.

    @param other: the other graph to take the intersection with.
    @return: the intersected graph.
    r   r'   N)r)   r(   r   r	   r&   ©r   r   r(   r   r   r   r   …   s    

r   c                 C   sð   t |tƒr|  |g¡ nÔt |tƒr<t|ƒdkr<|  |g¡ n°t |tƒrt|ƒdkrìt |d tƒrl|  |¡ qìt |d ttfƒrŠ|  |¡ qìtS n\t |t	ƒr¦|  |¡ nFt |t
ƒr¼|  |¡ n0t |tƒrÒ|  |¡ nt |tƒrè|  |¡ ntS | S )z8In-place subtraction (difference).

    @see: L{__sub__}r   r   )r   r   Údelete_verticesr"   r#   Údelete_edgesr%   r    r&   r   r   r   r   r   r   r   r   r   ”   s*    





r   c                 C   s&  ddl m} t||ƒr |  |¡S |  ¡ }t|ttfƒrD| |g¡ nÞt|tƒrht	|ƒdkrh| 
|g¡ nºt|tƒrÂt	|ƒdkr¼t|d tƒr˜| 
|¡ qÀt|d ttfƒr¶| |¡ qÀtS n|S n`t|tƒrØ| |¡ nJt|tƒrî| |¡ n4t|tƒr| 
|¡ nt|tƒr| 
|¡ ntS |S )aÂ  Removes the given object(s) from the graph

    @param other: if it is an integer, removes the vertex with the given
      ID from the graph (note that the remaining vertices will get
      re-indexed!). If it is a tuple, removes the given edge. If it is
      a graph, takes the difference of the two graphs. Accepts
      lists of integers or lists of tuples as well, but they can't be
      mixed! Also accepts L{Edge} and L{EdgeSeq} objects.
    r   r'   r   )r)   r(   r   Ú
differencer*   r   r    r-   r"   r#   r.   r%   r&   r   r   r   r   )r   r   r(   Úresultr   r   r   r   ±   s4    




r   c                 C   sT   ddl m} t|tƒrP|dkr$|ƒ S |dkr0| S |dkrL|  | g|d  ¡S tS tS )zóCopies exact replicas of the original graph an arbitrary number of
    times.

    @param other: if it is an integer, multiplies the graph by creating the
      given number of identical copies and taking the disjoint union of
      them.
    r   r'   é   )r)   r(   r   r   r   r&   r,   r   r   r   r   Þ   s    	
r   c                 C   s(   ddl m} t||ƒr |  |¡S tS dS )zsGraph union operator.

    @param other: the other graph to take the union with.
    @return: the union graph.
    r   r'   N)r)   r(   r   r   r&   r,   r   r   r   r   ö   s    

r   N)r   )r   )Zigraph._igraphr   r   r   Z
igraph.seqr   r   Zigraph.operators.functionsr   r   r	   Ú__all__r   r   r   r
   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   

,-