Piergaetano Battaglia Francesca Gorrieri Domenico Scorpiniti

Simulation models for economics

Project work on

"AIESEC flows."

 

The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Oracle's Java site.


Here you can find an introduction to the AIESEC flows application.


powered by NetLogo

view/download model file: aiesec_flows.nlogo

WHAT IS IT?

AIESEC is an international non-profit organization that provides services for university students and most of all offer internships in an international playground. The following project focuses on the analysis of the internship system and the migration flows, generated by individuals who want to find an internship abroad. These flows will be based on the combination of both endogenous characteristics of the agents and exogenous variables of the countries in which the AIESEC offices are based. Moreover the study will be extended to the expansion of the offices represented by their increased or reduced capacity of providing available positions, depending on their own efficiency and the results reached

HOW IT WORKS

The first step of our program is representing the AIESEC advertising campaign, during which the organization will try to convince people to apply for the internships offered, the rate of success will be set by the user through a slider on the interface. An additional task of the offices is generating available positions. Indeed, each division will provide a number of available places for individuals coming from each block of origin, these values will have to be set by the user.
The second step lies in the feedback influence. Indeed, a percentage of the workers at the end of the internship will provide its own feedback about the country in which it has done the experience and this will modify the preferences on that particular country of the new applying agents. This interaction of individuals who have already left and new potentially applying will condition the decision of each candidate about his or her destination. On the basis of this new modified endogenous variable, the candidates will go to the local AIESEC office and apply for an internship and the reiteration of this process will represent the migration flows.

HOW TO USE IT

Through the slider “population” the user decides the amount of the overall population.
The world is divided into four blocks.The inputs “europa”, “america” and “asia” set how many individuals will be born in each of the blocks. The monitor “asia” refers the percentage of people born in the asian block. The sum of this 4 objects has to be 1 and the monitor asia is automatically set to asjust the sum to 1, but still this inputs have to be set with numbers between 0 and 1.
Through the slider applying rate, the user decides which percentage of the population will decide to apply for an internship abroad.
Through the slider feedback the user can decide which percentage of the individuals who have been doing the internship will come back and provide their feedback.
The inputs on the left side of the interface are the number of available positions on each block for iinterns coming from each of the blocks.
eaf_places= places for Europeans in Africa
uaf_places= places for Americans in Africa
caf_places= places for Asians in Africa
cusa_places= places for Asians in America
eusa_places= places for Europeans in America
ausa_places= places for African in America
eas_places= places for Europeans in Asia
uas_places= places for Americans in Asia
aas_places= places for Africans in Asia
aeu_places= places for Africans in Europe
ueu_places= places for Americans in Europe
ceu_places= places for Asians in Europe

Moreover on the interface there are three figures. The past destinations graph shows the number of interns working in each of the four blocks.The quality rate graph shows the trend of the evolution of the variable quality with reference to each of the four blocks.
The happiness graph shows the sum of the happiness of the individuals who wanted to do an internship for each of the four blocks.

THINGS TO NOTICE

To make it clearer for the user to see the migration flows, first the AIESEC advertising campaign is underlined. Indeed all the individuals convinced by the organization to apply for an internship set color white. Secondly, the candidates will move to the respective office and look for a job abroad. If they find an available position they move to the block in which they have found a job and they set as color the one of their belonging country, in this way is easier to understand where do the people doing an internship somewhere come from. Finally at the moment of providing the feedback, the selected interns come back to their countries and they set the color red and a label in which is written the value of their updated variable quality.

THINGS TO TRY

Test 1 Abundance and scarcity of feedbacks: with all the other variables fixed, try to modify the feedback rate. (suggested values to notice the difference: 0, 0.5 and 1).
Test 2 Abundance and scarcity of availble internship positions: with all the other variables fixed, try to modify the overall available positions in order for them to be largerly above or below the number of applying interns.
Test 3 Rate of applying: with all the other variables fixed, try to modify the percentage of applying individuals (suggested values to notice the difference: 0, 0.5 and 1).
Test 4 Unequal distribution of the population: with all the other variables fixed, try to modify the distribution of the population around the world ( interesting the cases where one block is unpopulated, where two blocks are unpopulated, where one block is largerly overcrowded)
Test 5 Unequal distribution of the internship positions: with all the other variables fixed, try to see what happens under an unequal distribution of the available job positions ( interesting cases if only one block has availabl positions, if all the blocks but one offer available positions)
Test 6 Racism: what happens if no block is willing to offer an internship to any intern coming from a specific block.

EXTENDING THE MODEL

Interesting features that could be added to this program to make it more realistic are for example the capability of the individuals to communicate between them. Moreover it could be added the capability of offices of making previsions on the future best destinations and also of analyzing the past experiences.

NETLOGO FEATURES

An interesting feature of this model is how the endogenous procedure “feedback” affects the probability, that initially is random, of a candidate to apply in a specific block rather than another.

RELATED MODELS

Minority Model
El Farol Model

CREDITS AND REFERENCES

  1. CHALLET, D., MARSILI, M., OTTINO, G., 2004. Shedding light on El Farol. Physica A: Statistical Mechanics and its Applications , Volume 332, 1 February 2004, Pages 469–482
  2. EDMONDS, B., 1999. Gossip, Sexual Recombination and the El Farol Bar: modelling the emergence of heterogeneity, Journal of Artificial Societies and Social Simulation
  3. CHALLET, D., ZHANG, Y.C., 1997. Emergence of Cooperation and Organization in an Evolutionary Game. Institut de Physique Theorique, Universite de Fribourg, 1700 Fribourg, Switzerland
  4. CASTI, J.L., 1996. Seeing the light at El Farol. Complexity Vol. 1, No. 5, pp. 7-10.

CODE

globals [ EuropeanBlock
          AmericanBlock
          AsianBlock 
          AfricanBlock 
          free_aeu_places free_aas_places free_ausa_places
          free_ueu_places free_uas_places free_uaf_places
          free_caf_places free_ceu_places free_cusa_places
          free_eaf_places free_eusa_places free_eas_places
          x y z a b c l m n p q r 
          asiarate americarate europerate africarate 
          qualityinEurope qualityinAmerica qualityinAfrica qualityinAsia
          africans_back europeans_back americans_back asians_back
          Internspastdestination1 Internspastdestination2 Internspastdestination3 Internspastdestination4 
          happinessafrica happinesseurope happinessamerica happinessasia
          happyrateafrica happyrateeurope happyrateamerica happyrateasia
          americanscontacted asianscontacted africanscontacted europeanscontacted]
  

breed [ europeans european ]
breed [ africans african ]
breed [ asians asian ]
breed [ americans american]
breed [ offices office] 
offices-own [ name ]

turtles-own [ convinced destination stage quality pastdestination ]
 

to setup 
 clear-all
 reset-ticks
 
 create-offices 4
 ask offices [ set  shape "house" ]
 ask office 0 [ set name  "officeurope"  set xcor 15 set ycor 15 ]
 ask office 1 [ set name  "officeafrica" set xcor 15 set ycor -15  ]
 ask office 2 [ set name  "officeamerica" set xcor -15 set ycor 15  ]
 ask office 3 [ set name  "officeasia"  set xcor -15 set ycor -15  ]
 
 generate
 world
 distribute 
 
 ask  turtles [ set color black ]
 ask  offices [set color red] 
 
 set x 30
 set y 30
 set z 30
 set a 30
 set b 30
 set c 30
 set l 30
 set m 30
 set n 30
 set p 30
 set q 30
 set r 30
 set europerate 1
 set africarate 1
 set asiarate 1
 set americarate 1

 
end 

to generate                                                      ; according to the inputs on the interface
  
  let asia 1 - (europa + africa + america)
  
  create-europeans population * europa
 
  create-africans population * africa 
  
  create-americans population * america   
   
  create-asians population * asia 
  
  ask europeans [ set shape "person"]
  ask africans [ set shape "person"]
  ask americans [ set shape "person"]
  ask asians [ set shape "person"]
 
  
end


to world                                                         ; divide the world into 4 blocks
   
   set EuropeanBlock patches with [pxcor >= 0 and pycor > 0 ]  ask EuropeanBlock  [ set pcolor green ]
   set AfricanBlock patches with [ pxcor >= 0 and pycor <= 0 ]  ask AfricanBlock [ set pcolor brown ]
   set AmericanBlock patches with [ pxcor < 0 and pycor > 0 ]  ask AmericanBlock  [ set pcolor cyan] 
   set AsianBlock patches with [ pxcor < 0 and pycor <= 0 ]  ask AsianBlock  [ set pcolor yellow ] 
  
end

to distribute                                                    ; distribute the population in the blocks
  ask europeans [ move-to one-of EuropeanBlock]
  ask africans [ move-to one-of AfricanBlock ]
  ask asians [ move-to one-of AsianBlock ]
  ask americans [ move-to one-of AmericanBlock ]   
   
end 
  
to contact                                                        ; AIESEC offices convince a certain percentage of population, given by a slider on the interface to apply 
 
 
 set europeanscontacted 
 round ( applying * count europeans) 
 
 
 
 set africanscontacted
  round ( applying * count africans)
  
  
  
 set asianscontacted
  round ( applying * count asians)
  
  
  
 set americanscontacted
  round ( applying * count americans)
  
  
 
  ask n-of europeanscontacted europeans [ set label ""
          set convinced 1 set quality 100]  
  
  ask n-of africanscontacted africans [ set label ""
          set convinced 1 set quality 100]
  
  ask n-of asianscontacted asians [ set label ""
          set convinced 1 set quality 100]
  
  ask  n-of americanscontacted americans [ set label ""
          set convinced 1 set quality 100]
  
  ask turtles [ if ( convinced = 1) [ set color white ] ] 
  

end



to internship                                                      ;This is the endogenous part of our program, since according to the feedback rate,
                                                                   ;the population changes its endogenous preferences about the destination
 
  contact
  wait 0.5  
 
 
  let Eu ( x * africarate + y * americarate  + z * asiarate )
  
  
  let Af ( a * europerate + b * americarate + c * asiarate )
  
  
  let Am ( l * europerate + m * asiarate + n * africarate )
  
  
  let As ( p * europerate + q * americarate + r * africarate )
  
                                                                    ; First we move the applying interns to their local office
                                                                    ; Secondly they take their decision according to the evolution of the preferences
 ask europeans [ if (convinced = 1 )
     [ move-to office 0 set color green ] ] 
 ask europeans with [convinced = 1]  
            [ set destination random-float Eu abroad_e] 
 
 ask africans [ if (convinced = 1 )
     [ move-to office 1 set color brown ] ] 
 ask africans with [convinced = 1]  
            [ set destination random-float Af abroad_a]
 
 ask americans [ if (convinced = 1 )
     [ move-to office 2 set color cyan ] ] 
 ask americans with [convinced = 1]  
            [ set destination random-float Am abroad_u] 
 
 ask asians [ if (convinced = 1 )
     [ move-to office 3 set color yellow ] ]
 ask asians with [convinced = 1]  
            [ set destination random-float As abroad_c] 
 
end

 
to abroad_e
  
  if (destination <= x * africarate ) [move-to office 1]
  if (destination >= ( x * africarate + y * Americarate ) ) [move-to office 3]
  if (destination > x * africarate and destination < ( x * africarate + y * Americarate ) ) [move-to office 2]  
   
end
 
to abroad_a
    
   if (destination <= a * Europerate ) [move-to office 0]
   if (destination >= ( a * Europerate + b * Americarate ) ) [move-to office 1]
   if (destination > a * Europerate and destination < ( a * Europerate + b * Americarate ) ) [move-to office 2]
   
end
   
to abroad_u
     
   if (destination <= l * europerate ) [move-to office 0]
   if (destination >= ( l * europerate + m * Asiarate ) ) [move-to office 1]
   if (destination > l * europerate and destination < ( l * europerate + m * asiarate ) ) [move-to office 3]   
   
end
  
to abroad_c
     
   if (destination <= p * Europerate ) [move-to office 0]
   if (destination >= ( p * Europerate + q * Americarate ) ) [move-to office 1]
   if (destination > p * Europerate and destination < ( p * Europerate + q * Americarate ) ) [move-to office 2]
  
end


to select                                                             ; In this section the interns that did not find a free position in their first preference
                                                                      ; try to find another available position in another destination

  
  ;AfricanBlock: free places in Africa after the first selection
  
  let europeans_in_africa count europeans with [convinced = 1 and destination <= x * africarate ]
  if (europeans_in_africa > eaf_places) [
  ask n-of eaf_places europeans with [convinced = 1 and destination <= x * africarate ] [
  move-to one-of AfricanBlock set pastdestination 2 set happinesseurope happinesseurope + 2 
  set stage 1 set free_eaf_places 0 ] ]
  
  if (europeans_in_africa <= eaf_places ) [  ask n-of europeans_in_africa europeans with [convinced = 1 and destination <= x * africarate  ] [
  
  move-to one-of AfricanBlock set pastdestination 2 set stage 1 set happinesseurope happinesseurope + 2  
  
  set free_eaf_places eaf_places - europeans_in_africa ]]
       
  
  let americans_in_africa count americans with [ convinced = 1 and destination >= ( l * europerate + m * asiarate ) ]  
  if (americans_in_africa >  uaf_places) [
  ask n-of uaf_places americans with [convinced = 1 and destination >= ( l * europerate + m * asiarate ) ] [
  move-to one-of AfricanBlock set pastdestination 2 set happinessamerica happinessamerica + 2
  set stage 1 set free_uaf_places 0 ] ]
  if (americans_in_africa <= uaf_places ) [ ask n-of americans_in_africa americans with [convinced = 1 and destination >= ( l * europerate + m * asiarate )][
      move-to one-of AfricanBlock set pastdestination 2 set happinessamerica happinessamerica + 2
      set stage 1
      
  set free_uaf_places uaf_places - americans_in_africa ]]
  
  
  let asians_in_africa count asians with [convinced = 1 and destination >= ( p * Europerate + q * americarate )]
  if (asians_in_africa > caf_places )[
  ask n-of caf_places asians with [ convinced = 1 and
     destination  >= ( p * Europerate + q * americarate ) ] [
  move-to one-of AfricanBlock set pastdestination 2 set happinessasia happinessasia + 2 
  set stage 1 set free_caf_places 0 ] ]
  if (asians_in_africa <= caf_places) [ ask n-of asians_in_africa asians with [ convinced = 1 and destination >= ( p * Europerate + q * americarate ) ] [move-to one-of AfricanBlock set pastdestination 2
  set stage 1  set happinessasia happinessasia + 2 
  set free_caf_places caf_places - asians_in_africa]]
  
  wait 0.5
  
    
  ;EuropeanBlock
  
   
  let africans_in_europe count africans with [convinced = 1 and destination <= a * europerate]  
  if (africans_in_europe > aeu_places)[ ask n-of aeu_places africans with [convinced = 1 and destination <= a * europerate ] 
    [move-to one-of EuropeanBlock set pastdestination 1  set happinessafrica happinessafrica + 2
      set stage 1 set free_aeu_places 0 ] ]  
  if (africans_in_europe <= aeu_places)[ask n-of africans_in_europe africans with [convinced = 1 and 
     destination <= a * europerate ] [
  move-to one-of EuropeanBlock set pastdestination 1
  set stage 1  set happinessafrica happinessafrica + 2
     set free_aeu_places aeu_places - africans_in_europe ]]
     
   
  let americans_in_europe count americans with [ convinced = 1 and destination <= l * europerate ]   
  if (americans_in_europe > ueu_places)[
  ask n-of ueu_places americans with [convinced = 1 and destination <= l * europerate ] [
  move-to one-of EuropeanBlock set pastdestination 1 set happinessamerica happinessamerica + 2
  set stage 1 set free_ueu_places 0 ] ]
  if (americans_in_europe <= ueu_places) [ ask n-of americans_in_europe americans with [convinced = 1 and destination <= l * europerate ] [
  move-to one-of EuropeanBlock set pastdestination 1
  set stage 1 set happinessamerica happinessamerica + 2
  set free_ueu_places ueu_places - americans_in_europe]]
   
    
  let asians_in_europe count asians with [convinced = 1 and destination <= p * europerate ]   
  if (asians_in_europe > ceu_places)[
  ask n-of ceu_places asians with [convinced = 1 and destination <= p * europerate ] [
  move-to one-of EuropeanBlock set pastdestination 1  set happinessasia happinessasia + 2
  set stage 1 set free_ceu_places 0 ] ]
  if (asians_in_europe <= ceu_places) [ ask n-of asians_in_europe asians with [convinced = 1 and destination <= p * europerate ] [
  move-to one-of EuropeanBlock set pastdestination 1
  set stage 1  set happinessasia happinessasia + 2
  set free_ceu_places ceu_places - asians_in_europe]]
  
  wait 0.5
       
 ;AmericanBlock
 
  
  let europeans_in_america count europeans with [convinced = 1 and stage != 1 and destination > x * africarate and destination < ( x * africarate + y * americarate )] 
 
  if (europeans_in_america > eusa_places )[
  ask n-of eusa_places europeans with [ convinced = 1 and stage != 1 and  destination > x * africarate and destination < ( x * africarate + y * americarate )] [
  move-to one-of AmericanBlock set pastdestination 3 set happinesseurope happinesseurope + 2
  set stage 1 set free_eusa_places 0 ] ]
  if (europeans_in_america <= eusa_places )[
  ask n-of europeans_in_america europeans with [convinced = 1 and stage != 1 and destination > x * africarate and destination < ( x * africarate + y * americarate )] [
  move-to one-of AmericanBlock set pastdestination 3
  set stage 1 set happinesseurope happinesseurope + 2
  set free_eusa_places eusa_places - europeans_in_america]]
 
  
  let africans_in_america count africans with [convinced = 1 and destination > a * europerate and destination < ( a * europerate + b * americarate )] 
 
  if (africans_in_america > ausa_places )[
  ask n-of ausa_places africans with [ convinced = 1 and destination > a * europerate and destination < ( a * europerate + b * americarate )] [
  move-to one-of AmericanBlock set pastdestination 3 set happinessafrica happinessafrica + 2
  set stage 1 set free_ausa_places 0 ] ]
  if (africans_in_america <= ausa_places)[
  ask n-of africans_in_america africans with [ convinced = 1 and destination > a * europerate and destination < ( a * europerate + b * americarate ) ] [
  move-to one-of AmericanBlock set pastdestination 3
  set stage 1 set happinessafrica happinessafrica + 2
  set free_ausa_places ausa_places - africans_in_america]]
 
  
  let asians_in_america count asians with [convinced = 1 and destination > p * europerate and destination < ( p * europerate + q * americarate )] 
 
  if (asians_in_america > cusa_places )[
  ask n-of cusa_places asians with [convinced = 1 and  destination > p * europerate and destination < ( p * europerate + q * americarate )] [
  move-to one-of AmericanBlock set pastdestination 3 set happinessasia happinessasia + 2
  set stage 1 set free_cusa_places 0 ] ]
  if (asians_in_america <= cusa_places)[
  ask n-of asians_in_america asians with [ convinced = 1 and  destination > p * europerate and destination < ( p * europerate + q * americarate ) ] [
  move-to one-of AmericanBlock set pastdestination 3 set happinessasia happinessasia + 2
  set stage 1
  set free_cusa_places cusa_places - asians_in_america ]]
  
  wait 0.5
  
;AsianBlock


  let europeans_in_asia count europeans with [ convinced = 1 and destination >= (x * africarate + y * americarate )]

  if (europeans_in_asia > eas_places)[
  ask n-of eas_places europeans with [convinced = 1 and destination >= (x * africarate + y * americarate ) ] [
  move-to one-of AsianBlock set pastdestination 4 set happinesseurope happinesseurope + 2
  set stage 1 set free_eas_places 0 ]]
  if (europeans_in_asia <= eas_places)[ ask n-of europeans_in_asia europeans with [ convinced = 1 and
     destination >= (x * africarate + y * americarate ) ] [
  move-to one-of AsianBlock set pastdestination 4
  set stage 1 set happinesseurope happinesseurope + 2
  set free_eas_places eas_places - europeans_in_asia]]
     
 
  let africans_in_asia count africans with [convinced = 1 and destination >= ( a * europerate + b * americarate )]

  if (africans_in_asia > aas_places)[
  ask n-of aas_places africans with [convinced = 1 and destination >= ( a * europerate + b * americarate ) ] [
  move-to one-of AsianBlock set pastdestination 4 set happinessafrica happinessafrica + 2
  set stage 1 set free_aas_places 0 ]]
  if (africans_in_asia <= aas_places)[ ask n-of africans_in_asia africans with [ convinced = 1 and
     destination  >= ( a * europerate + b * americarate ) ] [
  move-to one-of AsianBlock set pastdestination 4 set happinessafrica happinessafrica + 2
  set stage 1
  set free_aas_places aas_places - africans_in_asia]]

 
  let americans_in_asia count americans with [convinced = 1 and destination > l * europerate and destination < ( l * europerate + m * asiarate )]

  if (americans_in_asia > uas_places)[
  ask n-of uas_places americans with [ convinced = 1 and
     destination > l * europerate and destination < ( l * europerate + m * asiarate  )] [
  move-to one-of AsianBlock set pastdestination 4 set happinessamerica happinessamerica + 2
  set stage 1 set free_uas_places 0 ]]
  if (americans_in_asia <= uas_places)[ ask n-of americans_in_asia americans with [convinced = 1 and
     destination > l * europerate and destination < ( l * europerate + m * asiarate  ) ] [
  move-to one-of AsianBlock set pastdestination 4 set happinessamerica happinessamerica + 2
  set stage 1
  set free_uas_places uas_places - americans_in_asia]]
  
  wait 0.5
  
return-home
look-for-another-place


   
ask europeans with [stage != 1] [die]
ask africans  with [stage != 1] [die]
ask asians    with [stage != 1] [die]
ask americans with [stage != 1] [die]

set Internspastdestination1 count turtles with [ pastdestination = 1]
set Internspastdestination2 count turtles with [ pastdestination = 2]
set Internspastdestination3 count turtles with [ pastdestination = 3]
set Internspastdestination4 count turtles with [ pastdestination = 4]

 

; we select a percentage of population that comes back to its origin and provides a feedback

let europeansfeedback 
 round ( feedback-rate * count europeans)
 
ask n-of europeansfeedback europeans [ move-to one-of EuropeanBlock
   set color red]
ask europeans with [color = green ] [die] 
 

let americansfeedback 
 round ( feedback-rate * count americans)
 
ask n-of americansfeedback americans [ move-to one-of AmericanBlock
   set color red]
ask americans with [color = cyan ] [die]
 
 
let asiansfeedback 
 round ( feedback-rate * count asians)
 
ask n-of asiansfeedback asians [ move-to one-of AsianBlock
   set color red]
ask asians with [color = yellow ] [die]
 

let africansfeedback 
 round ( feedback-rate * count africans)
 
ask n-of africansfeedback africans [ move-to one-of AfricanBlock
   set color red]
ask africans with [color = brown ] [die]

wait 0.5

  
generate 
distribute
ask turtles with [ convinced = 0 and stage != 1 ][set color black]
ask offices [set color red]
feedback
elfarol



ifelse africanscontacted != 0  [set happyrateafrica happinessafrica / africanscontacted] [ set happyrateafrica 1]
ifelse europeanscontacted != 0 [set happyrateeurope happinesseurope / europeanscontacted] [ set happyrateeurope 1]
ifelse asianscontacted != 0    [set happyrateasia happinessasia / asianscontacted] [ set happyrateasia 1]
ifelse americanscontacted != 0 [ set happyrateamerica happinessamerica / americanscontacted] [ set happyrateamerica 1]

end


to return-home
  
ask europeans with [convinced = 1 and stage != 1] [move-to office 0]
ask africans  with [convinced = 1 and stage != 1] [move-to office 1]
ask americans with [convinced = 1 and stage != 1] [move-to office 2]
ask asians    with [convinced = 1 and stage != 1] [move-to office 3]
end

to look-for-another-place
 
;african people and free places

set africans_back count africans with [convinced = 1 and stage != 1]

let available_placesAF   (free_aas_places + free_aeu_places + free_ausa_places)


ask africans with [convinced = 1 and stage != 1] [
; if (free_aeu_places != 0 and free_aas_places != 0 and free_ausa_places != 0)  [ set destination random int ( a * Europerate + b * americarate  + c * asiarate ) retry-abroadA4]

if (free_aeu_places != 0 and free_aas_places != 0 and free_ausa_places = 0 )  [ set destination random-float ( a * europerate + c * asiarate  ) retry-abroadA1]

if (free_aeu_places != 0 and free_aas_places = 0 and free_ausa_places != 0)   [ set destination random-float ( a * europerate + b * americarate ) retry-abroadA2] 

if (free_aeu_places = 0 and free_aas_places != 0 and free_ausa_places != 0)   [ set destination random-float ( b * americarate + c * asiarate ) retry-abroadA3]



if (free_aeu_places = 0 and free_aas_places = 0 and free_ausa_places != 0 )  [move-to one-of AmericanBlock set pastdestination 3 set stage 1 set free_ausa_places free_ausa_places - 1 set happinessafrica happinessafrica + 1]

if (free_aeu_places = 0 and free_aas_places != 0 and free_ausa_places = 0 )  [move-to one-of AsianBlock set pastdestination 4 set stage 1 set free_aas_places free_aas_places - 1 set happinessafrica happinessafrica + 1]

if (free_aeu_places != 0 and free_aas_places = 0 and free_ausa_places = 0 )  [move-to one-of EuropeanBlock set pastdestination 1 set stage 1 set free_aeu_places free_aeu_places - 1 set happinessafrica happinessafrica + 1]]



if (free_aeu_places = 0 and free_aas_places = 0 and free_ausa_places = 0) [ask africans with [convinced = 1 and stage != 1][set happinessafrica happinessafrica - 1 die]]


;american people and free places


set americans_back count americans with [convinced = 1 and stage != 1]
let available_placesAM  (free_uas_places + free_ueu_places + free_uaf_places)

ask americans with [convinced = 1 and stage != 1][

;if (free_ueu_places != 0 and free_uas_places != 0 and free_uaf_places != 0)  [ set destination random int ( l * europerate + m * asiarate + n * africarate ) retry-abroadA4AM]  
  
if (free_ueu_places != 0 and free_uas_places = 0 and free_uaf_places != 0)  [ set destination random-float ( l * europerate + n * africarate ) retry-abroadA2AM] 
  
if (free_ueu_places = 0 and free_uas_places != 0 and free_uaf_places != 0)  [ set destination random-float ( m * asiarate + n * africarate ) retry-abroadA3AM]
  
if (free_ueu_places != 0 and free_uas_places != 0 and free_uaf_places = 0 )  [ set destination random-float ( l * europerate + m * asiarate  ) retry-abroadA1AM]
  

if (free_ueu_places != 0 and free_uas_places = 0 and free_uaf_places = 0 ) [move-to one-of EuropeanBlock set pastdestination 1 set stage 1 set free_ueu_places free_ueu_places - 1 set happinessamerica happinessamerica + 1]

if (free_ueu_places = 0 and free_uas_places != 0 and free_uaf_places = 0 ) [move-to one-of AsianBlock set pastdestination 4 set stage 1 set free_uas_places free_uas_places - 1 set happinessamerica happinessamerica + 1]

if (free_ueu_places = 0 and free_uas_places = 0 and free_uaf_places != 0 )[move-to one-of AfricanBlock set pastdestination 2 set stage 1 set  free_uaf_places free_uaf_places - 1 set happinessamerica happinessamerica + 1]]
 
if (free_ueu_places = 0 and free_uas_places = 0 and free_uaf_places = 0) [ask americans with [convinced = 1 and stage != 1][set happinessamerica happinessamerica - 1 die]]

; asian people and free places 
 

set asians_back count asians with [convinced = 1 and stage != 1]
let available_placesAS  (free_cusa_places + free_ceu_places + free_caf_places)

ask asians with [ convinced = 1 and stage != 1][ 

;if (free_ceu_places > 0 and free_cusa_places > 0 and free_caf_places > 0) [ set destination random int ( p * europerate + q * americarate  + r * africarate ) retry-abroadA4AS]

if (free_ceu_places != 0 and free_cusa_places != 0 and free_caf_places = 0 ) [ set destination random-float ( p * europerate + q * americarate  ) retry-abroadA1AS]
  
if (free_ceu_places != 0  and free_cusa_places = 0 and free_caf_places != 0 ) [ set destination random-float ( p * europerate + r * africarate  ) retry-abroadA2AS] 
  
if (free_ceu_places = 0 and free_cusa_places != 0 and free_caf_places != 0)  [ set destination random-float ( q * americarate   + r * africarate ) retry-abroadA3AS]
  
  

if (free_ceu_places != 0 and free_cusa_places = 0 and free_caf_places = 0 ) [move-to one-of EuropeanBlock set pastdestination 1 set stage 1 set free_ceu_places free_ceu_places - 1 set happinessasia happinessasia + 1 ]

if (free_ceu_places = 0 and free_cusa_places != 0 and free_caf_places = 0 ) [move-to one-of AmericanBlock set pastdestination 3 set stage 1 set free_cusa_places free_cusa_places - 1 set happinessasia happinessasia + 1 ]
 
if (free_ceu_places = 0 and free_cusa_places = 0 and free_caf_places != 0)  [move-to one-of AfricanBlock set pastdestination 2 set stage 1 set free_caf_places free_caf_places - 1 set happinessasia happinessasia + 1 ] ]


if (free_ceu_places = 0 and free_cusa_places = 0 and free_caf_places = 0) [ask asians with [convinced = 1 and stage != 1][set happinessasia happinessasia - 1 die]]



; european people and free places 


set europeans_back count europeans with [convinced = 1 and stage != 1]
let available_placesEU  (free_eas_places + free_eusa_places + free_eaf_places)

ask europeans with [convinced = 1 and stage != 1][

;if (free_eas_places > 0 and free_eusa_places > 0 and free_eaf_places > 0)  [ set destination random int ( x * africarate + y * americarate + z * asiarate ) retry-abroadA4EU]

if (free_eas_places != 0 and free_eusa_places != 0 and free_eaf_places = 0 )[ set destination random-float ( y * americarate + z * asiarate ) retry-abroadA1EU]
  
if (free_eas_places > 0 and free_eusa_places = 0 and free_eaf_places > 0) [ set destination random-float ( x * africarate + y * americarate ) retry-abroadA2EU]
  
if (free_eas_places = 0 and free_eusa_places > 0 and free_eaf_places > 0)  [ set destination random-float ( x * africarate + z * asiarate ) retry-abroadA3EU]
  
  

if (free_eas_places != 0 and free_eusa_places = 0 and free_eaf_places = 0) [move-to one-of AsianBlock set pastdestination 4 set stage 1 set free_eas_places free_eas_places - 1 set happinesseurope happinesseurope + 1]

if (free_eas_places = 0 and free_eusa_places != 0 and free_eaf_places = 0)[move-to one-of AmericanBlock set pastdestination 3 set stage 1 set free_eusa_places free_eusa_places - 1 set happinesseurope happinesseurope + 1]

if (free_eas_places = 0 and free_eusa_places = 0 and free_eaf_places != 0) [move-to one-of AfricanBlock set pastdestination 2 set stage 1 set free_eaf_places free_eaf_places - 1 set happinesseurope happinesseurope + 1]]

if (free_eas_places = 0 and free_eusa_places = 0 and free_eaf_places = 0) [ask europeans with [convinced = 1 and stage != 1][set happinesseurope happinesseurope - 1 die]]

 
end

;retry-abroad africa

to retry-abroadA1
 ;set africans_back count africans with [convinced = 1 and stage != 1]  
if (destination <= a * europerate and free_aeu_places > 0 ) [move-to one-of EuropeanBlock set pastdestination 1 set stage 1 set free_aeu_places free_aeu_places - 1 set happinessafrica happinessafrica + 1 ]
if (destination > a * europerate and free_aas_places > 0) [move-to one-of AsianBlock set pastdestination 4 set stage 1 set free_aas_places free_aas_places - 1 set happinessafrica happinessafrica + 1 ]
end


to retry-abroadA2
  ; set africans_back count africans with [convinced = 1 and stage != 1]  
if (destination <= a * europerate and free_aeu_places > 0 ) [move-to one-of EuropeanBlock set pastdestination 1 set stage 1 set free_aeu_places free_aeu_places - 1 set happinessafrica happinessafrica + 1]
if (destination > a * europerate and free_ausa_places > 0 ) [move-to one-of AmericanBlock set pastdestination 3 set stage 1 set free_ausa_places free_ausa_places - 1 set happinessafrica happinessafrica + 1 ]
end

to retry-abroadA3
  ; set africans_back count africans with [convinced = 1 and stage != 1]
if (destination <= b * americarate and free_ausa_places > 0 )[move-to one-of AmericanBlock set pastdestination 3 set stage 1 set free_ausa_places free_ausa_places - 1 set happinessafrica happinessafrica + 1]
if (destination > b * americarate and free_aas_places > 0 ) [move-to one-of AsianBlock set pastdestination 4 set stage 1 set free_aas_places free_aas_places - 1 set happinessafrica happinessafrica + 1 ]
end


; retry-abroad america

to retry-abroadA1AM
  ; set americans_back count americans with [convinced = 1 and stage != 1]  
if (destination <= l * europerate and free_ueu_places > 0 )  [move-to one-of EuropeanBlock set pastdestination 1 set stage 1 set free_ueu_places free_ueu_places - 1 set happinessamerica happinessamerica + 1]
if (destination > l * europerate and free_uas_places > 0 ) [move-to one-of AsianBlock set pastdestination 4 set stage 1 set free_uas_places free_uas_places - 1 set happinessamerica happinessamerica + 1]
end


to retry-abroadA2AM
   ;set americans_back count americans with [convinced = 1 and stage != 1]  
if (destination <= l * europerate and free_ueu_places > 0 ) [move-to one-of EuropeanBlock set pastdestination 1 set stage 1 set free_ueu_places free_ueu_places - 1 set happinessamerica happinessamerica + 1 ]
if (destination > l * europerate and free_uaf_places > 0 ) [move-to one-of AfricanBlock set pastdestination 2 set stage 1 set free_uaf_places free_uaf_places - 1 set happinessamerica happinessamerica + 1]
end

to retry-abroadA3AM
   ;set americans_back count americans with [convinced = 1 and stage != 1]
if (destination <= m * asiarate and free_uas_places > 0 ) [move-to one-of AsianBlock set pastdestination 4 set stage 1 set free_uas_places free_uas_places - 1 set happinessamerica happinessamerica + 1] 
if (destination > m * asiarate and free_uaf_places > 0 ) [move-to one-of AfricanBlock set pastdestination 2 set stage 1 set free_uaf_places free_uaf_places - 1 set happinessamerica happinessamerica + 1]

end


; retry-abroad asia

to retry-abroadA1AS
  ;set asians_back count asians with [convinced = 1 and stage != 1]  
 if (destination <= p * europerate and free_ceu_places > 0 )  [move-to one-of EuropeanBlock set pastdestination 1 set stage 1 set free_ceu_places free_ceu_places - 1 set happinessasia happinessasia + 1]

 if (destination > p * europerate and free_cusa_places > 0 )  [move-to one-of AmericanBlock set pastdestination 3 set stage 1 set stage 1 set free_cusa_places free_cusa_places - 1 set happinessasia happinessasia + 1]

end


to retry-abroadA2AS
   ;set asians_back count asians with [convinced = 1 and stage != 1]  
 if (destination <= p * europerate and free_ceu_places > 0 ) [move-to one-of EuropeanBlock set pastdestination 1 set stage 1 set free_ceu_places free_ceu_places - 1 set happinessasia happinessasia + 1 ]

 if (destination > p * europerate and free_caf_places > 0 )  [move-to one-of AfricanBlock set pastdestination 2 set stage 1 set free_caf_places free_caf_places - 1 set happinessasia happinessasia + 1]

 
end

to retry-abroadA3AS
  ;set asians_back count asians with [convinced = 1 and stage != 1]
if (destination <= q * americarate and free_caf_places > 0 ) [move-to one-of AmericanBlock set pastdestination 3 set stage 1 set free_caf_places free_caf_places - 1 set happinessasia happinessasia + 1]
if (destination > q * americarate and free_cusa_places > 0 ) [move-to one-of AfricanBlock set pastdestination 2 set stage 1 set stage 1 set free_cusa_places free_cusa_places - 1 set happinessasia happinessasia + 1]

end

; retry-abroad europe

to retry-abroadA1EU
   ;set europeans_back count europeans with [convinced = 1 and stage != 1]  
if (destination <= y * americarate and free_eusa_places > 0 ) [move-to one-of AmericanBlock set pastdestination 3 set stage 1 set free_eusa_places free_eusa_places - 1 set happinesseurope happinesseurope + 1] 
if (destination > y * americarate and free_eas_places > 0 ) [move-to one-of AsianBlock set pastdestination 4 set stage 1 set free_eas_places free_eas_places - 1 set happinesseurope happinesseurope + 1]

end


to retry-abroadA2EU
   ;set europeans_back count europeans with [convinced = 1 and stage != 1]  
if (destination <= x * africarate and free_eaf_places > 0 ) [move-to one-of AfricanBlock set pastdestination 2 set stage 1 set free_eaf_places free_eaf_places - 1 set happinesseurope happinesseurope + 1]
if (destination > x * asiarate and free_eas_places > 0 ) [move-to one-of AsianBlock set pastdestination 4 set stage 1  set free_eas_places free_eas_places - 1 set happinesseurope happinesseurope + 1] 

end

to retry-abroadA3EU
   ;set europeans_back count europeans with [convinced = 1 and stage != 1]
if (destination <= x * africarate and free_eaf_places > 0 ) [move-to one-of AfricanBlock set pastdestination 2 set stage 1 set free_eaf_places free_eaf_places - 1 set happinesseurope happinesseurope + 1]
if (destination > x * africarate and free_eusa_places > 0 ) [move-to one-of AmericanBlock set pastdestination 3 set stage 1 set free_eusa_places free_eusa_places - 1 set happinesseurope happinesseurope + 1]
 
end

to feedback   
  ; we randomly modify the variable " quality" in a range of 40 around 100                                                                
   ask turtles with [ pastdestination != 0 and stage = 1 ][
   ifelse random-float 1 > 0.5  [set quality quality + random -40]
   [set quality quality + random 40]  ]
   ask turtles with [ pastdestination != 0 ] [ set label quality set label-color white ]
  
  
  ;; Europe quality
  ;; we sum the quality of the interns that have been in Europe
  set qualityinEurope sum [quality] of asians with [ pastdestination = 1 ] + sum [quality] of americans with [ pastdestination = 1 ] + 
  sum [quality] of africans with [ pastdestination = 1 ]

  ;; America quality
  set qualityinAmerica sum [quality] of asians with [ pastdestination = 3 ] + sum [quality] of europeans with [ pastdestination = 3 ] + 
  sum [quality] of africans with [ pastdestination = 3 ]

  ;; Africa quality
  set qualityinAfrica sum [quality] of asians with [ pastdestination = 2 ] + sum [quality] of americans with [ pastdestination = 2 ] + 
  sum [quality] of Europeans with [ pastdestination = 2 ]

  ;; Asia quality
  set qualityinAsia sum [quality] of europeans with [ pastdestination = 4 ] + sum [quality] of americans with [ pastdestination = 4 ] + 
  sum [quality] of africans with [ pastdestination = 4 ]

  ;;;;; Is just the sum of the quality after the internship in each country
  
  
  ;; According to the feedback rate 
  ;; How many interns have been in europe?
  
  let pastpersoninEurope count asians with [ pastdestination = 1 ] + count americans with [ pastdestination = 1 ] + 
  count africans with [ pastdestination = 1 ]
  
   
   ;; How many interns have been in america?
  let pastpersoninAmerica count asians with [ pastdestination = 3 ] + count europeans with [ pastdestination = 3 ] + 
  count africans with [ pastdestination = 3 ]

    
  ;; How many interns have been in asia?
  let pastpersoninAsia count europeans with [ pastdestination = 4 ] + count americans with [ pastdestination = 4 ] + 
  count africans with [ pastdestination = 4 ]
  
  
  ;; How many interns have been in africa?
  let pastpersoninAfrica count asians with [ pastdestination = 2 ] + count americans with [ pastdestination = 2 ] + 
  count europeans with [ pastdestination = 2 ]
   
  
  ;; qualityrate is the rate calculated with: quality in america for the past generation that made the internship / sum of the standard quality before of the internship
  ;; As example Europebase is 300 if in the past only 3 person did the internship in Europe, according to the fact that when the people leave their country their expectation is the mean 100
  
  ifelse pastpersoninEurope != 0 [ 
  let Europebase pastpersoninEurope * 100
  set Europerate qualityinEurope / Europebase ] [ set Europerate 1 ] 
  
   
  ;; we set up this ifelse because is possible that no one has done an internship in a particular country when we decrease the number of places and/or the population or if the feedback rate is really low!
  ifelse pastpersoninAmerica != 0 [ 
  let Americabase pastpersoninAmerica * 100
  set Americarate qualityinAmerica / Americabase ] [ set Americarate 1 ]
  
  
  ifelse pastpersoninAsia != 0 [ 
  let Asiabase pastpersoninAsia * 100
  set Asiarate qualityinAsia / Asiabase ] [ set Asiarate 1 ]
  
 
 
  ifelse pastpersoninAfrica != 0 [ 
  let Africabase pastpersoninAfrica * 100
  set Africarate qualityinAfrica / Africabase ] [ set Africarate 1 ]
 
  
  end


to elfarol
  
  ;; 4 country with places
  
  let lostinformation random-float 1 
    
 if ( internspastdestination1 != 0 and internspastdestination2 != 0 and internspastdestination3 != 0 and internspastdestination4 != 0 and lostinformation < 0.7 )   [
 if (internspastdestination1 > 0.30 * ( internspastdestination1 + internspastdestination2 + internspastdestination3 + internspastdestination4 ) )
 [set europerate europerate - 0.05 ]
  if (internspastdestination2 > 0.30 * ( internspastdestination1 + internspastdestination2 + internspastdestination3 + internspastdestination4 ) )
 [set africarate africarate - 0.05 ]
   if (internspastdestination3 > 0.30 * ( internspastdestination1 + internspastdestination2 + internspastdestination3 + internspastdestination4 ) )
 [set americarate americarate - 0.05 ]
   if (internspastdestination4 > 0.30 * ( internspastdestination1 + internspastdestination2 + internspastdestination3 + internspastdestination4 ) )
 [set asiarate asiarate - 0.05 ]]
 
 ; 3 country with places
  if ( internspastdestination1 = 0 or internspastdestination2 = 0 or internspastdestination3 = 0 or internspastdestination4 = 0 and lostinformation < 0.7 )
 [  if (internspastdestination1 > 0.40 * ( internspastdestination1 + internspastdestination2 + internspastdestination3 + internspastdestination4 ) )
 [set europerate europerate -  0.05 ]
  if (internspastdestination2 > 0.40 * ( internspastdestination1 + internspastdestination2 + internspastdestination3 + internspastdestination4 ) )
 [set africarate africarate - 0.05 ]
   if (internspastdestination3 > 0.40 * ( internspastdestination1 + internspastdestination2 + internspastdestination3 + internspastdestination4 ) )
 [set americarate americarate -  0.05  ]
   if (internspastdestination4 > 0.40 * ( internspastdestination1 + internspastdestination2 + internspastdestination3 + internspastdestination4 ) )
 [set asiarate asiarate -  0.05 ]]

end 

to go
  
 ask turtles with [ pastdestination != 0 ] [die]
 internship  
 select
 
 
 wait 1
 tick
  
end