breed [agents agent] agents-own [memory] globals [ options ;; list that contains the following values - according to the chosen payoff matrix: [low medium high] medium ;; numeric value assigned to the 'medium' demand high ;; numeric value assigned to the 'high' demand simplex-side-length ;; length of the simplex side agents-list ;; list that contains all the agents in the population elapsed-iterations ;; number of elapsed iterations since the simulation was started equitable-equilibrium-stop-condition ;; conditions for equitable-equilibrium fractious-state-stop-condition ;; conditions for fractious state equitable-equilibrium? ;; boolean variable that will become true if and only if the system has reached an equitable equilibrium IN THE CURRENT ITERATION equitable-equilibrium-at-least-once? ;; boolean variable that will become true if and only if the system has reached an equitable equilibrium AT LEAST ONCE DURING THE SIMULATION fractious-state-at-least-once? ;; boolean variable that will become true if and only if the system has reached a fractious state IN THE CURRENT ITERATION fractious-state? ;; boolean variable that will become true if and only if the system has reached an equitable equilibrium AT LEAST ONCE DURING THE SIMULATION system-status ;; this variable contains the message shown in the system-status monitor, in the interface scrren. endorsed-memory-weights ;; this list contains the weights assigned to each term in the endorsed memory set ] to setup print "" ;; leave a black line in the command center clear-all ;; reset variables ;; DEFINE THE REWARDS ACCORDING TO THE SELECTED PAYOFF MATRIX (the value for the lowest reward -low- is chosen in the interface screen) set high 100 - low ;; set the value assigned to high set medium 50 ;; set the value assigned to medium set options (list low medium high) ;; create a list which contains the values assigned to low, medium and high according to the selected payoff matrix ;; PRINT THE PAYOFF MATRIX ACCORDING TO THE SELECTED VALUE FOR LOW output-print " L M H " output-type " L |(" output-type low output-type "," output-type low output-type ")|(" output-type low output-type "," output-type medium output-type ")|(" output-type low output-type "," output-type high output-print ")|" output-type " M |(" output-type medium output-type "," output-type low output-type ")|(" output-type medium output-type "," output-type medium output-print ")| (0,0) |" output-type " H |(" output-type high output-type "," output-type low output-print ")| (0,0) | (0,0) |" ;; CREATE THE SIMPLEX set simplex-side-length 150 ;; set the simplex size create-simplex ;; call the procedure 'create-simplex' ;; CREATE A POPULATION OF n AGENTS create-agents n [ set shape "dot" ;; set the agent's shape set size 4 ;; set the agent's size set color black ;; set the agent's colour if label-on-agents? [set label who] ;; create a label with the id of each agent if memory-type = "Standard" [set memory n-values m [one-of options]] ;; create an m-size memory with random values for each agent if memory-type = "Endorsed" [set memory n-values m [one-of options]] ;; create an m-size memory with random values for each agent if memory-type = "Progressive" [set memory n-values 1 [one-of options]] ;; initialize the memory with just one value choosen at random set xcor place-agents-xcor (memory) ;; place the agents in the simplex according to their memory status (x-coordinate) set ycor place-agents-ycor (memory) ;; place the agents in the simplex according to their memory status (y-coordinate) ] ;; SET THE INITIAL VALUE OF SOME OF THE GLOBALS VARIABLES set system-status "----------" ;; this message is shown in the system-status monitor until an equitable equilibrium or a fractious state is reached set equitable-equilibrium? false ;; at first, there is not an equitable equilibrium in the system set fractious-state? false ;; at first, there is not a fractious state in the system set equitable-equilibrium-at-least-once? false ;; at first, there is not an equitable equilibrium in the system set fractious-state-at-least-once? false ;; at first, there is not a fractious state in the system ;; CREATE A LIST WITH ALL THE AGENTS IN THE POPULATION set agents-list sort agents ;; turns the agentset into a list ;; CREATE A LIST OF WEIGHTS FOR THE ENDORSED MEMORY if memory-type = "Endorsed" [ let weights [] ;; list of weights let current-weight 1 ;; lowest weight let i 0 ;; counter (loop) while [i < m] [ set weights fput current-weight weights ;; add the current weight to the list of weights set current-weight current-weight + d ;; increase the weight for the next element set i i + 1 ;; increase the loop counter ] set endorsed-memory-weights weights ;; update the global variable ] if memory-type != "Endorsed" [set d 0] ;; if the memory is not 'endorsed', 'd' (difference common in the arithmetic progression which is followed by the weights of each memory position makes no sense here if decision-rule = "Choose the best reply againts the opponents' most frequent demand" and memory-type = "Endorsed" [beep user-message "This decision rule is not compatible with an endorsed memory" ] ;; displays a warning in a pop-up window end to go set elapsed-iterations 0 ;; initialize the elapsed-iterations counter while [elapsed-iterations < number_of_iterations] ;; we run as many iterations as the value of the variable number_of_iterations [ let players agents-list ;; retrieve the original list of agents repeat (length agents-list) / 2 ;; the number of matches in each iteration is half the number of agents [ ;; 1. TAKE TWO PLAYERS AT RANDOM FROM THE LIST OF AGENTS let player1 one-of players ;; choose one agent from the list of agents at random set players remove player1 players ;; delete this agent so that it can't be chosen again during this iteration let player2 one-of players ;; choose one agent from the list of agents at random set players remove player2 players ;; delete this agent so that it can't be chosen again during this iteration ;; 2. EACH AGENT TAKES A DECISION TAKING INTO ACCOUNT HIS MEMORIES ABOUT PREVIOUS MATCHES let player1-decision take-decision ([memory] of player1) ;; player 1 takes his decision let player2-decision take-decision ([memory] of player2) ;; player 2 takes his decision ;; 3. EACH AGENT STORES THE OPPONENT'S DECISION IN HIS MEMORY ask player1 [set memory fput player2-decision memory] ;; player 1 stores player 2's decision in his memory ask player2 [set memory fput player1-decision memory] ;; player 2 stores player 1's decision in his memory if memory-type = "Standard" or memory-type = "Endorsed" [ask player1 [set memory but-last memory]] ;; Standard and endorsed memory: player 1 deletes his oldest value in his memory. if memory-type = "Progressive" and elapsed-iterations >= (m - 1) [ask player1 [set memory but-last memory]] ;; Progressive memory: player 1 deletes his oldest value in his memory when the m-size memory is reached if memory-type = "Standard" or memory-type = "Endorsed" [ask player2 [set memory but-last memory]] ;; Standard and endorsed memory: player 2 deletes his oldest value in his memory. if memory-type = "Progressive" and elapsed-iterations >= (m - 1) [ask player2 [set memory but-last memory]] ;; Progressive memory: player 2 deletes his oldest value in his memory when the m-size memory is reached ;; 4. UPDATE THE POSITION OF THE TWO AGENTS IN THE SIMPLEX ACCORDING TO THE NEW MEMORY STATUS ask player1 [setxy place-agents-xcor (memory) place-agents-ycor (memory)] ;; place the agents in the simplex according to their memory status (x-coordinate) ask player2 [setxy place-agents-xcor (memory) place-agents-ycor (memory)] ;; place the agents in the simplex according to their memory status (y-coordinate) ] set elapsed-iterations elapsed-iterations + 1 ;; the current iteration has finished tick ;; increase the tick counter (number of elapsed iterations) check-stop-conditions ;; call the procedure 'check-stop-conditions' if equitable-equilibrium? = true and stop-if-equilibrium? [print "* * * SIMULATION FINISHED * * *" stop] ;; if the 'stop-if-equilibrium?' swith is on, and the system has reached an equitable equilibrium in this iteration, the simulation stops now. if fractious-state? = true and stop-if-equilibrium? [print "* * * SIMULATION FINISHED * * *" stop] ;; if the 'fractious-state?' swith is on, and the system has reached a fractious state in this itaration, the simulation stops now. if elapsed-iterations = number_of_iterations ;; when the maximum number of iterations is reached, a message is shown and the simulation finishes. [ print "* * * SIMULATION FINISHED: The system has reached the maximum number of iterations. * * *" if equitable-equilibrium-at-least-once? = false and fractious-state-at-least-once? = false [set system-status "SIMULATION FINISHED" print "* * * No equilibrium was reached in the system. * * *"] stop ] ] end to-report take-decision [agents_memory] let random-number random-float 1 ;; create a random number ifelse random-number < epsilon ;; if the random number is lower than epsilon, the decision is taken randomly [ report one-of options ] ;; if the random number is lower than epsilon, the decision rule is 'rational' [ if decision-rule = "Demand the option that maximizes the expected benefit" [ let probability-opponent-demands-L (length filter [? = low] agents_memory) / m ;; count the number of appearances of L in the agent's memory let probability-opponent-demands-M (length filter [? = medium] agents_memory) / m ;; count the number of appearances of M in the agent's memory let probability-opponent-demands-H (length filter [? = high] agents_memory) / m ;; count the number of appearances of H in the agent's memory let reward-L low ;; set the reward assigned to low let reward-M medium ;; set the reward assigned to medium let reward-H high ;; set the reward assigned to high ;; the agent calculates the expected benefit if he chooses L, M or H let expected-benefit-L reward-L * probability-opponent-demands-L + reward-L * probability-opponent-demands-M + reward-L * probability-opponent-demands-H let expected-benefit-M reward-M * probability-opponent-demands-L + reward-M * probability-opponent-demands-M + 0 * probability-opponent-demands-H let expected-benefit-H reward-H * probability-opponent-demands-L + 0 * probability-opponent-demands-M + 0 * probability-opponent-demands-H ;; calculate the best option let possible-demands (list expected-benefit-L expected-benefit-M expected-benefit-H) ;; the list possible-demands contains: [benefit if the agent chooses L , benefit if the agent chooses M , benefit if the agent chooses H] let best-option max possible-demands ;; the best option is the highest value in the list possible-demands ;; PARTICULAR CASE: TWO OR THREE OPTIONS RESULT IN THE SAME EXPECTED BENEFIT if length filter [? = best-option] possible-demands > 1 ;; if two or three options produce the same benefit... [ if item 0 possible-demands = item 1 possible-demands and item 1 possible-demands = item 2 possible-demands [report one-of options] ;; benefit (low) = benefit (medium) = benefit (high) -> choose low, medium or high at random if item 0 possible-demands = item 1 possible-demands [report one-of list low medium] ;; benefit (low) = benefit (medium) -> choose low or medium at random if item 0 possible-demands = item 2 possible-demands [report one-of list low high] ;; benefit (low) = benefit (high) -> choose low or high at random if item 1 possible-demands = item 2 possible-demands [report one-of list medium high] ;; benefit (medium) = benefit (high) -> choose medium or high at random ] ;; GENERAL CASE: ONLY ONE OF THE THREE DEMANDS MAXIMIZE THE EXPECTED BENEFIT if item 0 possible-demands = best-option [report low] ;; if the first element in the list of possible demands is the best option, then the agent chooses low if item 1 possible-demands = best-option [report medium] ;; if the second element in the list of possible demands is the best option, then the agent chooses medium if item 2 possible-demands = best-option [report high] ;; if the third element in the list of possible demands is the best option, then the agent chooses high ] if decision-rule = "Demand the option that maximizes the expected benefit" and memory-type = "Endorsed" [ let i 0 ;; set a counter for the while loop: 0<=i 1 ;; if two or three options produce the same benefit... [ if item 0 possible-demands = item 1 possible-demands and item 1 possible-demands = item 2 possible-demands [report one-of options] ;; benefit (low) = benefit (medium) = benefit (high) -> choose low, medium or high at random if item 0 possible-demands = item 1 possible-demands [report one-of list low medium] ;; benefit (low) = benefit (medium) -> choose low or medium at random if item 0 possible-demands = item 2 possible-demands [report one-of list low high] ;; benefit (low) = benefit (high) -> choose low or high at random if item 1 possible-demands = item 2 possible-demands [report one-of list medium high] ;; benefit (medium) = benefit (high) -> choose medium or high at random ] ;; GENERAL CASE: ONLY ONE OF THE THREE DEMANDS MAXIMIZE THE EXPECTED BENEFIT if item 0 possible-demands = best-option [report low] ;; if the first element in the list of possible demands is the best option, then the agent chooses low if item 1 possible-demands = best-option [report medium] ;; if the second element in the list of possible demands is the best option, then the agent chooses medium if item 2 possible-demands = best-option [report high] ;; if the third element in the list of possible demands is the best option, then the agent chooses high ] if decision-rule = "Choose the best reply againts the opponents' most frequent demand" [ let probability-opponent-demands-L (length filter [? = low] agents_memory) / m ;; count the number of appearances of L in the agent's memory let probability-opponent-demands-M (length filter [? = medium] agents_memory) / m ;; count the number of appearances of M in the agent's memory let probability-opponent-demands-H (length filter [? = high] agents_memory) / m ;; count the number of appearances of H in the agent's memory ;; estimate the option that the opponent is likely to take let possible-demands (list probability-opponent-demands-L probability-opponent-demands-M probability-opponent-demands-H) ;; the list possible-demands contains: [probability that the opponent chooses L , probability that the opponent chooses M , probability that the opponent choosess H] let opponent-most-likely-demand max possible-demands ;; the opponent's most likely option is the highest value in the list possible-demands ;; PARTICULAR CASE: THERE IS A TIE IN THE NUMBER OF APPEARANCES OF low, medium or high if length filter [? = opponent-most-likely-demand] possible-demands > 1 ;; there is a tie in the opponents' most frequent demands in the previous matches [ if item 0 possible-demands = item 1 possible-demands and item 1 possible-demands = item 2 possible-demands [report one-of options] ;; frequency (low) = frequency (medium) = frequency (high) -> choose low, medium or high at random if item 0 possible-demands = item 1 possible-demands [report one-of list low medium] ;; frequency (low) = frequency (medium) -> choose low or medium at random if item 0 possible-demands = item 2 possible-demands [report one-of list low high] ;; frequency (low) = frequency (high) -> choose low or high at random if item 1 possible-demands = item 2 possible-demands [report one-of list medium high] ;; frequency (medium) = frequency (high) -> choose medium or high at random ] ;; GENERAL CASE: ONLY ONE OF THE THREE DEMANDS IS THE MOST FREQUENT if item 0 possible-demands = opponent-most-likely-demand [report high] ;; if the first element in the list of possible demands is the best option, then the agent chooses low if item 1 possible-demands = opponent-most-likely-demand [report medium] ;; if the second element in the list of possible demands is the best option, then the agent chooses medium if item 2 possible-demands = opponent-most-likely-demand [report low] ;; if the third element in the list of possible demands is the best option, then the agent chooses high ] ] end to-report place-agents-xcor [agents_memory] let appearances-of-L length filter [? = low] agents_memory ;; count the number of appearances of L in the agent's memory let appearances-of-M length filter [? = medium] agents_memory ;; count the number of appearances of M in the agent's memory let appearances-of-H length filter [? = high] agents_memory ;; count the number of appearances of H in the agent's memory ;; GENERAL CASE (there is one or more appearances of H in the memory vector) ifelse appearances-of-H > 0 [ let prop_H_L (appearances-of-H / (appearances-of-L + appearances-of-H)) ;; #H / (#L + #H) let prop_H_M (appearances-of-H / (appearances-of-M + appearances-of-H)) ;; #H / (#M + #H) let x-coordinate (1 / (((1 / prop_H_L) + (1 / prop_H_M))*(1 / sin 60) - (2 / tan 60))) * (((1 / prop_H_L)*(1 / sin 60))- (1 / tan 60)) * simplex-side-length let shifted-x-coordinate x-coordinate - simplex-side-length / 2 ;; we need to shift this as the triangle is centered in (0,0) report shifted-x-coordinate ] ;; PARTICULAR CASE (if there are no H's in the memory vector, a determination appears in the general expression. We deal with this case separately) [ let prop_L_M (appearances-of-L / (appearances-of-L + appearances-of-M)) ;; #L / (#L + #M) let x-coordinate prop_L_M * simplex-side-length let shifted-x-coordinate x-coordinate - simplex-side-length / 2 ;; we need to shift this as the triangle is centered in (0,0) report shifted-x-coordinate ] end to-report place-agents-ycor [agents_memory] let appearances-of-L length filter [? = low] agents_memory ;; count the number of appearances of L in the agent's memory let appearances-of-M length filter [? = medium] agents_memory ;; count the number of appearances of M in the agent's memory let appearances-of-H length filter [? = high] agents_memory ;; count the number of appearances of H in the agent's memory ;; GENERAL CASE (there is one or more appearances of H in the memory vector) ifelse appearances-of-H > 0 [ let prop_H_L (appearances-of-H / (appearances-of-L + appearances-of-H)) ;; #H / (#L + #H) let prop_H_M (appearances-of-H / (appearances-of-M + appearances-of-H)) ;; #H / (#M + #H) let y-coordinate (1 / (((1 / prop_H_L) + (1 / prop_H_M))*(1 / sin 60) - (2 / tan 60))) * simplex-side-length let shifted-y-coordinate y-coordinate - sqrt(3) / 4 * simplex-side-length ;; we need to shift this as the triangle is centered in (0,0) report shifted-y-coordinate ] ;; PARTICULAR CASE (if there are no H's in the memory vector, a determination appears in the general expression. We deal with this case separately) [ let y-coordinate 0 let shifted-y-coordinate y-coordinate - sqrt(3) / 4 * simplex-side-length ;; we need to shift this as the triangle is centered in (0,0) report shifted-y-coordinate ] end to create-simplex let M_xcor (- simplex-side-length / 2) ;; x-coordinate of the left vertex of the simplex (M). let M_ycor (- sqrt(3) * simplex-side-length / 4) ;; y-coordinate of the left vertex of the simplex (M). let L_xcor (simplex-side-length / 2) ;; x-coordinate of the right vertex of the simplex (L). let L_ycor (- sqrt(3) * simplex-side-length / 4) ;; y-coordinate of the right vertex of the simplex (L). let H_xcor 0 ;; x-coordinate of the top vertex of the simplex (H). let H_ycor (sqrt(3) / 4 * simplex-side-length) ;; y-coordinate of the top vertex of the simplex (H). let background-color [130 188 183] ;; define the background color ask patches [set pcolor background-color] ;; set the background color let surrounding-simplex-side-length simplex-side-length + 6 ;; set the size of the surrounding simplex. if decision-rule = "Demand the option that maximizes the expected benefit" [ ;; LEFT SIDE OF THE TRIANGLE: calculate the proportions of M and H in the memory vector so that the expected benefits of choosing M and choosing H match when there are no appearances of L in the memory vector(le = left equilibrium) let Ale (medium / high) let Ble (1 -( medium / high)) ;; RIGHT SIDE OF THE TRIANGLE: calculate the proportions of L and H in the memory vector so that the expected benefits of choosing L and choosing H match when there are no appearances of M in the memory vector (re = right equilibrium) let Cre (1 -( low / high)) let Apede (low / high) ;; LOWER SIDE OF THE TRIANGLE: calculate the proportions of L and M in the memory vector so that the expected benefits of choosing L and choosing M match when there are no appearances of H in the memory vector (lwe = lower equilibrium) let Clwe (1 -( low / medium)) let Blwe (low / medium) ;; calculate the proportions of L, M and H in the memory vector so that the expected benefit of choosing L, choosing M and choosing H match let Aep low / high ;; value of A in the equilibrium point (ep) let Bep low / medium - low / high ;; value of B in the equilibrium point (ep) let Cep 1 - low / medium ;; value of C in the equilibrium point (ep) let ep-x-coordinate-numerator 1 / ((Cep / (Aep + Cep)) * sin 60) - 1 / tan 60 let ep-x-coordinate-denominator ((1 / (Cep / (Aep + Cep)) + 1 / (Cep / (Bep + Cep))) * 1 / sin 60 ) - 2 / tan 60 let ep-x-coordinate ep-x-coordinate-numerator / ep-x-coordinate-denominator * simplex-side-length let shifted-ep-x-coordinate ep-x-coordinate - simplex-side-length / 2 let ep-y-coordinate (1 / (((1 / (Cep / (Aep + Cep))) + (1 / (Cep / (Bep + Cep)))) * (1 / sin 60) - 2 / tan 60 )) * simplex-side-length let shifted-ep-y-coordinate ep-y-coordinate - sqrt(3) / 4 * simplex-side-length ;; DRAW THE DECISION BORDERS create-turtles 1 [ ;; We only draw the decision borders if the memory type is not endorsed. ;\\ ifelse memory-type = "Endorsed" [ ;; OUTER TRIANGLE set size 0 setxy (surrounding-simplex-side-length / 2)(- sqrt(3) / 4 * (surrounding-simplex-side-length - (surrounding-simplex-side-length - simplex-side-length) / 4)) set color black set pen-size 5 pd set heading 270 fd surrounding-simplex-side-length ;; move towards the left vertex (M) ;\\ set heading 30 fd surrounding-simplex-side-length ;; move towards the top vertex (H) ;\\ set heading 150 fd surrounding-simplex-side-length ;; move towards the right vertex (L) ;\\ ] [ ;; OUTER TRIANGLE set size 0 setxy (surrounding-simplex-side-length / 2)(- sqrt(3) / 4 * (surrounding-simplex-side-length - (surrounding-simplex-side-length - simplex-side-length) / 4)) set color green set pen-size 5 pd set heading 270 fd (surrounding-simplex-side-length * Clwe) set color yellow fd (surrounding-simplex-side-length * Blwe) ;; move towards the left vertex (M) ;\\ set heading 30 fd (surrounding-simplex-side-length * Ble) set color red fd (surrounding-simplex-side-length * Ale) ;; move towards the top vertex (H) ;\\ set heading 150 fd (surrounding-simplex-side-length * Apede) set color green fd (surrounding-simplex-side-length * Cre) pu ;; move towards the right vertex (L) ;\\ ;; DECISION BORDERS ;; right border setxy shifted-ep-x-coordinate shifted-ep-y-coordinate set color black set pen-size 1 pd move-to patch (simplex-side-length / 2 - Cre * simplex-side-length * cos 60) (Cre * simplex-side-length * sin 60 - sqrt(3) / 4 * simplex-side-length) pu ;; left border setxy shifted-ep-x-coordinate shifted-ep-y-coordinate set color black set pen-size 1 pd move-to patch (Ble * simplex-side-length * cos 60 - simplex-side-length / 2) (Ble * simplex-side-length * sin 60 - sqrt(3) / 4 * simplex-side-length) pu ;; lower border setxy shifted-ep-x-coordinate shifted-ep-y-coordinate set color black set pen-size 1 pd move-to patch ( simplex-side-length / 2 - Clwe * simplex-side-length) (- sqrt(3) / 4 * simplex-side-length) pu ] die ] ;; ADD A LABEL TO THE SIMPLEX VERTICES ask patch (M_xcor - 5) (M_ycor - 2) [set plabel-color yellow set plabel "MEDIUM 50"] ask patch (L_xcor + 18)(L_ycor - 2) [set Plabel-color 54 set plabel WORD "LOW " low] ask patch (H_xcor + 4) (H_ycor + 6) [set Plabel-color RED set plabel WORD "HIGH " high] ] if decision-rule = "Choose the best reply againts the opponents' most frequent demand" [ let ep-x-coordinate simplex-side-length / 2 let shifted-ep-x-coordinate ep-x-coordinate - simplex-side-length / 2 let ep-y-coordinate (sqrt (3) / 6) * simplex-side-length let shifted-ep-y-coordinate ep-y-coordinate - (sqrt (3) / 4) * simplex-side-length let coordenada_equilibrio_y (sqrt (3) / 6 - sqrt (3) / 4) * simplex-side-length ;; DRAW THE DECISION BORDERS create-turtles 1 [ ;\\ ;; OUTER TRIANGLE set size 0 setxy (surrounding-simplex-side-length / 2)(- sqrt(3) / 4 * (surrounding-simplex-side-length - (surrounding-simplex-side-length - simplex-side-length) / 4)) set color green set pen-size 5 pd set heading 270 fd (surrounding-simplex-side-length * 1 / 2) set color YELLOW fd (surrounding-simplex-side-length * 1 / 2) set heading 30 fd (surrounding-simplex-side-length * 1 / 2) set color RED fd (surrounding-simplex-side-length * 1 / 2) set heading 150 fd (surrounding-simplex-side-length * 1 / 2) set color 54 fd (surrounding-simplex-side-length * 1 / 2) pu ;; DECISION BORDERS set color black set pen-size 1 ;; right border setxy shifted-ep-x-coordinate shifted-ep-y-coordinate pd move-to patch (simplex-side-length / 4) 0 pu ;; left border setxy shifted-ep-x-coordinate shifted-ep-y-coordinate pd move-to patch (- simplex-side-length / 4) 0 pu ;; lower border setxy shifted-ep-x-coordinate shifted-ep-y-coordinate pd move-to patch 0 (- sqrt (3) / 4 * simplex-side-length) die ] ;; ADD A LABEL TO THE SIMPLEX VERTICES ask patch (M_xcor - 5) (M_ycor - 2) [set plabel-color yellow set plabel "MEDIUM 50"] ask patch (L_xcor + 18)(L_ycor - 2) [set Plabel-color 54 set plabel WORD "LOW " low] ask patch (H_xcor + 4) (H_ycor + 6) [set Plabel-color RED set plabel WORD "HIGH " high] ] end to check-stop-conditions if memory-type != "Endorsed" [ set equitable-equilibrium-stop-condition all? agents [length filter [? = medium] memory >= (1 - epsilon) * m] set fractious-state-stop-condition all? agents [length filter [? = medium] memory <= epsilon * m] ] if memory-type = "Endorsed" [ let S (2 + (m - 1) * d) / 2 * m set equitable-equilibrium-stop-condition all? agents [check-endorsed-memory (memory) >= (1 - epsilon) * S ] set fractious-state-stop-condition all? agents [check-endorsed-memory (memory) <= epsilon * S ] ] ;; IF THIS IS THE FIRST TIME THE SYSTEM HAS REACHED AN EQUITABLE EQUILIBRIUM if equitable-equilibrium-stop-condition = true and equitable-equilibrium? = false [ print (word "* * * The system has reached an equitable equilibrium in the iteration number " elapsed-iterations " * * *") set system-status "EQUITABLE EQUILIBRIUM" ;; display "EQUITABLE EQUILIBRIUM" in the system-status monitor set equitable-equilibrium? true ;; now, the system is in equitable equilibrium set equitable-equilibrium-at-least-once? true ;; the system has reached an equitable equilibrium at least once ] ;; IF THIS IS THE FIRST TIME THE SYSTEM HAS REACHED A FRACTIOUS STATE if fractious-state-stop-condition and fractious-state? = false [ print (word "* * * The system has reached a fractious state in the iteration number " elapsed-iterations " * * *") set system-status "FRACTIOUS STATE" ;; display "FRACTIOUS STATE" in the system-status monitor set fractious-state? true ;; now, the system is in fractious state set fractious-state-at-least-once? true ;; the system has reached a fractious state at least once ] ;; IF THE SYSTEM LEAVES THE EQUITABLE EQUILIBRIUM... if equitable-equilibrium? = true and not equitable-equilibrium-stop-condition [ print (word "* * * The system has left the equitable equilibrium in the iteration number " elapsed-iterations " * * *") set equitable-equilibrium? false ] ;; IF THE SYSTEM LEAVES THE FRACTIOUS STATE... if fractious-state? = true and not fractious-state-stop-condition [ print (word "* * * The system has left the fractious state in the iteration number " elapsed-iterations " * * *") set fractious-state? false ] end to-report check-endorsed-memory [agents-memory] let q 0 (foreach agents-memory endorsed-memory-weights [if ?1 = medium [set q q + ?2]]) report q ;; returns the number of elements equal to medium in the agent's memory (each appearance of medium in the memory set is multiplied by the weight of the position in which it appears) end @#$#@#$#@ GRAPHICS-WINDOW 4 10 524 551 100 100 2.54 1 10 1 1 1 0 0 0 1 -100 100 -100 100 0 0 1 Elapsed iterations CC-WINDOW 5 816 551 911 Command Center 0 SLIDER 8 481 180 514 n n 2 100 20 2 1 NIL HORIZONTAL TEXTBOX 50 497 200 515 number of agents 11 0.0 1 SLIDER 8 513 180 546 m m 1 20 10 1 1 NIL HORIZONTAL TEXTBOX 64 529 141 547 memory size 11 0.0 1 CHOOSER 5 673 232 718 low low 10 20 30 40 2 BUTTON 248 769 315 802 SETUP setup NIL 1 T OBSERVER NIL S NIL NIL BUTTON 336 768 403 801 GO go NIL 1 T OBSERVER NIL G NIL NIL SLIDER 180 481 352 514 number_of_iterations number_of_iterations 1 1000 100 1 1 NIL HORIZONTAL SLIDER 180 513 352 546 epsilon epsilon 0 0.2 0.1 .01 1 NIL HORIZONTAL TEXTBOX 246 529 396 547 noise level 11 0.0 1 OUTPUT 5 718 232 801 12 TEXTBOX 160 677 310 695 lowest payoff 11 0.0 1 SWITCH 352 481 519 514 label-on-agents? label-on-agents? 1 1 -1000 MONITOR 370 33 520 78 SYSTEM STATUS system-status 17 1 11 TEXTBOX 7 559 264 651 1. CHOOSE THE PARAMETERS TO RUN THE SIMULATION\nn: number of agents\nm: memory size\nnumber_of_iterations\nepsilon: noise level 11 15.0 1 TEXTBOX 6 653 156 671 2. SELECT A PAYOFF MATRIX 11 15.0 1 TEXTBOX 252 558 439 586 3. CHOOSE A DECISION RULE 11 15.0 1 TEXTBOX 249 748 542 776 5. CLICK SETUP AND THEN GO TO START THE SIMULATION 11 15.0 1 CHOOSER 245 576 483 621 decision-rule decision-rule "Demand the option that maximizes the expected benefit" "Choose the best reply againts the opponents' most frequent demand" 0 CHOOSER 245 649 485 694 memory-type memory-type "Standard" "Progressive" "Endorsed" 0 TEXTBOX 251 630 453 658 4. SELECT A MEMORY CONFIGURATION 11 15.0 1 SWITCH 352 513 519 546 stop-if-equilibrium? stop-if-equilibrium? 0 1 -1000 SLIDER 247 708 339 741 d d 1 10 0 1 1 NIL HORIZONTAL TEXTBOX 346 702 505 746 ONLY IN THE CASE OF ENDORSED \nMEMORY: common difference in the arithmetic progression 9 0.0 1 @#$#@#$#@ WHAT IS IT? ----------- This is a replication of the model developed by Robert Axtell, Joshua M. Epstein and H. Peyton Young (AEY's model hereafter) in which two players demand some portion of the same pie, and the portion of pie that they get depends on the portion demanded by their opponent. HOW IT WORKS ------------ In AEY's model, two players demand some portion of a pie. They could demand three possible portions: low, medium and high. As long as the sum of the two demands is not more than 100 percent of the pie, each player gets what he demands; otherwise each one gets nothing. There is a population of n agents that are randomly paired to play. Each agent has a memory in which he retains the decision taken by his opponents in previous games. The agent uses the information stored in his memory to demand the portion of the pie that maximizes his/her benefit (with probability 1-epsilon) and randomly (with probably epsilon), where epsilon represents the noise level in the system. What makes an agent choose among low, medium or high? There are two possible decision rules in this model: > FIRST DECISION RULE: DEMAND THE OPTION THAT MAXIMIZES THE EXPECTED BENEFIT An agent will check his memory to find how often each option has been chosen by his opponents. Then, the agent considers that the probability that his current opponent chooses L (low) – for example – is equal to the relative appearance of L in his memory. In the same way, he calculates how likely it is for the opponent to choose M and H. Once the agent knows this information, the agent estimates his benefit for the three possible options as follows: - The average benefit I get if I choose L is L multiplied by the probability that my opponent chooses L, M or H. - The average benefit I get if I choose M is M multiplied by the probability that my opponent chooses L or M. - The average benefit I get if I choose H is H multiplied by the probability that my opponent chooses H. > SECOND DECISION RULE: CHOOSE THE BEST REPLY AGAINST THE OPPONENTS' MOST FREQUENT DEMAND In this case, the agents will demande the pie portion that maximizes their benefits against the most likely option taken by their opponents in previous games (i.e. the mode of their memory). This is to say, an agent assumes that his opponent’s option will be the mode of the content of his memory. An agent will choose H if L is the most frequent decision taken by his opponents in the previous matches; If the most repeated value in his memory is M, the player will choose M. If previous matches show that H is the most frequent decision taken by his opponents, the agent will choose L. Notice that any of these ‘rational behaviours’ (first or second decision sule) take place with probability 1-epsilon. However, a random decision is taken with probability epsilon. The payoff matrix (i.e. the combination of rewards) can be chosen as well by changing the value assigned to low in the interface screen. The values used for low, medium and high in AEY's model are, respectively, 30, 50 and 70. Finally, you can choose three types of memory configuration: • STANDARD MEMORY: An m-size memory (m is defined in the interface screen). All the agents are initialized with m random values in their memories. • PROGRESSIVE MEMORY: The agents' memories are initialized with only one element (chosen at random). After the first iteration, each agents stores the decision taken by his opponent, increasing the memory size to two; after the second interation, each agent stores the decision taken by his opponent, generating a 3-size memory. This process is allowed to continue during a number of iterations, until the memory size reaches the value 'm'. At this point, the agents start deleting their oldest memory so that the memory size keps constant and equal to m. • ENDORSED MEMORY: In AEY’s model, all the elements in the agents’ memory have the same weight when they have to take a decision. This means that the oldest values in the memory (i.e. the decisions taken by the agents’ opponents several matches ago) have the same importance than the recent ones. When the 'endorsed memory' option is selected, the memory structure is modified so that the recent decisions have a higher weight than the older ones. The weight that we have assigned to each memory position follows an arithmetic progression: for instance, if the common difference of the arithmetic progression is set to 3, the oldest value in the memory will have a weight of 1, the second oldest value will have a weight of 4 (1+3), the third oldest value will have a weight of 7 (4+3), and so on. Supposing that the memory size is m, the most recent value in the memory will have a weight of [1 + (memory size – 1) · 3]. HOW TO USE IT ------------- • 1. Select the parameters to run the simulation. They are located below the simplex: - n: number of agents. - m: memory size. - number of iterations. - epsilon: noise level. If you want the agents to show a label with their id, turn on the switch 'label-on-agents'. If you want to stop the simulation when the system reaches an equitable equilibrium or a fractious state, turn on the switch 'stop-if-equilibrium'. Otherwise, the simulation keeps on running until the specified number of iterations is reached (this is useful to observe how the system leaves the equitable equilibrium or the fractious state when there is noise in the system -epsilon > 0). • 2. Select the payoff matrix by choosing a value for low (lowest demand). Notice that AEY's original model uses 30 as the lowest demand. • 3. Choose a decision rule. • 4. Select a memory configuration. • 5. Click setup to initialize the system with the selected parameters and then go to run the simulation. @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 airplane true 0 Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 arrow true 0 Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box false 0 Polygon -7500403 true true 150 285 285 225 285 75 150 135 Polygon -7500403 true true 150 135 15 75 150 15 285 75 Polygon -7500403 true true 15 75 15 225 150 285 150 135 Line -16777216 false 150 285 150 135 Line -16777216 false 150 135 15 75 Line -16777216 false 150 135 285 75 bug true 0 Circle -7500403 true true 96 182 108 Circle -7500403 true true 110 127 80 Circle -7500403 true true 110 75 80 Line -7500403 true 150 100 80 30 Line -7500403 true 150 100 220 30 butterfly true 0 Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 Circle -16777216 true false 135 90 30 Line -16777216 false 150 105 195 60 Line -16777216 false 150 105 105 60 car false 0 Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 Circle -16777216 true false 180 180 90 Circle -16777216 true false 30 180 90 Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 Circle -7500403 true true 47 195 58 Circle -7500403 true true 195 195 58 circle false 0 Circle -7500403 true true 0 0 300 circle 2 false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 cow false 0 Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 Polygon -7500403 true true 73 210 86 251 62 249 48 208 Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 cylinder false 0 Circle -7500403 true true 0 0 300 dot false 0 Circle -7500403 true true 90 90 120 face happy false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 face neutral false 0 Circle -7500403 true true 8 7 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Rectangle -16777216 true false 60 195 240 225 face sad false 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 fish false 0 Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 Circle -16777216 true false 215 106 30 flag false 0 Rectangle -7500403 true true 60 15 75 300 Polygon -7500403 true true 90 150 270 90 90 30 Line -7500403 true 75 135 90 135 Line -7500403 true 75 45 90 45 flower false 0 Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 Circle -7500403 true true 85 132 38 Circle -7500403 true true 130 147 38 Circle -7500403 true true 192 85 38 Circle -7500403 true true 85 40 38 Circle -7500403 true true 177 40 38 Circle -7500403 true true 177 132 38 Circle -7500403 true true 70 85 38 Circle -7500403 true true 130 25 38 Circle -7500403 true true 96 51 108 Circle -16777216 true false 113 68 74 Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 house false 0 Rectangle -7500403 true true 45 120 255 285 Rectangle -16777216 true false 120 210 180 285 Polygon -7500403 true true 15 120 150 15 285 120 Line -16777216 false 30 120 270 120 leaf false 0 Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 line true 0 Line -7500403 true 150 0 150 300 line half true 0 Line -7500403 true 150 0 150 150 pentagon false 0 Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 person false 0 Circle -7500403 true true 110 5 80 Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 Rectangle -7500403 true true 127 79 172 94 Polygon -7500403 true true 195 90 240 150 225 180 165 105 Polygon -7500403 true true 105 90 60 150 75 180 135 105 plant false 0 Rectangle -7500403 true true 135 90 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 square false 0 Rectangle -7500403 true true 30 30 270 270 square 2 false 0 Rectangle -7500403 true true 30 30 270 270 Rectangle -16777216 true false 60 60 240 240 star false 0 Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 target false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 Circle -7500403 true true 60 60 180 Circle -16777216 true false 90 90 120 Circle -7500403 true true 120 120 60 tree false 0 Circle -7500403 true true 118 3 94 Rectangle -6459832 true false 120 195 180 300 Circle -7500403 true true 65 21 108 Circle -7500403 true true 116 41 127 Circle -7500403 true true 45 90 120 Circle -7500403 true true 104 74 152 triangle false 0 Polygon -7500403 true true 150 30 15 255 285 255 triangle 2 false 0 Polygon -7500403 true true 150 30 15 255 285 255 Polygon -16777216 true false 151 99 225 223 75 224 truck false 0 Rectangle -7500403 true true 4 45 195 187 Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 Rectangle -1 true false 195 60 195 105 Polygon -16777216 true false 238 112 252 141 219 141 218 112 Circle -16777216 true false 234 174 42 Rectangle -7500403 true true 181 185 214 194 Circle -16777216 true false 144 174 42 Circle -16777216 true false 24 174 42 Circle -7500403 false true 24 174 42 Circle -7500403 false true 144 174 42 Circle -7500403 false true 234 174 42 turtle true 0 Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 wheel false 0 Circle -7500403 true true 3 3 294 Circle -16777216 true false 30 30 240 Line -7500403 true 150 285 150 15 Line -7500403 true 15 150 285 150 Circle -7500403 true true 120 120 60 Line -7500403 true 216 40 79 269 Line -7500403 true 40 84 269 221 Line -7500403 true 40 216 269 79 Line -7500403 true 84 40 221 269 x false 0 Polygon -7500403 true true 270 75 225 30 30 225 75 270 Polygon -7500403 true true 30 75 75 30 270 225 225 270 @#$#@#$#@ NetLogo 4.0.4 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ setup go equitable-equilibrium-at-least-once? fractious-state-at-least-once? elapsed-iterations @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@