You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Finish the spatial prisoner's dilemma model in TerraME. It needs to deal with empty cells. The first version is shown below.
--[[Games on GridsMartin A. Nowak and Karl SigmundSpatial evolutionary game theory, which was first used to shed light on the emergence ofcooperation, has grown rapidly during the past five years and has proved useful in otherbiological and economic contexts. A wealth of computer simulations of artificial populations now exist showingthat cooperation can be stably sustained in societies of simple automata.The introduction of spatial structure has shown that cooperation becomeseven more likely if interactions are restricted to neighbors. The venerablerule of cooperating with neighbors is certainly not new. But placed alongsideother spatial models, it offers wide perspectives for the emergence andstability of cooperative societies. In particular, it shows that even if the interactionbetween two individuals is not repeated, cooperation can be sustainedin the long run.Spatial Prisioner's DillemaUnder what conditions will there be a spatial coexistence of cooperators and defectors, andWhen will we observe the extinction of either cooperators or defectors?What does the variety and the size of the spatial domains depend on?Will the dynamics always lead to stationary patterns, or will there be also non-stationarypatterns in the long run?How does the dynamics changes if a larger local neighborhood is considered in the updaterule (i.e. if the second nearest neighbors are included, too)?The following example uses the following rules:Cooperators can survive by forming clusters and thereby outweighing losses against defectors.There is a balance between payoff and survival ratesThe following example uses the following rules:1. Each player occupies a single cell2. Players compete against all 8 neighbors in an 3 x 3 cell 3. The initial configuration has one defector in the center4. Updates are synchronous 5. Each cell copies the most successful strategy in its neighborhoodReferences Nowak MA & May RM (1992). Evolutionary games and spatial chaos. Nature 359:826?~@~S829Schweitzer et al. (2002): "Evolution of Cooperation in a Spatial Prisoner?~@~Ys Dilemma" Advances in Complex Systems, vol. 5, no. 2-3, pp. 269-299Hauert, Ch. & Doebeli, M. (2004) Spatial structure often inhibits the evolution of cooperation in the spatial Snowdrift game. Nature (2004) 428 643-646.]]----[[1. Payoffs (T)emptation, (R)eward, (P)unishment, and (S)ucker's payoff T > R > P > S -- prisioner's dillema T > R > S > P -- hawk-dove game-- Nowak and May models 3 x 3 ("moore") neighborhood, agent is a neighbor of itself Prisioner's dillema with R = 1.00 and S = 0.00-- Schweitzer models 2x2 ("vonneumann") neighborhood, agent is not a neighbor of itself Prisioner's dillema with R = 3.00 and S = 0.002. Regions on Novak May models 1.75 < T < 1.8 -- cooperators prevail over a network of defectors 1.80 < T < 2.0 -- spatial chaos if T = 1.85, put one defector in the center cell - spatial chaos 3. Regions on Schweitzer models-- Consider R = 3 and S = 0 -- Vary 3 < T < 6 and 0 < P < 3-- T > R > P > S (prisioners dillema)-- Region A Coexistence with a majority of cooperators - -- 3 < T < (4 ?~H~R P/3) if 0.00 < P < 0.75 -- 3 < T < (6 ?~H~R 3P) if 0.75 < P < 1.0-- examples: (T = 3.5, P = 0.5 ) and (T = 3.8, P = 0.6)-- Region B - Coexistence with a minority of cooperators - spatial chaos-- 4 ?~H~R P/3 < T < 4.5?~H~RP if 0.0 < P < 0.75-- examples: (T = 3.9, P = 0.5) and (T = 4.2, P = 0.2)-- -- limit btw A and B - T = 3.8333 and P = 0.5 -- Region C Coexistence with cooperators in small clusters (region C)---- 4 - P/3 < T < 9 - 3P iff 1.5 < P < 1.875-- 4 - P/3 < T < 6 - P iff 0.75 < P < 1.5-- 4.5 - P < T < 6 - P iff 0.0 < P < 0.75-- examples: (T = 4.5, P = 1.0) and (T = 5.6, P = 0.2)-- (T=4.0, P =0.5) is the border between regions B and C.]]--payoffs= {
nowak_may= {
fractal= {temptation=1.85, reward=1.00, punishment=0.01, sucker=0.00},
coop1= {temptation=1.45, reward=1.00, punishment=0.01, sucker=0.00},
coop2= {temptation=1.76, reward=1.00, punishment=0.01, sucker=0.00},
chaos= {temptation=1.90, reward=1.00, punishment=0.01, sucker=0.00}
},
schweitzer= {
regA= {temptation=3.50, reward=3.00, punishment=0.50, sucker=0.00},
regB= {temptation=3.90, reward=3.00, punishment=0.50, sucker=0.00},
regC= {temptation=4.50, reward=3.00, punishment=1.00, sucker=0.00},
borderAB= {temptation=3.83, reward=3.00, punishment=0.50, sucker=0.00},
borderBC= {temptation=4.00, reward=3.00, punishment=0.50, sucker=0.00}
}
}
percent_cooperators= {
nowak_may= {fractal=1.00, coop1=0.90, coop2=0.90, chaos=0.90},
schweitzer= {regA=0.50, regB=0.75, regC=0.90, borderAB=0.50, borderBC=0.50}
}
localprobCooperate=0-- create a table with the available strategies in order to-- allow the user to select one from the graphical interfacestrategies= {}
idxstrategies= {}
forEachOrderedElement(percent_cooperators, function(idx, mtable)
forEachOrderedElement(mtable, function(midx)
localvalue=idx.."_"..midxtable.insert(strategies, value)
idxstrategies[value] = {author=idx, case=midx}
end)
end)
-- neighbor configurationneigh= {
nowak_may= {strategy="moore", self=true, wrap=true},
schweitzer= {strategy="vonneumann", self=false, wrap=true}
}
-- result of a game between two agentslocalgame= {}
game.Cooperate= {}
game.Defect= {}
-- state of an agent comparing previous and current movestate= {}
state.Cooperate= {}
state.Defect= {}
state.Cooperate.Cooperate="Cooperate"state.Cooperate.Defect="CooperateToDefect"state.Defect.Cooperate="DefectToCooperate"state.Defect.Defect="Defect"localfunctionplayGame(agent1, agent2)
returngame[agent1.strategy][agent2.strategy]
endlocalagent=Agent{
playWithNeighbors=function(agent)
localcell=agent:getCell()
agent.payoff=0forEachNeighbor(cell, function(cell, neigh)
agent.payoff=agent.payoff+playGame(agent, neigh:getAgent())
end)
end,
findBestStrategy=function(agent)
localcell=agent:getCell()
agent.beststrategy=agent.strategylocalbestpayoff=agent.payoffforEachNeighbor(cell, function(cell, neigh)
other=neigh:getAgent()
ifother.payoff>bestpayoffthenbestpayoff=other.payoffagent.beststrategy=other.strategyendend)
end,
changeStrategy=function(agent)
agent.state=state[agent.strategy][agent.beststrategy]
agent.strategy=agent.beststrategyend,
init=function(self)
ifmath.random() <=probCooperatethenself.strategy="Cooperate"elseself.strategy="Defect"endself.state=self.strategyself.beststrategy=self.strategyend
}
functiondefectorCentre(model)
-- find the central celllocalmid= (model.dim-1) /2localcell=model.cells:get(mid, mid)
-- get the agent at the central celllocalag=cell:getAgent()
ag.strategy="Defect"ag.state="Defect"endSPD=Model{
dim=Choice{min=10, default=41},
agents=Choice{min=100, default=1681},
finalTime=Choice{min=50, default=100},
strategy=Choice(strategies),
init=function(model)
verify(model.agents<=model.dim*model.dim, "There should be enough space for all agents.")
localauthor=idxstrategies[model.strategy].authorlocalcase=idxstrategies[model.strategy].casegame.Cooperate.Cooperate=payoffs[author][case].rewardgame.Cooperate.Defect=payoffs[author][case].suckergame.Defect.Cooperate=payoffs[author][case].temptationgame.Defect.Defect=payoffs[author][case].punishmentprobCooperate=percent_cooperators[author][case]
model.cell=Cell{
color=function(cell)
localagent=cell:getAgent()
ifagentthenreturnagent.stateelsereturn"Empty"endend
}
model.cells=CellularSpace{
xdim=model.dim,
ydim=model.dim,
instance=model.cell
}
model.cells:createNeighborhood(neigh[author])
model.society=Society{
quantity=model.agents,
instance=agent,
percentCooperators=function(self)
localnum_coop=0forEachAgent(self, function(agent)
ifagent.strategy=="Cooperate" thennum_coop=num_coop+1endend)
return (100*num_coop) /#selfend
}
model.env=Environment{model.cells, model.society}
model.env:createPlacement{
strategy="uniform"
}
ifauthor=="nowak_may" andcase=="fractal" thendefectorCentre(model)
endmodel.timer=Timer{
Event{action=function()
model.society:playWithNeighbors()
model.society:findBestStrategy()
model.society:changeStrategy()
model.society:notify()
model.cells:notify()
end}
}
Map{
target=model.cells,
select="color",
color="RdBu",
value= {"Defect", "CooperateToDefect", "Empty", "DefectToCooperate", "Cooperate"}
}
Chart{
target=model.society,
select="percentCooperators"
}
model.society:notify()
end
}
SPD:configure()
The text was updated successfully, but these errors were encountered:
Finish the spatial prisoner's dilemma model in TerraME. It needs to deal with empty cells. The first version is shown below.
The text was updated successfully, but these errors were encountered: