Simulateur_v18_FR_parti_500

Simulateur_v18_FR_parti_500 preview image

1 collaborator

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.0.3 • Viewed 95 times • Downloaded 11 times • Run 0 times
Download the 'Simulateur_v18_FR_parti_500' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Info tab cannot be displayed because of an encoding error

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

extensions [sound]

turtles-own [meme
             pre
             infl_list
             ]

globals [nb
         nb_cible
         essais
         ratio
         in
         out
         bruit
         effet
         base
         compression
         forme
         exclusion
         ;in
         rn
         co
         meme_2
         meme_R
         pre_R
         host
         change
         pole
         total
         percentage
         go_trans
         transfert
         trans_cible
         couleur_de
         couleur_vers
         PQ_de
         CAQ_de
         QS_de
         PLQ_de
         PQ_vers
         CAQ_vers
         QS_vers
         PLQ_vers
         PQ_CAQ_%
         PQ_QS_%
         PQ_PLQ_%
         CAQ_PQ_%
         CAQ_QS_%
         CAQ_PLQ_%
         QS_PQ_%
         QS_CAQ_%
         QS_PLQ_%
         PLQ_PQ_%
         PLQ_CAQ_%
         PLQ_QS_%
         ji
         p_class1 p_class2
         p_class3
         p_class4
         in_data
         iteration
         fvote
         file-in file-out file-config file-attenuer file-saisir file-format file-recit file-vote
         inscription
         list_data
         percent
         autolink
         Dif
         TermMoins TermPlus
         limite_gauche_PQ limite_droite_PQ
         limite_gauche_PLQ limite_droite_PLQ
         limite_gauche_CAQ limite_droite_CAQ
         limite_gauche_QS limite_droite_QS
         prégnance_basse_PQ prégnance_haute_PQ
         prégnance_basse_PLQ prégnance_haute_PLQ
         prégnance_basse_CAQ prégnance_haute_CAQ
         prégnance_basse_QS prégnance_haute_QS
         prégnance_PQ prégnance_PLQ prégnance_CAQ prégnance_QS
         déplacer_PQ déplacer_PLQ déplacer_CAQ déplacer_QS
         debut_even_PQ debut_even_CAQ debut_even_QS debut_even_PLQ
         fin_even_PQ fin_even_CAQ fin_even_QS fin_even_PLQ
         PQ CAQ PLQ QS Tous
         PQ_1 CAQ_1 PLQ_1 QS_1
         PQ_2 CAQ_2 PLQ_2 QS_2
         PQ_3a PQ_3b CAQ_3 PLQ_3a PLQ_3b QS_3
         vote_PQ vote_CAQ vote_QS vote_PLQ
         tot_percent
         tot_class1 tot_class2 tot_class3 tot_class4
         Adhérents_PQ Adhérents_CAQ Adhérents_QS Adhérents_PLQ
         côté_PQ côté_CAQ côté_QS côté_PLQ
         u1
         u2
         w1
         w2
         s
         z
         f01 f02 f03 f04 f05 f06 f07 f08 f09 f10
         f11 f12 f13 f14 f15 f16 f17 f18 f19 f20
         f21 f22 f23 f24 f25 f26 f27 f28 f29 f30
         f31 f32 f33 f34 f35 f36 f37 f38 f39 f40
         d_PQ lg_PQ ld_PQ p_PQ pb_PQ ph_PQ de_PQ fe_PQ
         d_CAQ lg_CAQ ld_CAQ p_CAQ pb_CAQ ph_CAQ de_CAQ fe_CAQ
         d_QS lg_QS ld_QS p_QS pb_QS ph_QS de_QS fe_QS
         d_PLQ lg_PLQ ld_PLQ p_PLQ pb_PLQ ph_PLQ de_PLQ fe_PLQ
         seq zéro
         ]

to randomize  ;; générer des variables aléatoires normalisées
  set u1 random-float 1
  set u2 random-float 1
  set w1 (2 * u1 - 1)
  set w2 (2 * u2 - 1)
  set s ((w1 ^ 2) + (w2 ^ 2))
  if s <= 1
     [set z (w1 * sqrt(-2 * ln s / s) * random bruit / 10)]
end 

to config
  set valeurs false
  set go_trans false
  set PQ_CAQ_% 0
  set PQ_QS_% 0
  set PQ_PLQ_% 0
  set CAQ_PQ_% 0
  set CAQ_QS_% 0
  set CAQ_PLQ_% 0
  set PLQ_PQ_% 0
  set PLQ_CAQ_% 0
  set PLQ_QS_% 0
  set PQ_de false
  set CAQ_de false
  set QS_de false
  set PLQ_de false
  set PQ_vers false
  set CAQ_vers false
  set QS_vers false
  set PLQ_vers false
  set récit false
  set fvote false
  ;set repet_even false
  if niveau = true [set pole_droit true]
  file-close-all
  clear-ticks
  clear-turtles
  clear-all-plots
  clear-output
  set bruit 6 ;; bruit stochastique simulant l'effet de variables intermédiaires affectant la transmission
  set effet 2 ;; facteur diminuant la distribution des agents sur l'ordonnée
  set base 1.06 ;; facteur diminuant la distribution des agents sur l'abscisse
  set compression 4 ;; facteur comprimant la distribution des agents vers le bas simulant une diminution de prégnance
  if pole_droit = true [set pole true ]
  if pole_droit = true [set Droit% true]
  set nb 1
  set iteration 1
  set nb_cible 1
  set essais 0
  set change 0
  set total 0
  ask patches [ set pcolor lime]
  draw
  set-default-shape turtles "person"
  reset-ticks
  set out false
  set in false
  set forme false
  set inscription false
  set tot_percent 0
  set percentage 0
  set tot_class1 0
  set tot_class2 0
  set tot_class3 0
  set tot_class4 0
  set PQ_2 0
  set CAQ_2 0
  set QS_2 0
  set PLQ_2 0
  set vote_PQ 0
  set vote_CAQ 0
  set vote_QS 0
  set vote_PLQ 0
  if limite_iters = 0 [set limite_iters limite_iters + 1]
end 

to draw  ;; dessiner les axes
  ask patches [if pxcor = 0 and pxcor <= 30 [set pcolor gray]
               if pycor = 0 and pycor <= 30 [set pcolor gray]]
  ask patch  -5  0 [set pcolor violet]
  ask patch  -10  0 [set pcolor violet]
  ask patch  -15  0 [set pcolor violet]
  ask patch  -20  0 [set pcolor violet]
  ask patch  -25  0 [set pcolor violet]
  ask patch  -30  0 [set pcolor violet]
  ask patch  0  0 [set pcolor violet]
  ask patch  5  0 [set pcolor violet]
  ask patch  10  0 [set pcolor violet]
  ask patch  15  0 [set pcolor violet]
  ask patch  20  0 [set pcolor violet]
  ask patch  25  0 [set pcolor violet]
  ask patch  30  0 [set pcolor violet]
  ask patch  0  5 [set pcolor violet]
  ask patch  0  10 [set pcolor violet]
  ask patch  0  15 [set pcolor violet]
  ask patch  0  20 [set pcolor violet]
  ask patch  0  25 [set pcolor violet]
  ask patch  0  30 [set pcolor violet]
end 

to go
  if f01 != 0 [set forme true]
  ifelse forme = true [if in = false and (pole_droit = true or valeurs = true or Droit% = true) [user-message "Données manquantes du fichier d'entrée" stop]]
    [user-message "Fichier manquant du format des données" stop]
  ifelse out = false and in = false [user-message "Fichier de sortie inexistant" stop] [if out = false [user-message "Fichier de sortie inexistant" stop]]
  if PQ_1 != true or PLQ_1 != true [user-message "SVP gérez l'entourage avant de lancer la simulation" stop]
  set nb 1
  if pole_droit = false [set pole false]
  ask turtles [set co (exp(abs(meme)))
               set host who
               if limite_gauche  > limite_droite [set limite_droite limite_gauche  + 1] ;; faire suivre la limite droite de l'événement en fonction de la limite gauche

               randomize
               transmission
;écriture des paramètres des agents lors de chaque itération dans le fichier de sortie
               if out = true and valeurs = true [file-open file-out file-write  who file-write meme file-write pre file-write infl_list file-close]
               ]
    tick

    if inscription = true [inscrire_vote]

    set percent (change / total * 100) ;;calcul des pourcentages d'agents du côté droit en totalité et par parti
                    set percentage count turtles with [meme > 0]
                    set percentage precision (percentage / échantillon * 100) 0
                    set p_class1 count turtles with [color = blue and meme > 0]
                    set p_class1 precision (p_class1 / count turtles with [color = blue] * 100) 0
                    set p_class4 count turtles with [color = red and meme > 0]
                    set p_class4 precision (p_class4 / count turtles with [color = red] * 100) 0
                    set p_class2 count turtles with [color = magenta and meme > 0]
                    set p_class2 precision (p_class2 / count turtles with [color = magenta] * 100) 0
                    set p_class3 count turtles with [color = orange and meme > 0]
                    set p_class3 precision (p_class3 / count turtles with [color = orange] * 100) 0
;paramètres d'estimation du vote
ifelse PQ_on = true [set PQ_3a count turtles with [color = blue and meme < 0] * PQ->Xg% / 100] [set PQ_3a 0] ;; 35%
ifelse PQ_on = true [set PQ_3b count turtles with [color = blue and meme > 0] * PQ->Xd% / 100] [set PQ_3b 0] ;; 25%
ifelse CAQ_on = true [set CAQ_3 count turtles with [color = magenta and meme > 0] * CAQ->Xd% / 100] [set CAQ_3 0] ;; 85%
ifelse QS_on = true [set QS_3 count turtles with [color = orange and meme > 0] * QS->Xd% / 100] [set QS_3 0] ;; 10%
ifelse PLQ_on = true [set PLQ_3b count turtles with [color = red and meme < 0] * PLQ->Xg% / 100] [set PLQ_3b 0] ;; 25%
ifelse PLQ_on = true [set PLQ_3a count turtles with [color = red and meme > 0] * PLQ->Xd% / 100] [set PLQ_3a 0] ;; 24%

set vote_PQ round ((count turtles with [color = blue and meme > 0] - (PQ_3a + PQ_3b) + CAQ_3 + QS_3 + (PLQ_3a * PQ<-PLQ% / 100)) / échantillon * 100) ;; 100%
set vote_CAQ round ((count turtles with [color = magenta] - CAQ_3 + (PQ_3a * CAQ<-PQ% / 100) + (PLQ_3b * CAQ<-PLQ% / 100)) / échantillon * 100) ;; 80% 80%
set vote_QS round ((count turtles with [color = orange] + PQ_3b + (PLQ_3b * (100 - CAQ<-PLQ%) / 100) + (PLQ_3a * (100 - PQ<-PLQ%) / 100)  - QS_3) / échantillon * 100)
set vote_PLQ round ((count turtles with [color = red] - (PLQ_3a + PLQ_3b) + (PQ_3a * (100 - CAQ<-PQ%) / 100)) / échantillon * 100)


;écriture dans le fichier de sortie des estimations du vote suivi de l'écriture dans le fichier de sortie des résultats du côté "POUR"
if fvote = false and valeurs = false [
  if estimation = true or Droit% = true or pole_droit = true [file-open file-out]
ifelse estimation = true [file-write vote_PQ file-write "; " file-write vote_CAQ file-write "; " file-write vote_QS file-write "; " file-write vote_PLQ file-write "; "] [if Droit% = true [file-write " ; ; ; ; "]]
ifelse Droit% = true  [file-write percentage file-write "; " file-write p_class1 file-write "; " file-write p_class2 file-write "; " file-write p_class3 file-write "; " file-write p_class4 file-write "; " file-write iteration file-write "; "  file-print essais + 1 file-close] [if pole_droit = true [file-write " ; ; ; ; " file-write iteration file-write "; "  file-print essais + 1 file-close]]
    if niveau  = true and iteration > debut_iters [if count turtles with [meme > 0] / échantillon * 100 > niveau_bas and count turtles with [meme > 0] / échantillon * 100 < niveau_haut [if pole = true [set percentage count turtles with [meme > 0] set percentage precision (percentage / échantillon * 100) 1
                   if Droit% = false [file-open file-out file-write percentage file-write "; "   file-write p_class1 file-write "; " file-write p_class2 file-write "; " file-write p_class3 file-write "; " file-write p_class4 file-write "; " file-print iteration file-close
                   set tot_percent tot_percent + percentage set tot_class1 tot_class1 + p_class1 set tot_class2 tot_class2 + p_class2 set tot_class3 tot_class3 + p_class3 set tot_class4 tot_class4 + p_class4]]
      ]
      set nb_cible nb_cible + 1
      set essais essais + 1
      if nb_cible > cible and pole_droit = true [if paramétrage = true [parametres] sound:play-note "Tubular Bells" 60 64 1 stop]
      if nb_cible <= cible [data reset-ticks clear-plot set iteration 0]]]
    if iteration >= nb_iters and nb_iters != 0 [ifelse pole_droit = true or estimation = true [set essais essais + 1 data reset-ticks clear-plot set iteration 0] [if out = true [if valeurs = false and (pole_droit = true or Droit% = true) [if paramétrage = true [parametres]]] sound:play-note "Tubular Bells" 60 64 1 stop]]
    set iteration iteration + 1
    ;;rafraichir le graphique
   if ticks > 25 [reset-ticks
                        clear-plot]
   if nb_essais > 0 and nb_essais < essais + 1 [if out = true [if valeurs = false [if paramétrage = true [parametres]]] sound:play-note "Tubular Bells" 60 64 1 stop]
end 

to transmission  ;; procéder à la transmission mémétique

   ask in-link-neighbors [set total total + 1
                          if repet_even = true [event] ;;commande par catégorie reproduisant l'événement avant chaque transmission.
    if [pre] of self > [pre] of myself and ([pre] of self - [pre] of myself >= écart_bas and [pre] of self - [pre] of myself < écart_haut)
                                            [set meme_R ([meme] of self)
                                             set pre_R ([pre] of self)
                                            ifelse (([meme] of self < 0 and [meme] of myself > 0) or ([meme] of self > 0 and [meme] of myself < 0))
                                            [set meme_2 [meme] of myself * -1
                                                     set change change + 1
 ;calcul de l'effet de l'entourage pour l'agent ciblé
   if PQ_1 = true and côté_PQ = "POUR" and [color] of myself = blue and [meme_2] of myself < 0 [if count in-link-neighbors with [meme > 0] > influenceurs - Adhérents_PQ [set meme_2 meme_2 * -1 set change change - 1]] ;; atténuation du changement de côté en fonction du nombre d'influenceurs du côté opposé
   if PQ_1 = true and côté_PQ = "CONTRE" and [color] of myself = blue and [meme_2] of myself > 0 [if count in-link-neighbors with [meme < 0] > influenceurs - Adhérents_PQ [set meme_2 meme_2 * -1 set change change - 1]]
   if CAQ_1 = true and côté_CAQ = "CONTRE"and [color] of myself = magenta and [meme_2] of myself > 0 [if count in-link-neighbors with [meme < 0] > influenceurs - Adhérents_CAQ [set meme_2 meme_2 * -1 set change change - 1]]
   if CAQ_1 = true and côté_CAQ = "POUR" and [color] of myself = magenta and [meme_2] of myself < 0 [if count in-link-neighbors with [meme > 0] > influenceurs - Adhérents_CAQ [set meme_2 meme_2 * -1 set change change - 1]]
   if QS_1 = true and côté_QS = "POUR"and [color] of myself = orange and [meme_2] of myself < 0 [if count in-link-neighbors with [meme > 0] > influenceurs - Adhérents_QS [set meme_2 meme_2 * -1 set change change - 1]]
   if QS_1 = true and côté_QS = "CONTRE" and [color] of myself = orange and [meme_2] of myself > 0 [if count in-link-neighbors with [meme < 0] > influenceurs - Adhérents_QS [set meme_2 meme_2 * -1 set change change - 1]]
    if PLQ_1 = true and côté_PLQ = "POUR" and [color] of myself = red and [meme_2] of myself < 0 [if count in-link-neighbors with [meme > 0] > influenceurs - Adhérents_PLQ [set meme_2 meme_2 * -1 set change change - 1]]
   if PLQ_1 = true and côté_PLQ = "CONTRE"and [color] of myself = red and [meme_2] of myself > 0 [if count in-link-neighbors with [meme < 0] > influenceurs - Adhérents_PLQ [set meme_2 meme_2 * -1 set change change - 1]]]
                                                       [set meme_2 [meme] of myself]


                                             if pre_R > [pre] of myself  [set meme_2 (meme_2 + (meme_R * pre_R / co * [pre] of myself) + z * bruit) / base]
                                             ifelse meme_2 >= 0 [if abs(meme_2) >= limites [set meme_2 (limites - random-float bruit)]]
                                                                [if abs(meme_2) >= limites [set meme_2 (limites - random-float bruit) * -1]]

                                     ask turtle host [pregnance
                                     set meme meme_2
                                     set xcor meme
                                     if pre > limites [set pre limites]
                                     if pre < 0 [set pre 0]
                                     set ycor pre
                                     ]

 ]]
end 

to pregnance ;; calculer la prégnance après la transmission mémétique
  randomize
  Set Dif (abs(meme_2 - meme)) / compression
  Set TermMoins (pre - Dif + z) / base
  Set TermPlus (pre + Dif + z) / base
  ifelse pre >= abs(meme_2) - effet
     [if TermMoins >= 0 and TermMoins <= limites [set pre TermMoins]]
     [if TermPlus >= 0 and TermPlus <= limites [set pre TermPlus]]
  if pre <= 0 [set pre random-float bruit]
end 

to event ;; produire un événement
set exclusion 1
  If Récit = true [set seq 0 while [seq <= 9] [ if iteration >= item seq de_PQ and iteration <= item seq fe_PQ
    [set debut_even_PQ item seq de_PQ set fin_even_PQ item seq fe_PQ set limite_gauche_PQ item seq lg_PQ set limite_droite_PQ item seq ld_PQ
       set prégnance_PQ item seq p_PQ set prégnance_haute_PQ item seq ph_PQ set prégnance_basse_PQ item seq pb_PQ set déplacer_PQ item seq d_PQ] set seq seq + 1]]

  if PQ = true or Tous = true  [if (iteration >= debut_even_PQ and iteration <= fin_even_PQ) or (debut_even = 0 and fin_even = 0) [ask turtles with [color = blue] [if meme > limite_gauche_PQ  and  meme < limite_droite_PQ and pre < prégnance_haute_PQ and pre > prégnance_basse_PQ [set meme_2 meme
                                                              set meme_2 meme_2 + déplacer_PQ
                                                              ifelse meme_2 >= 0 [if abs(meme_2) >= limites [set meme_2 (limites - random-float bruit)]]
                                                                                 [if abs(meme_2) >= limites [set meme_2 (limites - random-float bruit) * -1]]
                                                              ifelse prégnance_PQ = 0 [pregnance]
                                                                     [set pre prégnance_PQ + log(random-float bruit) 2]

                                                              set meme meme_2
                                                              if meme > limites [set meme limites]
                                                              if pre > 29 [set pre 29]
                                                              if pre < -29 [set pre -29]
                                                              if pre < 0 [set pre 0]
                                                              setxy meme pre]]]
  ]

 If Récit = true [set seq 0 while [seq <= 9] [ if iteration >= item seq de_CAQ and iteration <= item seq fe_CAQ
    [set debut_even_CAQ item seq de_CAQ set fin_even_CAQ item seq fe_CAQ set limite_gauche_CAQ item seq lg_CAQ set limite_droite_CAQ item seq ld_CAQ
       set prégnance_CAQ item seq p_CAQ set prégnance_haute_CAQ item seq ph_CAQ set prégnance_basse_CAQ item seq pb_CAQ set déplacer_CAQ item seq d_CAQ] set seq seq + 1]]

  if CAQ = true or Tous = true  [if (iteration >= debut_even_CAQ and iteration <= fin_even_CAQ) or (debut_even = 0 and fin_even = 0) [ask turtles with [color = magenta] [if meme > limite_gauche_CAQ  and  meme < limite_droite_CAQ and pre < prégnance_haute_CAQ and pre > prégnance_basse_CAQ [set meme_2 meme
                                                              set meme_2 meme_2 + déplacer_CAQ
                                                              ifelse meme_2 >= 0 [if abs(meme_2) >= limites [set meme_2 (limites - random-float bruit)]]
                                                                                 [if abs(meme_2) >= limites [set meme_2 (limites - random-float bruit) * -1]]
                                                              ifelse prégnance_CAQ = 0 [pregnance]
                                                                     [set pre prégnance_CAQ + log(random-float bruit) 2]

                                                              set meme meme_2
                                                              if meme > limites [set meme limites]
                                                              if pre > 29 [set pre 29]
                                                              if pre < -29 [set pre -29]
                                                              if pre < 0 [set pre 0]
                                                              setxy meme pre]]]
  ]

 If Récit = true [set seq 0 while [seq <= 9] [ if iteration >= item seq de_QS and iteration <= item seq fe_QS
    [set debut_even_QS item seq de_QS set fin_even_QS item seq fe_QS set limite_gauche_QS item seq lg_QS set limite_droite_QS item seq ld_QS
       set prégnance_QS item seq p_QS set prégnance_haute_QS item seq ph_QS set prégnance_basse_QS item seq pb_QS set déplacer_QS item seq d_QS] set seq seq + 1]]

  if QS = true or Tous = true [if (iteration >= debut_even_QS and iteration <= fin_even_QS) or (debut_even = 0 and fin_even = 0) [ask turtles with [color = orange] [if meme > limite_gauche_QS  and  meme < limite_droite_QS and pre < prégnance_haute_QS and pre > prégnance_basse_QS [set meme_2 meme
                                                              set meme_2 meme_2 + déplacer_QS
                                                              ifelse meme_2 >= 0 [if abs(meme_2) >= limites [set meme_2 (limites - random-float bruit)]]
                                                                                 [if abs(meme_2) >= limites [set meme_2 (limites - random-float bruit) * -1]]
                                                              ifelse prégnance_QS = 0 [pregnance]
                                                                     [set pre prégnance_QS + log(random-float bruit) 2]

                                                              set meme meme_2
                                                              if meme > limites [set meme limites]
                                                              if pre > 29 [set pre 29]
                                                              if pre < -29 [set pre -29]
                                                              if pre < 0 [set pre 0]
                                                              setxy meme pre]]]

  ]

 If Récit = true [set seq 0 while [seq <= 9] [ if iteration >= item seq de_PLQ and iteration <= item seq fe_PLQ
    [set debut_even_PLQ item seq de_PLQ set fin_even_PLQ item seq fe_PLQ set limite_gauche_PLQ item seq lg_PLQ set limite_droite_PLQ item seq ld_PLQ
       set prégnance_PLQ item seq p_PLQ set prégnance_haute_PLQ item seq ph_PLQ set prégnance_basse_PLQ item seq pb_PLQ set déplacer_PLQ item seq d_PLQ] set seq seq + 1]]

if PLQ = true or Tous = true  [if (iteration >= debut_even_PLQ and iteration <= fin_even_PLQ) or (debut_even = 0 and fin_even = 0) [ask turtles with [color = red] [if meme > limite_gauche_PLQ  and  meme < limite_droite_PLQ and pre < prégnance_haute_PLQ and pre > prégnance_basse_PLQ [set meme_2 meme
                                                              set meme_2 meme_2 + déplacer_PLQ
                                                              ifelse meme_2 >= 0 [if abs(meme_2) >= limites [set meme_2 (limites - random-float bruit)]]
                                                                                 [if abs(meme_2) >= limites [set meme_2 (limites - random-float bruit) * -1]]
                                                              ifelse prégnance_PLQ = 0 [pregnance]
                                                                     [set pre prégnance_PLQ + log(random-float bruit) 2]

                                                              set meme meme_2
                                                              if meme > limites [set meme limites]
                                                              if pre > 29 [set pre 29]
                                                              if pre < -29 [set pre -29]
                                                              if pre < 0 [set pre 0]
                                                              setxy meme pre]]]
 ]
set exclusion 0
end 

to in_file ;fichier d'entrée
  set in true
  if forme = false and f01 = 0 [user-message "Fichier manquant du format des données" stop]
 carefully [set file-in user-file
  if (file-in != false)
  [
    set list_data []
   file-open file-in
   while [not file-at-end?]
         [set list_data sentence list_data (list (list file-read file-read file-read file-read)) ]
   user-message "Fichier chargé!"

  ]
data] [set in false user-message "Erreur de lecture du fichier de distribution"]
calcul
end 

to data ;lecture de la distribution des agents
  clear-turtles
  set in_data 1
  create-turtles échantillon
   ifelse (is-list? list_data) [foreach list_data [ [?1] -> ask turtle first ?1 [if in_data <= (limite_iters * échantillon) + 1  [set meme item 1 ?1
                                                                                                               set pre item 2 ?1
                                                                                                               set infl_list last ?1
                                                                                                               foreach infl_list [ [??1] -> create-link-from turtle ??1 ]
                                                                                                               ask links [hide-link]
                                                                                                               setxy meme pre

if (who >= f09 or who <= f10) or (who >= f07 and who <= f08) or (who >= f05 and who <= f06) or (who >= f03 and who <= f04) or (who >= f01 and who <= f02) [set color red] ;; répartition des agents par parti en fonction du fichier source
if (who >= f19 and who <= f20) or (who >= f17 and who <= f18) or (who >= f15 and who <= f16) or (who >= f13 and who <= f14) or (who >= f11 and who <= f12) [set color blue]
if (who >= f29 and who <= f30) or (who >= f27 and who <= f28) or (who >= f25 and who <= f26) or (who >= f23 and who <= f24) or (who >= f21 and who <= f22) [set color magenta]
if (who >= f39 and who <= f40) or (who >= f37 and who <= f38) or (who >= f35 and who <= f36) or (who >= f33 and who <= f34) or (who >= f31 and who <= f32) [set color orange]
                                                                                                               set in_data in_data + 1]] ]]


                                [set in false user-message "Erreur de lecture" ]
if pole_droit [set pole true]
if go_trans = true [transférer]
end 

to out_pole
  if in = false [user-message "Fichier d'entrée manquant" stop]
  file-close
  set file-out user-new-file
    if is-string? file-out
  [
    carefully [if file-exists? file-out
      [file-delete file-out]] [set out false user-message "Erreur d'ouverture de fichier" stop]
    file-open file-out]
  set out true
  if valeurs = false [
  set percentage count turtles with [meme > 0]
  set percentage precision (percentage / échantillon * 100) 0
  set p_class1 count turtles with [color = blue and meme > 0]
  set p_class1 precision (p_class1 / count turtles with [color = blue] * 100) 0
  set p_class4 count turtles with [color = red and meme > 0]
  set p_class4 precision (p_class4 / count turtles with [color = red] * 100) 0
  set p_class2 count turtles with [color = magenta and meme > 0]
  set p_class2 precision (p_class2 / count turtles with [color = magenta] * 100) 0
  set p_class3 count turtles with [color = orange and meme > 0]
  set p_class3 precision (p_class3 / count turtles with [color = orange] * 100) 0
  if fvote = false [
  if estimation = true or Droit% = true [file-print " Vote PQ ; Vote CAQ ; Vote QS ; Vote PLQ ; Ref TOTAL ; Ref PQ ; Ref CAQ ; Ref QS ; Ref PLQ ; Iterations ; Essais"]
  ifelse estimation = true [file-write vote_PQ file-write " ; " file-write vote_CAQ file-write " ; " file-write vote_QS file-write " ; " file-write vote_PLQ file-write " ; "] [if Droit% = true [file-write "; ; ; ; "]]
  ifelse Droit% = true [file-write percentage file-write "; "  file-write p_class1 file-write "; " file-write p_class2 file-write "; " file-write p_class3 file-write "; " file-write p_class4 file-write "; " file-write 0 file-write "; "  file-print essais] [if pole_droit = true [file-write " ; ; ; ; " file-write 0 file-write "; " file-print essais file-close]]
  ]]
end 

to saisie ;; saisie de la configuration par parti pour la gestion d'événements
  if Formations = "PQ" or Formations = "Tous" [set limite_gauche_PQ limite_gauche set limite_droite_PQ limite_droite set prégnance_basse_PQ prégnance_basse set prégnance_haute_PQ prégnance_haute set prégnance_PQ prégnance
   set déplacer_PQ déplacer set debut_even_PQ debut_even set fin_even_PQ fin_even set PQ true]
  if Formations = "CAQ" or Formations = "Tous"  [set limite_gauche_CAQ limite_gauche set limite_droite_CAQ limite_droite set prégnance_basse_CAQ prégnance_basse set prégnance_haute_CAQ prégnance_haute set prégnance_CAQ prégnance
    set déplacer_CAQ déplacer set debut_even_CAQ debut_even set fin_even_CAQ fin_even set CAQ true]
  if Formations = "QS" or Formations = "Tous" [set limite_gauche_QS limite_gauche set limite_droite_QS limite_droite set prégnance_basse_QS prégnance_basse set prégnance_haute_QS prégnance_haute set prégnance_QS prégnance
    set déplacer_QS déplacer set debut_even_QS debut_even set fin_even_QS fin_even set QS true]
   if Formations = "PLQ" or Formations = "Tous" [set limite_gauche_PLQ limite_gauche set limite_droite_PLQ limite_droite set prégnance_basse_PLQ prégnance_basse set prégnance_haute_PLQ prégnance_haute set prégnance_PLQ prégnance
    set déplacer_PLQ déplacer set debut_even_PLQ debut_even set fin_even_PLQ fin_even set PLQ true]
  if Formations = "Tous" [set Tous true]
end 

to attribuer ;; configuration par parti de l'atténuation
  if Partis = "PQ" [set PQ_1 true set Adhérents_PQ Adhérents set côté_PQ côté]
  if Partis = "CAQ"[set CAQ_1 true set Adhérents_CAQ Adhérents set côté_CAQ côté]
  if Partis = "QS" [set QS_1 true set Adhérents_QS Adhérents set côté_QS côté]
  if Partis = "PLQ"[set PLQ_1 true set Adhérents_PLQ Adhérents set côté_PLQ côté]
end 

to parametres ;; impression des paramètres utilisés et de la moyenne des pourcentages obtenus pour tous les cibles
  file-open file-out
  if cible > essais [set cible essais]
        file-print "" file-print "PARAMETRES:"
        file-write "Entree: ; " file-print file-in
        file-write "Sortie: ; " file-print file-out
        if récit = true [file-write "Recit: ; " file-print file-recit]
        file-write "Echantillon: ; " file-print échantillon
        file-write "Influenceurs: ; " file-print influenceurs
        file-write "Limites: ; " file-print limites
        file-write "Liens uniques: ; " file-print (count links)
        file-write "Essais: ; " file-print essais
        file-write "Nb_iters: ; " file-print nb_iters
        if niveau = true [file-write "Debut_iters: ; " file-print debut_iters
        file-write "cible: ; " file-print cible
        set ratio cible / essais * 100
        file-write "Prob: ; " file-write precision ratio 3 file-print " %"
        file-write "Niveau_bas: ; " file-print niveau_bas
        file-write "Niveau_haut: ; " file-print niveau_haut]
        file-write "Interactions: ; " file-print total
        file-write "Inversions: ; " file-print change
        file-write "Changements: ; " file-write precision percent 3 file-print " %"
        file-print "Attenuation:"
        if PQ_1 = true [file-write "Adherents_PQ: ; " file-print Adhérents_PQ
        file-write "Cote_PQ: ; " file-print côté_PQ]
        if CAQ_1 = true [file-write "Adherents_CAQ: ; " file-print Adhérents_CAQ
        file-write "Cote_CAQ: ; " file-print côté_CAQ]
        if QS_1 = true [file-write "Adherents_QS: ; " file-print Adhérents_QS
        file-write "Cote_QS: ; " file-print côté_QS]
        if PLQ_1 = true [file-write "Adherents_PLQ: ; " file-print Adhérents_PLQ
        file-write "Cote_PLQ: ; " file-print côté_PLQ]
        ifelse récit = false [if repet_even = true [file-write "debut_even: ; " file-print debut_even
        file-write "fin_even: ; " file-print fin_even]
        if PQ = true [file-write "Limite_gauche_PQ: ; " file-print limite_gauche_PQ
        file-write "Limite_droite_PQ: ; " file-print limite_droite_PQ
        file-write "Pregnance_basse_PQ: ; " file-print prégnance_basse_PQ
        file-write "Pregnance_haute_PQ: ; " file-print prégnance_haute_PQ
         if prégnance_PQ != 0 [file-write "Pregnance_PQ: ; " file-print prégnance_PQ]
        file-write "Deplacer_PQ: ; " file-print déplacer_PQ
        file-write "Debut_even_PQ: ; " file-print debut_even_PQ
        file-write "Fin_even_PQ: ; " file-print fin_even_PQ]
        if CAQ = true [file-write "Limite_gauche_CAQ: ; " file-print limite_gauche_CAQ
        file-write "Limite_droite_CAQ: ; " file-print limite_droite_CAQ
        file-write "Pregnance_basse_CAQ: ; " file-print prégnance_basse_CAQ
        file-write "Pregnance_haute_CAQ: ; " file-print prégnance_haute_CAQ
         if prégnance_CAQ != 0 [file-write "Pregnance_CAQ: ; " file-print prégnance_CAQ]
        file-write "Deplacer_CAQ: ; " file-print déplacer_CAQ
        file-write "Debut_even_CAQ: ; " file-print debut_even_CAQ
        file-write "Fin_even_CAQ: ; " file-print fin_even_CAQ]
        if QS = true [file-write "Limite_gauche_QS: ; " file-print limite_gauche_QS
        file-write "Limite_droite_QS: ; " file-print limite_droite_QS
        file-write "Pregnance_basse_QS: ; " file-print prégnance_basse_QS
        file-write "Pregnance_haute_QS: ; " file-print prégnance_haute_QS
         if prégnance_QS != 0 [file-write "Pregnance_QS: ; " file-print prégnance_QS]
        file-write "Deplacer_QS: ; " file-print déplacer_QS
        file-write "Debut_even_QS: ; " file-print debut_even_QS
        file-write "Fin_even_QS: ; " file-print fin_even_QS]
        if PLQ = true [file-write "Limite_gauche_PLQ: ; " file-print limite_gauche_PLQ
        file-write "Limite_droite_PLQ: ; " file-print limite_droite_PLQ
        file-write "Pregnance_basse_PLQ: ; " file-print prégnance_basse_PLQ
         file-write "Pregnance_haute_PLQ: ; " file-print prégnance_haute_PLQ
         if prégnance_PLQ != 0 [file-write "Pregnance_PLQ: ; " file-print prégnance_PLQ]
        file-write "Deplacer_PLQ: ; " file-print déplacer_PLQ
         file-write "Debut_even_PLQ: ; " file-print debut_even_PLQ
         file-write "Fin_even_PLQ: ; " file-print fin_even_PLQ]]
        [if PQ = true [file-write "Limite_gauche_PQ: ; " file-print lg_PQ
        file-write "Limite_droite_PQ: ; " file-print ld_PQ
        file-write "Pregnance_basse_PQ: ; " file-print pb_PQ
        file-write "Pregnance_haute_PQ: ; " file-print ph_PQ
        file-write "Pregnance_PQ: ; " file-print p_PQ
        file-write "Deplacer_PQ: ; " file-print d_PQ
        file-write "Debut_even_PQ: ; " file-print de_PQ
        file-write "Fin_even_PQ: ; " file-print fe_PQ]
        if CAQ = true [file-write "Limite_gauche_CAQ: ; " file-print lg_CAQ
        file-write "Limite_droite_CAQ: ; " file-print ld_CAQ
        file-write "Pregnance_basse_CAQ: ; " file-print pb_CAQ
        file-write "Pregnance_haute_CAQ: ; " file-print ph_CAQ
        file-write "Pregnance_CAQ: ; " file-print p_CAQ
        file-write "Deplacer_CAQ: ; " file-print d_CAQ
        file-write "Debut_even_CAQ: ; " file-print de_CAQ
        file-write "Fin_even_CAQ: ; " file-print fe_CAQ]
        if QS = true [file-write "Limite_gauche_QS: ; " file-print lg_QS
        file-write "Limite_droite_QS: ; " file-print ld_QS
        file-write "Pregnance_basse_QS: ; " file-print pb_QS
        file-write "Pregnance_haute_QS: ; " file-print ph_QS
        file-write "Pregnance_QS: ; " file-print p_QS
        file-write "Deplacer_QS: ; " file-print d_QS
        file-write "Debut_even_QS: ; " file-print de_QS
        file-write "Fin_even_QS: ; " file-print fe_QS]
         if PLQ = true [file-write "Limite_gauche_PLQ: ; " file-print lg_PLQ
        file-write "Limite_droite_PLQ: ; " file-print ld_PLQ
        file-write "Pregnance_basse_PLQ: ; " file-print pb_PLQ
        file-write "Pregnance_haute_PLQ: ; " file-print ph_PLQ
        file-write "Pregnance_PLQ: ; " file-print p_PLQ
        file-write "Deplacer_PLQ: ; " file-print d_PLQ
         file-write "Debut_even_PLQ: ; " file-print de_PLQ
         file-write "Fin_even_PLQ: ; " file-print fe_PLQ]]
   if go_trans = true [file-print "Transferts electoraux:"]
   if PQ_CAQ_% != 0 [file-write "PQ_CAQ: ; " file-write PQ_CAQ_% file-print " %"]
   if PQ_QS_% != 0 [file-write "PQ_QS: ; " file-write PQ_QS_% file-print " %"]
   if PQ_PLQ_% != 0 [file-write "PQ_PLQ: ; " file-write PQ_PLQ_% file-print " %"]
   if CAQ_PQ_% != 0 [file-write "CAQ_PQ: ; " file-write CAQ_PQ_% file-print " %"]
   if CAQ_QS_% != 0 [file-write "CAQ_QS: ; " file-write CAQ_QS_% file-print " %"]
   if CAQ_PLQ_% != 0 [file-write "CAQ_PLQ: ; " file-write CAQ_PLQ_% file-print " %"]
   if PLQ_PQ_% != 0 [file-write "PLQ_PQ: ; " file-write PLQ_PQ_% file-print " %"]
   if PLQ_CAQ_% != 0 [file-write "PLQ_CAQ: ; " file-write PLQ_CAQ_% file-print " %"]
   if PLQ_QS_% != 0 [file-write "PLQ_QS: ; " file-write PLQ_QS_% file-print " %"]
   ask turtles with [color = blue] [set PQ_2 PQ_2 + 1]
   ask turtles with [color = red] [set PLQ_2 PLQ_2 + 1]
   ask turtles with [color = magenta] [set CAQ_2 CAQ_2 + 1]
   ask turtles with [color = orange] [set QS_2 QS_2 + 1]
   if estimation = true [file-print "Configuration de l'estimation:"]
   if estimation = true [if PQ_on = true [file-write "PQ->Xd: ; " file-write PQ->Xd% file-print " %"]]
   if estimation = true [if PQ_on = true [file-write "PQ->Xg: ; " file-write PQ->Xg% file-print " %"]]
   if estimation = true [if CAQ_on = true [file-write "CAQ->Xd: ; " file-write CAQ->Xd% file-print " %"]]
   if estimation = true [if QS_on = true [file-write "QS->Xd: ; " file-write QS->Xd% file-print " %"]]
   if estimation = true [if PLQ_on = true [file-write "PLQ->Xd: ; " file-write PLQ->Xd% file-print " %"]]
   if estimation = true [if PLQ_on = true [file-write "PLQ->Xg: ; " file-write PLQ->Xg% file-print " %"]]
   if estimation = true [if PQ_on = true [file-write "CAQ<-PQ: ; " file-write CAQ<-PQ% file-print " %"]]
   if estimation = true [if PLQ_on = true [file-write "PQ<-PLQ: ; " file-write PQ<-PLQ% file-print " %"]]
   if estimation = true [if PLQ_on = true [file-write "CAQ<-PLQ: ; " file-write CAQ<-PLQ% file-print " %"]]
   file-print "Distribution initiale:"
   file-write "Vote PQ: ; " file-write round (PQ_2 / échantillon * 100) file-print " %"
   file-write "Vote CAQ: ; " file-write round (CAQ_2 / échantillon * 100) file-print " %"
   file-write "Vote QS: ; " file-write round (QS_2 / échantillon * 100) file-print " %"
   file-write "Vote PLQ: ; " file-write round (PLQ_2 / échantillon * 100) file-print " %"
  if Droit% = false and Niveau = true and cible > 0 [set tot_percent tot_percent / cible
  set tot_class1 tot_class1 / cible
  set tot_class2 tot_class2 / cible
  set tot_class3 tot_class3 / cible
  set tot_class4 tot_class4 / cible
  file-print "MOYENNES:"
  file-write precision  tot_percent 1 file-write ";" file-write precision tot_class1 1 file-write ";" file-write precision tot_class2 1 file-write ";" file-write precision tot_class3 1 file-write ";" file-write precision  tot_class4 1]
file-close
end 

to init_atténuation ;;remise à zéo des paramètres de l'entourage
set PQ_1 false
  set CAQ_1 false
  set PLQ_1 false
  set QS_1 false
  set Adhérents_PQ 0
  set Adhérents_CAQ 0
  set Adhérents_QS 0
  set Adhérents_PLQ 0
  set côté_PQ ""
  set côté_QS ""
  set côté_CAQ ""
  set côté_PLQ ""
end 

to init_saisie ;;remise à zéro des paramètres d'événements
  set PQ false
  set CAQ false
  set PLQ false
  set QS false
  set limite_gauche_PQ 0
  set limite_droite_PQ 0
  set limite_gauche_PLQ 0
  set limite_droite_PLQ 0
  set limite_gauche_CAQ 0
  set limite_droite_CAQ 0
  set limite_gauche_QS 0
  set limite_droite_QS 0
  set prégnance_basse_PQ 0
  set prégnance_haute_PQ 0
  set prégnance_basse_PLQ 0
  set prégnance_haute_PLQ 0
  set prégnance_basse_CAQ 0
  set prégnance_haute_CAQ 0
  set prégnance_basse_QS 0
  set prégnance_haute_QS 0
  set prégnance_PQ 0
  set prégnance_PLQ 0
  set prégnance_CAQ 0
  set prégnance_QS 0
  set déplacer_PQ 0
  set déplacer_PLQ 0
  set déplacer_CAQ 0
  set déplacer_QS 0
  set debut_even_PQ 0
  set fin_even_PQ 0
  set debut_even_CAQ 0
  set fin_even_CAQ 0
  set debut_even_QS 0
  set fin_even_QS 0
  set debut_even_PLQ 0
  set fin_even_PLQ 0
end 

to charger_atténuer ;lecture d'un fichier de configuration de l'entourage (atténuation)
carefully [set file-attenuer user-file
  if (file-attenuer != false)
  [
   file-open file-attenuer
  set Adhérents_PQ file-read set Adhérents_CAQ file-read set Adhérents_QS file-read set Adhérents_PLQ file-read set côté_PQ file-read set côté_CAQ file-read set côté_QS file-read set côté_PLQ file-read
  set PQ_1 file-read set CAQ_1 file-read set QS_1 file-read set PLQ_1 file-read
  user-message "Fichier chargé!" file-close]
] [user-message "Erreur de lecture du fichier d'atténuation"]
end 

to charger_saisir ;;lecture d'un fichier configurant un événement
carefully [set file-saisir user-file
  if (file-saisir != false)
  [
   file-open file-saisir
  set limite_gauche_PQ file-read set limite_gauche_CAQ file-read set limite_gauche_QS file-read set limite_gauche_PLQ file-read
  set limite_droite_PQ file-read set limite_droite_CAQ file-read set limite_droite_QS file-read set limite_droite_QS file-read
  set prégnance_basse_PQ file-read set prégnance_basse_CAQ file-read set prégnance_basse_QS file-read set prégnance_basse_PLQ file-read
  set prégnance_haute_PQ file-read set prégnance_haute_CAQ file-read set prégnance_haute_QS file-read set prégnance_haute_PLQ file-read
  set prégnance_PQ file-read set prégnance_CAQ file-read set prégnance_QS file-read set prégnance_PLQ file-read
  set déplacer_PQ file-read set déplacer_CAQ file-read set déplacer_QS file-read set déplacer_PLQ file-read
  set debut_even_PQ file-read set debut_even_CAQ file-read set debut_even_QS file-read set debut_even_PLQ file-read
  set fin_even_PQ file-read set fin_even_CAQ file-read set fin_even_QS file-read set fin_even_PLQ file-read
  set PQ file-read set CAQ file-read set QS file-read set PLQ file-read
  set repet_even file-read
  set debut_even 99
  set fin_even 99
  user-message "Fichier chargé!" file-close]
] [user-message "Erreur de lecture du fichier d'événement"]
end 

to sauver_atténuer ;;sauvegarde dans un fichier des paramètres de l'entourage
  set file-attenuer user-new-file
    if is-string? file-attenuer
  [
    carefully [if file-exists? file-attenuer
      [file-delete file-attenuer]] [set out false user-message "Erreur d'ouverture de fichier" stop]
    file-open file-attenuer]
  file-write Adhérents_PQ file-write Adhérents_CAQ file-write Adhérents_QS file-write Adhérents_PLQ file-write côté_PQ file-write côté_CAQ file-write côté_QS file-write côté_PLQ
  file-write PQ_1 file-write CAQ_1 file-write QS_1 file-write PLQ_1
  file-close
end 

to sauver_saisir ;;sauvegarde dans un fichier des paramètres d'un événement
  set file-saisir user-new-file
    if is-string? file-saisir
  [
    carefully [if file-exists? file-saisir
      [file-delete file-saisir]] [set out false user-message "Erreur d'ouverture de fichier" stop]
    file-open file-saisir]
  file-write limite_gauche_PQ file-write limite_gauche_CAQ file-write limite_gauche_QS file-write limite_gauche_PLQ
  file-write limite_droite_PQ file-write limite_droite_CAQ file-write limite_droite_QS file-write limite_droite_PLQ
  file-write prégnance_basse_PQ file-write prégnance_basse_CAQ file-write prégnance_basse_QS file-write prégnance_basse_PLQ
  file-write prégnance_haute_PQ file-write prégnance_haute_CAQ file-write prégnance_haute_QS file-write prégnance_haute_PLQ
  file-write prégnance_PQ file-write prégnance_CAQ file-write prégnance_QS file-write prégnance_PLQ
  file-write déplacer_PQ file-write déplacer_CAQ file-write déplacer_QS file-write déplacer_PLQ
  file-write debut_even_PQ file-write debut_even_CAQ file-write debut_even_QS file-write debut_even_PLQ
  file-write fin_even_PQ file-write fin_even_CAQ file-write fin_even_QS file-write fin_even_PLQ
  file-write PQ file-write CAQ file-write QS file-write PLQ
  file-write repet_even
  file-close
end 

to sauver_config ;;sauvegarde dans un fichier des paramètres de la configuration générale
set file-config user-new-file
    if is-string? file-config
  [
    carefully [if file-exists? file-config
      [file-delete file-config]] [set out false user-message "Erreur d'ouverture de fichier" stop]
    file-open file-config]
  file-write valeurs file-write pole_droit file-write Droit% file-write Niveau
  file-write debut_iters file-write Niveau_bas file-write Niveau_haut file-write échantillon file-write influenceurs file-write limites
  file-write nb_iters file-write nb_essais file-write cible
  file-write PQ->Xd% file-write PQ->Xg% file-write CAQ->Xd% file-write QS->Xd% file-write PLQ->Xg% file-write PLQ->Xd% file-write PQ<-PLQ% file-write CAQ<-PQ% file-write CAQ<-PLQ%
file-close
end 

to charger_config ;;lecture d'un fichier contenant les paramètres de la configuration générale
carefully [set file-config user-file
  if (file-config != false)
  [
   file-open file-config
  set valeurs file-read set pole_droit file-read set Droit% file-read set Niveau file-read
  set debut_iters file-read set Niveau_bas file-read set Niveau_haut file-read set échantillon file-read set influenceurs file-read set limites file-read
  set nb_iters file-read set nb_essais file-read set cible file-read
  set PQ->Xd% file-read set PQ->Xg% file-read set CAQ->Xd% file-read set QS->Xd% file-read set PLQ->Xg% file-read set PLQ->Xd% file-read  set PQ<-PLQ% file-read  set CAQ<-PQ% file-read set CAQ<-PLQ% file-read
  user-message "Fichier chargé!" file-close]
] [user-message "Erreur de lecture du fichier de configuration"]
end 

to format ;;lecture d'un fichier contenant la configuration de distribution des agents en fonction du fichier source
carefully [set file-format user-file
  if (file-format != false)
  [set forme true
   file-open file-format
   set f01 file-read set f02 file-read set f03 file-read set f04 file-read set f05 file-read set f06 file-read set f07 file-read set f08 file-read set f09 file-read set f10 file-read
   set f11 file-read set f12 file-read set f13 file-read set f14 file-read set f15 file-read set f16 file-read set f17 file-read set f18 file-read set f19 file-read set f20 file-read
   set f21 file-read set f22 file-read set f23 file-read set f24 file-read set f25 file-read set f26 file-read set f27 file-read set f28 file-read set f29 file-read set f30 file-read
   set f31 file-read set f32 file-read set f33 file-read set f34 file-read set f35 file-read set f36 file-read set f37 file-read set f38 file-read set f39 file-read set f40 file-read
   user-message "Fichier chargé!" file-close]
] [user-message "Erreur de lecture du fichier de format"]
end 

to inscrire ;;inscription dans un récit d'événements se produisant séquentiellement
  ifelse zéro = true
 [if formations = "PQ" [set d_PQ replace-item séquence d_PQ déplacer_PQ
 set lg_PQ replace-item séquence lg_PQ limite_gauche_PQ
 set ld_PQ replace-item séquence ld_PQ limite_droite_PQ
 set p_PQ replace-item séquence p_PQ prégnance_PQ
 set pb_PQ replace-item séquence pb_PQ prégnance_basse_PQ
 set ph_PQ replace-item séquence ph_PQ prégnance_haute_PQ
 set de_PQ replace-item séquence de_PQ debut_even_PQ
 set fe_PQ replace-item séquence fe_PQ fin_even_PQ]

 if formations = "CAQ" [set d_CAQ replace-item séquence d_CAQ déplacer_CAQ
 set lg_CAQ replace-item séquence lg_CAQ limite_gauche_CAQ
 set ld_CAQ replace-item séquence ld_CAQ limite_droite_CAQ
 set p_CAQ replace-item séquence p_CAQ prégnance_CAQ
 set pb_CAQ replace-item séquence pb_CAQ prégnance_basse_CAQ
 set ph_CAQ replace-item séquence ph_CAQ prégnance_haute_CAQ
 set de_CAQ replace-item séquence de_CAQ debut_even_CAQ
 set fe_CAQ replace-item séquence fe_CAQ fin_even_CAQ]

 if formations = "QS" [set d_QS replace-item séquence d_QS déplacer_QS
 set lg_QS replace-item séquence lg_QS limite_gauche_QS
 set ld_QS replace-item séquence ld_QS limite_droite_QS
 set p_QS replace-item séquence p_QS prégnance_QS
 set pb_QS replace-item séquence pb_QS prégnance_basse_QS
 set ph_QS replace-item séquence ph_QS prégnance_haute_QS
 set de_QS replace-item séquence de_QS debut_even_QS
 set fe_QS replace-item séquence fe_QS fin_even_QS]

 if formations = "PLQ" [set d_PLQ replace-item séquence d_PLQ déplacer_PLQ
 set lg_PLQ replace-item séquence lg_PLQ limite_gauche_PLQ
 set ld_PLQ replace-item séquence ld_PLQ limite_droite_PLQ
 set p_PLQ replace-item séquence p_PLQ prégnance_PLQ
 set pb_PLQ replace-item séquence pb_PLQ prégnance_basse_PLQ
 set ph_PLQ replace-item séquence ph_PLQ prégnance_haute_PLQ
 set de_PLQ replace-item séquence de_PLQ debut_even_PLQ
 set fe_PLQ replace-item séquence fe_PLQ fin_even_PLQ]
 ]
  [user-message "Il faut initialiser avant"]
end 

to remise_0 ;;initialisation et remise à zéro des listes d'événements pour un récit
  set zéro true
 set d_PQ [0 0 0 0 0 0 0 0 0 0]
 set d_CAQ [0 0 0 0 0 0 0 0 0 0]
 set d_QS [0 0 0 0 0 0 0 0 0 0]
 set d_PLQ [0 0 0 0 0 0 0 0 0 0]
 set lg_PQ [0 0 0 0 0 0 0 0 0 0]
 set lg_CAQ [0 0 0 0 0 0 0 0 0 0]
 set lg_QS [0 0 0 0 0 0 0 0 0 0]
 set lg_PLQ [0 0 0 0 0 0 0 0 0 0]
 set ld_PQ [0 0 0 0 0 0 0 0 0 0]
 set ld_CAQ [0 0 0 0 0 0 0 0 0 0]
 set ld_QS [0 0 0 0 0 0 0 0 0 0]
 set ld_PLQ [0 0 0 0 0 0 0 0 0 0]
 set p_PQ [0 0 0 0 0 0 0 0 0 0]
 set p_CAQ [0 0 0 0 0 0 0 0 0 0]
 set p_QS [0 0 0 0 0 0 0 0 0 0]
 set p_PLQ [0 0 0 0 0 0 0 0 0 0]
 set pb_PQ [0 0 0 0 0 0 0 0 0 0]
 set pb_CAQ [0 0 0 0 0 0 0 0 0 0]
 set pb_QS [0 0 0 0 0 0 0 0 0 0]
 set pb_PLQ [0 0 0 0 0 0 0 0 0 0]
 set ph_PQ [0 0 0 0 0 0 0 0 0 0]
 set ph_CAQ [0 0 0 0 0 0 0 0 0 0]
 set ph_QS [0 0 0 0 0 0 0 0 0 0]
 set ph_PLQ [0 0 0 0 0 0 0 0 0 0]
 set de_PQ [0 0 0 0 0 0 0 0 0 0]
 set de_CAQ [0 0 0 0 0 0 0 0 0 0]
 set de_QS [0 0 0 0 0 0 0 0 0 0]
 set de_PLQ [0 0 0 0 0 0 0 0 0 0]
 set fe_PQ [0 0 0 0 0 0 0 0 0 0]
 set fe_CAQ [0 0 0 0 0 0 0 0 0 0]
 set fe_QS [0 0 0 0 0 0 0 0 0 0]
 set fe_PLQ [0 0 0 0 0 0 0 0 0 0]
end 

to sauver_récit ;sauvegarde dans un fichier de la séquence d'événements pour un récit
   set file-recit user-new-file
    if is-string? file-recit
  [
    carefully [if file-exists? file-recit
      [file-delete file-recit]] [set out false user-message "Erreur d'ouverture de fichier" stop]
    file-open file-recit]
  file-write lg_PQ file-write lg_CAQ file-write lg_QS file-write lg_PLQ
  file-write ld_PQ file-write ld_CAQ file-write ld_QS file-write ld_PLQ
  file-write pb_PQ file-write pb_CAQ file-write pb_QS file-write pb_PLQ
  file-write ph_PQ file-write ph_CAQ file-write ph_QS file-write ph_PLQ
  file-write p_PQ file-write p_CAQ file-write p_QS file-write p_PLQ
  file-write d_PQ file-write d_CAQ file-write d_QS file-write d_PLQ
  file-write de_PQ file-write de_CAQ file-write de_QS file-write de_PLQ
  file-write fe_PQ file-write fe_CAQ file-write fe_QS file-write fe_PLQ
  file-write PQ file-write CAQ file-write QS file-write PLQ
  file-write nb_iters file-write nb_essais file-write cible
  file-write debut_iters file-write niveau_bas file-write niveau_haut
  file-write valeurs file-write pole_droit file-write droit% file-write niveau file-write estimation file-write limite_iters
  file-write PQ_on file-write CAQ_on file-write QS_on file-write PLQ_on
  file-write repet_even file-write récit
  file-close
end 

to charger_récit ;lecture d'un fichier contenant la séquence d'événements pour un récit
  carefully [set file-recit user-file
  if (file-recit != false)
  [
   file-open file-recit
  set lg_PQ file-read set lg_CAQ file-read set lg_QS file-read set lg_PLQ file-read
  set ld_PQ file-read set ld_CAQ file-read set ld_QS file-read set ld_PLQ file-read
  set pb_PQ file-read set pb_CAQ file-read set pb_QS file-read set pb_PLQ file-read
  set ph_PQ file-read set ph_CAQ file-read set ph_QS file-read set ph_PLQ file-read
  set p_PQ file-read set p_CAQ file-read set p_QS file-read set p_PLQ file-read
  set d_PQ file-read set d_CAQ file-read set d_QS file-read set d_PLQ file-read
  set de_PQ file-read set de_CAQ file-read set de_QS file-read set de_PLQ file-read
  set fe_PQ file-read set fe_CAQ file-read set fe_QS file-read set fe_PLQ file-read
  set PQ file-read set CAQ file-read set QS file-read set PLQ file-read
  set nb_iters file-read set nb_essais file-read set cible file-read
  set debut_iters file-read set niveau_bas file-read set niveau_haut file-read
  set valeurs file-read set pole_droit file-read set droit% file-read set niveau file-read set estimation file-read set limite_iters file-read
  set PQ_on file-read set CAQ_on file-read set QS_on file-read set PLQ_on file-read
  set repet_even file-read set récit file-read
  user-message "Fichier chargé!" set zéro true file-close]
] [user-message "Erreur de lecture du fichier de récit"]
end 

to sauver_vote ;sauvegarde dans un fichier des estimations des intentions de vote
   set fvote true
   set file-vote user-new-file
    if is-string? file-vote
  [
    carefully [if file-exists? file-vote
      [file-delete file-vote]] [set out false user-message "Erreur d'ouverture de fichier" stop]
  file-open file-vote set inscription true file-print " Vote PQ ; Vote CAQ ; Vote QS ; Vote PLQ ; Iterations ; Essais "]
set out true
end 

to inscrire_vote ;procédure d'inscription des estimations du vote lors de chaque itération
file-open file-vote
file-write vote_PQ file-write "; " file-write vote_CAQ file-write "; " file-write vote_QS file-write "; " file-write vote_PLQ file-write "; " file-write iteration file-write "; " file-print essais + 1
file-close
end 

to établir ;; établir la liste des transferts électoraux d'un parti vers un autre en utilisant le bouton "Établir"
  set go_trans true
  if De = "PQ" and Vers = "CAQ" [set PQ_de true set CAQ_vers true set PQ_CAQ_% Pourcent]
  if De = "PQ" and Vers = "QS" [set PQ_de true set QS_vers true set PQ_QS_% Pourcent]
  if De = "PQ" and Vers = "PLQ" [set PQ_de true set PLQ_vers true set PQ_PLQ_% Pourcent]
  if De = "CAQ" and Vers = "PQ" [set CAQ_de true set PQ_vers true set CAQ_PQ_% Pourcent]
  if De = "CAQ" and Vers = "QS" [set CAQ_de true set QS_vers true set CAQ_QS_% Pourcent]
  if De = "CAQ" and Vers = "PLQ" [set CAQ_de true set PLQ_vers true set CAQ_PLQ_% Pourcent]
  if De = "QS" and Vers = "PQ" [set QS_de true set PQ_vers true set QS_PQ_% Pourcent]
  if De = "QS" and Vers = "CAQ" [set QS_de true set CAQ_vers true set QS_CAQ_% Pourcent]
  if De = "QS" and Vers = "PLQ" [set QS_de true set PLQ_vers true set QS_PLQ_% Pourcent]
  if De = "PLQ" and Vers = "PQ" [set PLQ_de true set PQ_vers true set PLQ_PQ_% Pourcent]
  if De = "PLQ" and Vers = "CAQ" [set PLQ_de true set CAQ_vers true set PLQ_CAQ_% Pourcent]
  if De = "PLQ" and Vers = "QS" [set PLQ_de true set QS_vers true set PLQ_QS_% Pourcent]
end 

to transférer ;; activation du transfert en appuyant sur le bouton "Transférer"
  if PQ_de = true and CAQ_vers = true [set couleur_de blue set couleur_vers magenta set Pourcent PQ_CAQ_% effectuer calcul]
  if PQ_de = true and QS_vers = true [set couleur_de blue set couleur_vers orange set Pourcent PQ_QS_% effectuer calcul]
  if PQ_de = true and PLQ_vers = true [set couleur_de blue set couleur_vers red set Pourcent PQ_PLQ_% effectuer calcul]
  if CAQ_de = true and PQ_vers = true [set couleur_de magenta set couleur_vers blue set Pourcent CAQ_PQ_% effectuer calcul]
  if CAQ_de = true and QS_vers = true [set couleur_de magenta set couleur_vers orange set Pourcent CAQ_QS_% effectuer calcul]
  if CAQ_de = true and PLQ_vers = true [set couleur_de magenta set couleur_vers red set Pourcent CAQ_PLQ_% effectuer calcul]
  if QS_de = true and PQ_vers = true [set couleur_de orange set couleur_vers blue set Pourcent QS_PQ_% effectuer calcul]
  if QS_de = true and CAQ_vers = true [set couleur_de orange set couleur_vers magenta set Pourcent QS_CAQ_% effectuer calcul]
  if QS_de = true and PLQ_vers = true [set couleur_de orange set couleur_vers red set Pourcent QS_PLQ_% effectuer calcul]
  if PLQ_de = true and PQ_vers = true [set couleur_de red set couleur_vers blue set Pourcent PLQ_PQ_% effectuer calcul]
  if PLQ_de = true and CAQ_vers = true [set couleur_de red set couleur_vers magenta set Pourcent PLQ_CAQ_% effectuer calcul]
  if PLQ_de = true and QS_vers = true [set couleur_de red set couleur_vers orange set Pourcent PLQ_QS_% effectuer calcul]
end 

to effectuer ;;effectuer les transferts électoraux
  set transfert round(count turtles with [color = couleur_de] * Pourcent / 100)
  set ji 1
  while [ji < transfert]
  [set trans_cible random 500
    ask turtle trans_cible [if color = couleur_de [set color couleur_vers set ji ji + 1]]]
end 

to calcul ;;calculer les pourcentages de chaque parti
 set vote_PQ round (count turtles with [color = blue] / échantillon * 100)
 set vote_CAQ round (count turtles with [color = magenta] / échantillon * 100)
 set vote_QS round (count turtles with [color = orange] / échantillon * 100)
 set vote_PLQ round (count turtles with [color = red] / échantillon * 100)
end 

There is only one version of this model, created about 4 years ago by Pierre-Alain Cotnoir.

Attached files

File Type Description Last updated
Simulateur_v18_FR_parti_500.png preview Preview for 'Simulateur_v18_FR_parti_500' about 4 years ago, by Pierre-Alain Cotnoir Download

This model does not have any ancestors.

This model does not have any descendants.