Ñò
Ì ÆWc           @   s›   d  d k  l Z d  d k Td  d k Td  d k l Z d  d k l Z d  d k l	 Z	 d  d k
 Z d  d k Z d  d k Z d  d k Z d d	 d „  ƒ  YZ d S(
   iÿÿÿÿ(   t
   Parametres(   t   *(   t   Marche_travail(   t   Marche_biens(   t   MatriceNt	   Programmec           B   sò   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sü   g  } xé t  | i ƒ D]Ø } d } d } x> t  | i ƒ D]- }	 | i | |	 d j o | d 7} Pq8 q8 WxD t  | i ƒ D]3 }	 t }
 | i | |	 d j o | d 7} Pqy qy W| d j o" | d j o | i | | ƒ q | d 7} d GHq W| | f S(   Ni    i   s&   Un TA elimine dans supprimer agents TA(   t   ranget   mt   nt   datat   Truet   append(   t   selft
   matrice_TEt
   matrice_AVt   liste_agents_TAt   nb_TA_eliminest   liste_agents_TA_tmpt   it   compteur_TEt   compteur_AVt   jt   visited(    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   supprimer_agents_TA   s*      
	 
	
	c         C   sT  g  } g  }	 g  }
 g  } g  } g  } xt t  t | ƒ ƒ D]` } | | i d j  o5 |
 i | | ƒ | | | i 7} | d 7} d GHq7 | i | | ƒ q7 Wx‘ t  t | ƒ ƒ D]} } | | i d j  o0 | i | | ƒ | | | i 7} | d 7} q® |	 i | | ƒ | i | | ƒ | i | | ƒ q® W| } | } | | |	 | | | | f S(   Ni    i   s!   Un TA elimine dans faire faillite(   R   t   lent   cashR   (   R   t   dette_totaleR   t   liste_agents_EVt   liste_salaires_effectifst   liste_prix_indicatifsR   t   nb_EV_eliminest   new_liste_agents_TAt   new_liste_agents_EVt   TA_en_faillitet   EV_en_faillitet   new_liste_salaires_effectifst   new_liste_prix_indicatifsR   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   faire_faillite-   s4     
	 c         C   s  t  | ƒ } t  | ƒ } t | | ƒ } g  }	 xŒ t t  | ƒ ƒ D]x }
 | |
 | j oa g  } xG t t  | ƒ ƒ D]3 } | | | j o | i | i |
 | ƒ qp qp W|	 i | ƒ q@ q@ WxJ t | i ƒ D]9 } x0 t | i ƒ D] } |	 | | | i | | <qâ WqÌ W| } | S(   N(   R   R   R   R   R	   R   R   (   R   R   R   R   R   R    R   R   t   new_matrice_TEt	   bloc_datat   at
   ligne_datat   bR   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   reformer_matrice_TEN   s(         !c         C   s  t  | ƒ } t  | ƒ } t | | ƒ } g  }	 xŒ t t  | ƒ ƒ D]x }
 | |
 | j oa g  } xG t t  | ƒ ƒ D]3 } | | | j o | i | i |
 | ƒ qp qp W|	 i | ƒ q@ q@ WxP t t  | ƒ ƒ D]< } x3 t t  | ƒ ƒ D] } |	 | | | i | | <qè WqÏ W| } | S(   N(   R   R   R   R   R	   (   R   R   R   R   R   R    R   R   t   new_matrice_AVR'   R(   R)   R*   R   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   reformer_matrice_AVd   s(         !c         C   sp   |  i  | | | | ƒ \ } } | } |  i | | | | | ƒ } |  i | | | | | ƒ } | } | | | | f S(   N(   R   R+   R-   (   R   R   R   R   R   R   R   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   maj_matrices_initialisationz   s    c
      	   C   sµ   |  i  | | | | ƒ \ }
 } |  i | |
 | | | | |	 ƒ \ } } } } } } }	 |  i | | | | | ƒ } |  i | | | | | ƒ } | } | } | | | | | | | | |	 f	 S(   N(   R   R%   R+   R-   (   R   R   R   R   R   R   R   R   R   R   R   R   R    (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   maj_matrices†   s    6c         C   sf   d } x+ t  t | ƒ ƒ D] } | | | i 7} q Wx+ t  t | ƒ ƒ D] } | | | i 7} qG W| S(   Ni    (   R   R   R   (   R   R   R   t   sommeR   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   calculer_cash_total“   s      c   	   	   C   sß   t  i t d d ƒ ƒ } g  } | i d ƒ x1 t t | ƒ ƒ D] } | i d t | ƒ ƒ q> Wx+ t | ƒ D] } | i d t | ƒ ƒ ql Wx1 t t | ƒ ƒ D] } | i d t | ƒ ƒ q  W| i d ƒ | i | ƒ | S(   Ns   output_cash.csvt   wbt	   Iterations   Agent TAt   Migrants   Agent EVs   Cash total systeme(   t   csvt   writert   openR   R   R   t   strt   writerow(	   R   t   liste_agents_TA_initt   nb_migrantst   liste_agents_EV_initt   myfile_casht   donneesR   R   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   initialiser_fichier_cashŸ   s       c      	   C   s  g  } | i  | ƒ d } d } x[ t t | ƒ ƒ D]G } | | | j o# | d 7} | i  | | d ƒ q2 | i  d ƒ q2 Wx! t | ƒ D] } | i  d ƒ qŠ Wx[ t t | ƒ ƒ D]G } | | | j o# | d 7} | i  |	 | d ƒ q´ | i  d ƒ q´ W| i  |
 ƒ | i | ƒ d  S(   Ni    i   iigÿt   x(   R   R   R   R9   (   R   R=   t	   iterationR:   R   R;   R<   R   t   liste_cash_agents_TAt   liste_cash_agents_EVt   cash_total_systemeR>   t
   curseur_TAt
   curseur_EVR   R   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt%   collecter_donnees_cash_avant_migrants®   s*     
  
c      	   C   sf  g  } | i  | ƒ d } d } x[ t t | ƒ ƒ D]G } | | | j o# | d 7} | i  | | d ƒ q2 | i  d ƒ q2 Wd t | ƒ GHx[ t t | ƒ ƒ D]G } | | | j o# | d 7} | i  | | d ƒ qŸ | i  d ƒ qŸ Wx[ t t | ƒ ƒ D]G } | | | j o# | d 7} | i  |	 | d ƒ qý | i  d ƒ qý W| i  |
 ƒ | i | ƒ d  S(   Ni    i   iigÿs   len curseur TA : (   R   R   R   R8   R9   (   R   R=   RA   R:   R   R;   R<   R   RB   RC   RD   t   liste_init_migrantsR>   RE   RF   R   R   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt%   collecter_donnees_cash_apres_migrantsÅ   s2     
 
 
c         C   sp   t  i t d d ƒ ƒ } g  } | i d ƒ x1 t t | ƒ ƒ D] } | i d t | ƒ ƒ q> W| i | ƒ | S(   Ns   output_salaires.csvR2   R3   s   Salaire effectif agent EV(   R5   R6   R7   R   R   R   R8   R9   (   R   R<   t   myfile_salairesR>   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   initialiser_fichier_salairesã   s     c   	      C   sˆ   g  } | i  | ƒ d } x[ t t | ƒ ƒ D]G } | | | j o# | d 7} | i  | | d ƒ q, | i  d ƒ q, W| i | ƒ d  S(   Ni    i   iÿÿÿÿ(   R   R   R   R9   (	   R   RJ   RA   R<   R   R   R>   t   curseurR   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   collecter_donnees_salairesí   s     
c         C   sp   t  i t d d ƒ ƒ } g  } | i d ƒ x1 t t | ƒ ƒ D] } | i d t | ƒ ƒ q> W| i | ƒ | S(   Ns   output_prix.csvR2   R3   s   Prix indic agent EV(   R5   R6   R7   R   R   R   R8   R9   (   R   R<   t   myfile_prixR>   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   initialiser_fichier_prixú   s     c   	      C   sˆ   g  } | i  | ƒ d } x[ t t | ƒ ƒ D]G } | | | j o# | d 7} | i  | | d ƒ q, | i  d ƒ q, W| i | ƒ d  S(   Ni    i   iÿÿÿÿ(   R   R   R   R9   (	   R   RN   RA   R<   R   R   R>   RL   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   collecter_donnees_prix  s     
c         C   s   t  i t d d ƒ ƒ } | S(   Ns   output_temps.csvR2   (   R5   R6   R7   (   R   t   myfile_temps(    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   initialiser_fichier_temps  s    c         C   s$   g  } | i  | ƒ | i | ƒ d  S(   N(   R   R9   (   R   RQ   t   tempsR>   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   collecter_donnees_temps  s    c         C   sH   d } x+ t  t | ƒ ƒ D] } | | | i 7} q W| t | ƒ } | S(   Ni    (   R   R   R   (   R   R   R0   R(   t   moyenne_cash_TA(    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyRU     s     c         C   sH   d } x+ t  t | ƒ ƒ D] } | | | i 7} q W| t | ƒ } | S(   Ni    (   R   R   R   (   R   R   R0   R(   t   moyenne_cash_EV(    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyRV   #  s     c         C   s4   g  } x' t  t | ƒ ƒ D] } | i d ƒ q W| S(   Ni    (   R   R   R   (   R   R   t#   liste_salaires_effectifs_precedenteR   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt/   initialiser_liste_salaires_effectifs_precedente,  s
     c         C   s8   g  } x+ t  t | ƒ ƒ D] } | i | | ƒ q W| S(   N(   R   R   R   (   R   R   RW   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt'   maj_liste_salaires_effectifs_precedente3  s
     c         C   s4   g  } x' t  t | ƒ ƒ D] } | i d ƒ q W| S(   Ni    (   R   R   R   (   R   R   t    liste_prix_indicatifs_precedenteR   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt,   initialiser_liste_prix_indicatifs_precedente:  s
     c         C   s8   g  } x+ t  t | ƒ ƒ D] } | i | | ƒ q W| S(   N(   R   R   R   (   R   R   RZ   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt$   maj_liste_prix_indicatifs_precedenteA  s
     c         C   s•  g  } g  } x\ t  | i ƒ D]K }	 g  }
 x/ t  | i ƒ D] } |
 i | i |	 | ƒ q8 W| i |
 ƒ q Wg  } x\ t  | i ƒ D]K }	 g  }
 x/ t  | i ƒ D] } |
 i | i |	 | ƒ q W| i |
 ƒ q Wx= t  | ƒ D]/ } t d d ƒ } | i | ƒ | i | ƒ qÝ Wd t t | ƒ ƒ GHt | ƒ } t | ƒ } t | | ƒ } xP t  t | ƒ ƒ D]< }	 x3 t  t | ƒ ƒ D] } | |	 | | i |	 | <qxWq_Wt | ƒ } t | ƒ } x• t  | | ƒ D]„ } x{ t  t | ƒ ƒ D]g } | i	 d j o! t
 i d d ƒ | i | | <qàt
 i
 ƒ  } t | t | i	 ƒ ƒ | i | | <qàWqÇWt | ƒ } t | ƒ } t | | ƒ } xP t  t | ƒ ƒ D]< }	 x3 t  t | ƒ ƒ D] } | |	 | | i |	 | <q¢Wq‰Wt | ƒ } t | ƒ } x• t  | | ƒ D]„ } x{ t  t | ƒ ƒ D]g } | i d j o! t
 i d d ƒ | i | | <q
t
 i
 ƒ  } t | t | i ƒ ƒ | i | | <q
WqñW| } | } | | | | f S(   Ni   id   s   len nouvelle liste de TAg      à?i    i   (   R   R   R   R   R	   t   Agent_TAR8   R   R   t   proba_matrice_TEt   randomt   randintt   intt   floatt   proba_matrice_AV(   R   t
   parametresR   R   R;   R   R   t   matrice1RH   R   t   ligne_matriceR   t   matrice2R   t   migrantR   R&   t   Mt   It   rR,   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   integrer_migrantsI  s|           !  !,  !  !,c   $   $   C   s(  d } t  | d ƒ } zà| i ƒ  i d ƒ } | d =g  } | D] } | | i d d ƒ q? ~ } g  } | D] } | t | ƒ ql ~ } g  } | D] }	 | t d |	 ƒ q“ ~ }
 | i ƒ  i d ƒ } | d =g  } | D] } | | i d d ƒ qÙ ~ } g  } | D] } | t | ƒ q~ } | i ƒ  i d ƒ } | d =g  } xP | D]H } | i d d ƒ } | d j o
 d  } n t | ƒ } | i | ƒ qKW| i ƒ  i d ƒ } | d =g  } xP | D]H } | i d d ƒ } | d j o
 d  } n t | ƒ } | i | ƒ qÀWg  } xT t t	 | ƒ ƒ D]@ } | | }	 | | } | | } | i t
 |	 d | | ƒ ƒ q%W| i ƒ  i d ƒ } | d =g  } xP | D]H } | i d d ƒ } | d j o
 d  } n t | ƒ } | i | ƒ q’W| i ƒ  i d ƒ d	 } t | ƒ } | i ƒ  i d ƒ d	 } t | ƒ } t	 |
 ƒ } t	 | ƒ } t | | ƒ } x¼ t | i ƒ D]« } | i ƒ  i d ƒ } | d =g  } | D] } | | i d d ƒ qŒ~ } g  }  | D] } |  t t | ƒ ƒ q¹~  } x, t | i ƒ D] } | | | i | | <qëWq_Wt	 |
 ƒ } t	 | ƒ } t | | ƒ }! x¼ t |! i ƒ D]« } | i ƒ  i d ƒ } | d =g  }" | D] } |" | i d d ƒ qr~" } g  }# | D] } |# t t | ƒ ƒ qŸ~# } x, t |! i ƒ D] } | | |! i | | <qÑWqEWWd  | i ƒ  X| | | |! |
 | | | | | | f S(
   Ns   input_migrants.csvRk   t   ,i    s   
t    i   g      à?i   (   R7   t   readlinet   splitt   replaceRb   R]   t   NoneR   R   R   t   Agent_EVR   R   Ra   R   R	   t   close($   R   t   fnamet   fileRB   t   _[1]t   vt   _[2]t   valeurt   _[3]R   R   RC   t   _[4]t   _[5]t   liste_salaires_indicatifs_strt   liste_salaires_indicatifst   liste_prix_indicatifs_strR   R   R   t   salairet   prixt   liste_benefices_entreprises_strt   liste_benefices_entreprisesRD   R   R   R   R   R   t   lignet   _[6]t   _[7]R   t   _[8]t   _[9](    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   lire_input_migrants‰  sž    -'*-' 
 
 


  
 --  -- !c         C   sr   g  } g  } x+ t  t | ƒ ƒ D] } | i | | ƒ q Wx+ t  t | ƒ ƒ D] } | i | | ƒ qM W| | f S(   N(   R   R   R   (   R   R   R   R:   R<   R   R   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   conserver_listes_agents_initæ  s      c   '      C   sÀ  t  i ƒ  } d GHt d ƒ } | i ƒ  t | i ƒ } t | ƒ } t | ƒ } d } d } d } d GH|  i ƒ  \ }	 } }
 } } } } } } } } t	 i
 t i i | i d ƒ |
 i d d d d	 ƒt	 i
 t i i | i d
 ƒ |
 i d d d d	 ƒ|  i | | ƒ \ } } |  i | | | ƒ } |  i | ƒ } |  i | ƒ } |  i ƒ  } |  i | d | | | | | | | |	 ƒ
 |  i | d | | | ƒ |  i | d | | | ƒ |  i | ƒ } |  i | ƒ } d GHxt d d ƒ D]} d t | ƒ GH|  i | ƒ } |  i | ƒ } | i |
 | | | | ƒ \ }
 } } } }  }! }" | i | | | | | |  |" | | ƒ	 \ } } }# }$ } |  i  | |
 | | | |! | | | ƒ	 \	 } } }
 } } }! } } } | d d j p | | i! d j oz t	 i
 t i i | i d t | ƒ ƒ |
 i d d d d	 ƒt	 i
 t i i | i d t | ƒ ƒ |
 i d d d d	 ƒn t" | ƒ } t# | ƒ } |  i$ | | ƒ }	 |  i | | | | | | | | | |	 ƒ
 |  i | | | | | ƒ |  i | | | | | ƒ d GHqØW|  i% | | | | |
 | ƒ \ } }
 } }% t	 i
 t i i | i d t d ƒ ƒ |
 i d d d d	 ƒt	 i
 t i i | i d t d ƒ ƒ |
 i d d d d	 ƒxt d | i! ƒ D]} d t | ƒ GH| i |
 | | | | ƒ \ }
 } } } }  }! }" | i | | | | | |  |" | | ƒ	 \ } } }# }$ } |  i  | |
 | | | |! | | | ƒ	 \	 } } }
 } } }! } } } | d d j p | | i! d j oz t	 i
 t i i | i d t | ƒ ƒ |
 i d d d d	 ƒt	 i
 t i i | i d t | ƒ ƒ |
 i d d d d	 ƒn t" | ƒ } t# | ƒ } |  i$ | | ƒ }	 |  i& | | | | | | | | | |	 |% ƒ |  i | | | | | ƒ |  i | | | | | ƒ |  i |! ƒ } |  i | ƒ } d GHq’Wt  i ƒ  | }& |  i' | |& ƒ d  S(   Nt   INITIALISATIONs	   input.txti    t   RECUPERATIONt   matrice_TE0t   fmts   %it	   delimiters   	t   matrice_AV0t   Initialisations   
i   i
   s
   ITERATION R   R   t   matrice_TE_migrantst   matrice_AV_migrantss   ITERATION AVEC MIGRANTS ((   t   timet   clockR    t   parseRa   R;   R   R   RŠ   t   npt   savetxtt   ost   patht   joint   dossierR	   R‹   R?   RK   RO   RR   RG   RM   RP   RU   RV   R   R8   RY   R\   t
   travaillert   faire_tourner_marches_biensR/   t   itt   obtenir_liste_cash_agents_TAt   obtenir_liste_cash_agents_EVR1   Rl   RI   RT   ('   R   t   t0Rd   R;   t   marche_travailt   marche_biensR   R   R   RD   R   R   R   R   R   R   RB   RC   R„   R:   R<   R=   RJ   RN   RQ   RU   RV   RA   RW   RZ   t   repartition_heures_travailleurst   liste_total_heurest   liste_production_entreprisesR   t   liste_payes_totales_employest   repartition_cash_acheteurst    somme_repartition_cash_acheteursRH   RS   (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   runô  s„    
-11( 06B%;?(	*;; 06B%;?+	(   t   __name__t
   __module__R   R%   R+   R-   R.   R/   R1   R?   RG   RI   RK   RM   RO   RP   RR   RT   RU   RV   RX   RY   R[   R\   Rl   RŠ   R‹   R¬   (    (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyR      s4   		!									
		
											@	]	(    (   Rd   R    t   agenttat   agentevt   marchetravailR   t   marchebiensR   t   matriceR   t   numpyR˜   Rš   R5   R•   R   (    (    (    s*   /home/kaufmanl/SIMU/Migrants1/programme.pyt   <module>   s   

