
    WL1i                      P    d dl Z d dlZd Zd Zd Zd Zd Zd Zd Zd	 Z	d
 Z
d Zy)    Nc                 h   t        | d      }|j                         }t               t               t               }}}|D ]o  }|j                         j	                  d      \  }}|dk7  r|j                  |       |dk7  r|j                  |       |dk7  sW|dk7  s]|j                  ||f       q |||fS )Nr> )open	readlinessetstripsplitadd)	
nomfichierfichierlisteXGYflechexys	            :/home/zanotti/Dropbox/FAC/LINFO/UE12/TP/correspondances.pyLireCorrespondancer      s    :c"GEuSU35qQ $$S)17EE!H7EE!HG!r'EE1Q%L a7N    c           
      .   t        t        |             }t        t        |d            D cg c]  }t        |t	        d      z          c}t        t        d|dz
              D cg c]  }t        |t	        d      z          c}z   }||fS c c}w c c}w )N   ar   A)listrangeminchrordmax)nxnyr   cr   s        r   FillXYr&   %   s|    U2YA$)#b*$56qQS\	6UZ[^_`acdfaf[gUh9iPQ#a#c(l:K9iiAa5L 	79is   B&Bc                 ,   t        | d      t        |d      }} t        | |      \  }}t        |      }t        |      }t        t	        j
                  ||            }t        t        |      |      }t        t        j                  ||            }|||fS )ud   
    Génère une correspondance aléatoire.
    Défaut: construit le produit cartésien X x Y
    4   )	r   r&   r	   r   	itertoolsproductlenrandomsample)r#   r$   nbarcsr   r   allarcsr   s          r   Correspondancer0   *   s    
 2bz#b*R2bMEQqAAAA9$$Q*+GWv&FFMM'6*+Aa7Nr   c                     t        | d      t        |d      }} t        | |      \  }t        t        |      |      }t        j                  ||      }t        fd|D              }t        |      |t              fS )u+   
    Génère une fonction aléatoire.
    r(   c              3   L   K   | ]  }|t        j                        f  y wNr,   choice.0r   r   s     r   	<genexpr>zFonction.<locals>.<genexpr>E   s     /aQa !/   !$)r   r&   r+   r,   r-   r	   )r#   r$   r.   r   Defr   r   s         @r   Fonctionr;   9   sr     2r{3r2;R2bMEQq Q F --6
"C/3//AFAs1vr   c           	      f   t        | d      t        |d      }} t        | |      \  }t        | d      } t        |d      }t        t        |             }t        |      D cg c]  }t	        |t        d      z          c}t        fd|D              }t        |      |t              fS c c}w )u.   
    Génère une application aléatoire.
    r(   r   c              3   L   K   | ]  }|t        j                        f  y wr3   r4   r6   s     r   r8   zApplication.<locals>.<genexpr>V   s     -aQa !-r9   )r   r&   r   r   r    r!   r	   )r#   r$   r   r%   r   r   s        @r   Applicationr>   J   s     2r{CBKR2bMEQq	RB	RBU2YA$)"I.qQS\	.A-1--AFAs1v	 	/s   "B.c                     t        |d      }t        | |      } t        | |      \  }}t        j                  ||       }t	        t        ||            }t	        |      |t	        |      fS )u,   
    Génère une injection aléatoire.
    r(   )r   r&   r,   r-   r	   zip)r#   r$   r   r   YYr   s         r   	InjectionrB   Z   s]    
 
RB	RB2bMEQq	q"	BC"IAFAs1vr   c                 8   t        | d      } t        | |      }t        | |      \  }}t        j                  ||      }t	        t        ||            }|D ]-  }||vs|j                  |t        j                  |      f       / t	        |      |t	        |      fS )u-   
    Génère une surjection aléatoire.
    r(   )r   r&   r,   r-   r	   r@   r   r5   )r#   r$   r   r   XXr   r   s          r   
SurjectionrE   i   s     
RB	RB2bMEQq	q"	BC1IA (BwEE1V]]1%&'( FAs1vr   c                     t        | d      }|}t        ||      \  }}t        j                  |       t	        t        ||            }t	        |      |t	        |      fS )u,   
    Génère une bijection aléatoire.
    r(   )r   r&   r,   shuffler	   r@   )nr#   r$   r   r   r   s         r   	BijectionrI   {   sS     
QB	B2bMEQq
NN1C!HAFAs1vr   c                 |   | \  }}}t        d|       t        d|       t        d       t               }|D ]  }g }|D ]+  }||f|v s
|j                  |       |j                  |       - t	        |      dkD  sDt        dt        |      j                  d      dd	       t        d
j                  |              y )Nu	    Départ:u	   Arrivée:z Graphe:r   	   u   ↦ r   )endz, )printr	   appendr   r+   strrjustjoin)r%   r   r   r   Ir   IXr   s           r   DiagrammeSagittalrU      s    GQq	+a	+a	*A ! 	A!u{		!a	 r7Q;$s1v||A26$))B- !r   c                 .   | \  }}}|D ch c]  \  }}|	 }}}|D ch c]  \  }}|	 }}}|D ]  \  }}t        |d|        |j                  |      D ]  }t        |d        |j                  |      D ]  }t        d|        y c c}}w c c}}w )Nr   )rN   
difference)	r%   r   r   r   r   _Defcr   Imcs	            r   FormaterCorrespondancer[      s    GQq&1aAD&1aAC 1aa\\$ a\\# c! s
   BB)r)   r,   r   r&   r0   r;   r>   rB   rE   rI   rU   r[    r   r   <module>r]      s:    ,
" $!(	r   