
Wc           @   s   d  d l  m Z d  d l Td  d l Td  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 Z d  d l Z d  d l Z d  d l 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  | j  D] } d } d } x< t  | j  D]+ }	 | j | |	 d k r8 | d 7} Pq8 q8 WxB t  | j  D]1 }	 t }
 | j | |	 d k rw | d 7} Pqw qw W| d k r | d k r | j | |  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(    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   supprimer_agents_TA   s$    


	c         C   sP  g  } g  }	 g  }
 g  } g  } g  } xr t  t |   D]^ } | | j d k  r |
 j | |  | | | j 7} | d 7} d GHq7 | j | |  q7 Wx t  t |   D]{ } | | j d k  r | j | |  | | | j 7} | d 7} q |	 j | |  | j | |  | j | |  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   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   faire_faillite-   s0    
c         C   s  t  |  } t  |  } t | |  } g  }	 x t t  |   D]t }
 | |
 | k r@ g  } xE t t  |   D]1 } | | | k ro | j | j |
 |  qo qo W|	 j |  q@ q@ WxJ t | j  D]9 } x0 t | j  D] } |	 | | | j | | <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   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   reformer_matrice_TEN   s     !c         C   s  t  |  } t  |  } t | |  } g  }	 x t t  |   D]t }
 | |
 | k r@ g  } xE t t  |   D]1 } | | | k ro | j | j |
 |  qo qo W|	 j |  q@ q@ WxP t t  |   D]< } x3 t t  |   D] } |	 | | | j | | <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   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   reformer_matrice_AVd   s     !c         C   sp   |  j  | | | |  \ } } | } |  j | | | | |  } |  j | | | | |  } | } | | | | f S(   N(   R   R+   R-   (   R   R   R   R   R   R   R   R   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   maj_matrices_initialisationz   s    c
      	   C   s   |  j  | | | |  \ }
 } |  j | |
 | | | | |	  \ } } } } } } }	 |  j | | | | |  } |  j | | | | |  } | } | } | | | | | | | | |	 f	 S(   N(   R   R%   R+   R-   (   R   R   R   R   R   R   R   R   R   R   R   R   R    (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   maj_matrices   s    6c         C   sf   d } x+ t  t |   D] } | | | j 7} q Wx+ t  t |   D] } | | | j 7} qG W| S(   Ni    (   R   R   R   (   R   R   R   t   sommeR   R   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   calculer_cash_total   s    c   	      C   s   t  j t d d   } g  } | j d  x1 t t |   D] } | j d t |   q> Wx+ t |  D] } | j d t |   ql Wx1 t t |   D] } | j d t |   q W| j d  | j |  | 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   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   initialiser_fichier_cash   s    c         C   s  g  } | j  |  d } d } xY t t |   D]E } | | | k rj | d 7} | j  | | d  q2 | j  d  q2 Wx! t |  D] } | j  d  q WxY t t |   D]E } | | | k r | d 7} | j  |	 | d  q | j  d  q W| j  |
  | j |  d  S(   Ni    i   iigt   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   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt%   collecter_donnees_cash_avant_migrants   s$    

c         C   s`  g  } | j  |  d } d } xY t t |   D]E } | | | k rj | d 7} | j  | | d  q2 | j  d  q2 Wd t |  GHxY t t |   D]E } | | | k r | d 7} | j  | | d  q | j  d  q WxY t t |   D]E } | | | k r1| d 7} | j  |	 | d  q | j  d  q W| j  |
  | j |  d  S(   Ni    i   iigs   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   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt%   collecter_donnees_cash_apres_migrants   s,    


c         C   sp   t  j t d d   } g  } | j d  x1 t t |   D] } | j d t |   q> W| j |  | 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   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   initialiser_fichier_salaires   s    c   	      C   s   g  } | j  |  d } xY t t |   D]E } | | | k rd | d 7} | j  | | d  q, | j  d  q, W| j |  d  S(   Ni    i   i(   R   R   R   R9   (	   R   RJ   RA   R<   R   R   R>   t   curseurR   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   collecter_donnees_salaires   s    
c         C   sp   t  j t d d   } g  } | j d  x1 t t |   D] } | j d t |   q> W| j |  | 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   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   initialiser_fichier_prix   s    c   	      C   s   g  } | j  |  d } xY t t |   D]E } | | | k rd | d 7} | j  | | d  q, | j  d  q, W| j |  d  S(   Ni    i   i(   R   R   R   R9   (	   R   RN   RA   R<   R   R   R>   RL   R   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   collecter_donnees_prix  s    
c         C   s   t  j t d d   } | S(   Ns   output_temps.csvR2   (   R5   R6   R7   (   R   t   myfile_temps(    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   initialiser_fichier_temps  s    c         C   s$   g  } | j  |  | j |  d  S(   N(   R   R9   (   R   RQ   t   tempsR>   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   collecter_donnees_temps  s    c         C   sH   d } x+ t  t |   D] } | | | j 7} q W| t |  } | S(   Ni    (   R   R   R   (   R   R   R0   R(   t   moyenne_cash_TA(    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyRU     s
    c         C   sH   d } x+ t  t |   D] } | | | j 7} q W| t |  } | S(   Ni    (   R   R   R   (   R   R   R0   R(   t   moyenne_cash_EV(    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyRV   #  s
    c         C   s4   g  } x' t  t |   D] } | j d  q W| S(   Ni    (   R   R   R   (   R   R   t#   liste_salaires_effectifs_precedenteR   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt/   initialiser_liste_salaires_effectifs_precedente,  s    c         C   s8   g  } x+ t  t |   D] } | j | |  q W| S(   N(   R   R   R   (   R   R   RW   R   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt'   maj_liste_salaires_effectifs_precedente3  s    c         C   s4   g  } x' t  t |   D] } | j d  q W| S(   Ni    (   R   R   R   (   R   R   t    liste_prix_indicatifs_precedenteR   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt,   initialiser_liste_prix_indicatifs_precedente:  s    c         C   s8   g  } x+ t  t |   D] } | j | |  q W| S(   N(   R   R   R   (   R   R   RZ   R   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt$   maj_liste_prix_indicatifs_precedenteA  s    c         C   s  g  } g  } x\ t  | j  D]K }	 g  }
 x/ t  | j  D] } |
 j | j |	 |  q8 W| j |
  q Wg  } x\ t  | j  D]K }	 g  }
 x/ t  | j  D] } |
 j | j |	 |  q W| j |
  q Wx= t  |  D]/ } t d d  } | j |  | j |  q Wd t t |   GHt |  } t |  } t | |  } xP t  t |   D]< }	 x3 t  t |   D] } | |	 | | j |	 | <qxWq_Wt |  } t |  } x t  | |  D] } xy t  t |   D]e } | j	 d k rt
 j d d  | j | | <qt
 j
   } t | t | j	   | j | | <qWqWt |  } t |  } t | |  } xP t  t |   D]< }	 x3 t  t |   D] } | |	 | | j |	 | <qWqWt |  } t |  } x t  | |  D] } xy t  t |   D]e } | j d k r=t
 j d d  | j | | <qt
 j
   } t | t | j   | j | | <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,   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   integrer_migrantsI  sb    ! ,! ,c         C   s  d } t  | d  } z| j   j d  } | d =g  | D] } | j d d  ^ q; } g  | D] } t |  ^ q` } g  | D] } t d |  ^ q } | j   j d  } | d =g  | D] } | j d d  ^ q } g  | D] } t |  ^ q } | j   j d  }	 |	 d =g  }
 xN |	 D]F } | j d d  } | d k rPd  } n t |  } |
 j |  q#W| j   j d  } | d =g  } xN | D]F } | j d d  } | d k rd  } n t |  } | j |  qWg  } xT t t	 |   D]@ } | | } |
 | } | | } | j t
 | d | |   qW| j   j d  } | d =g  } xN | D]F } | j d d  } | d k rd  } n t |  } | j |  qfW| j   j d  d	 } t |  } | j   j d  d	 } t |  } t	 |  } t	 |  } t | |  } x t | j  D] } | j   j d  } | d =g  | D] } | j d d  ^ qZ} g  | D] } t t |   ^ q} x, t | j  D] } | | | j | | <qWq1Wt	 |  } t	 |  } t | |  } x t | j  D] } | j   j d  } | d =g  | D] } | j d d  ^ q0} g  | D] } t t |   ^ qU} x, t | j  D] } | | | j | | <qWqWWd  | j   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   vt   valeurR   R   RC   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   ligneR   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   lire_input_migrants  s    %"%		


 	%%%%!c         C   sr   g  } g  } x+ t  t |   D] } | j | |  q Wx+ t  t |   D] } | j | |  qM W| | f S(   N(   R   R   R   (   R   R   R   R:   R<   R   R   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   conserver_listes_agents_init  s    c   '      C   s  t  j   } d GHt d  } | j   t | j  } t |  } t |  } d } d } d } d GH|  j   \ }	 } }
 } } } } } } } } t	 j
 t j j | j d  |
 j d d d d	 t	 j
 t j j | j d
  | j d d d d	 |  j | |  \ } } |  j | | |  } |  j |  } |  j |  } |  j   } |  j | d | | | | | | | |	 
 |  j | d | | |  |  j | d | | |  |  j |  } |  j |  } d GHxt d d  D] } d t |  GH|  j |  } |  j |  } | j |
 | | | |  \ }
 } } } }  }! }" | j | | | | | |  |" | | 	 \ } } }# }$ } |  j  | |
 | | | |! | | | 	 \	 } } }
 } } }! } } } | d d k s| | j! d k rOt	 j
 t j j | j d t |   |
 j d d d d	 t	 j
 t j j | j d t |   | j d d d d	 n  t" |  } t# |  } |  j$ | |  }	 |  j | | | | | | | | | |	 
 |  j | | | | |  |  j | | | | |  d GHqW|  j% | | | | |
 |  \ } }
 } }% t	 j
 t j j | j d t d   |
 j d d d d	 t	 j
 t j j | j d t d   | j d d d d	 xt d | j!  D]} d t |  GH| j |
 | | | |  \ }
 } } } }  }! }" | j | | | | | |  |" | | 	 \ } } }# }$ } |  j  | |
 | | | |! | | | 	 \	 } } }
 } } }! } } } | d d k so| | j! d k rt	 j
 t j j | j d t |   |
 j d d d d	 t	 j
 t j j | j d t |   | j d d d d	 n  t" |  } t# |  } |  j$ | |  }	 |  j& | | | | | | | | | |	 |%  |  j | | | | |  |  j | | | | |  |  j |!  } |  j |  } d GHqWt  j   | }& |  j' | |&  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   Rz   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   (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\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   (    (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyR      s4   		!									
		
											@	]	(    (   Rd   R    t   agenttat   agentevt   marchetravailR   t   marchebiensR   t   matriceR   t   numpyR   R   R5   R   R   (    (    (    sK   C:\Users\La\Desktop\Genve - A conserver\Simulation_120_30\6M\programme.pyt   <module>   s   

