Create spatial tournaments¶
A spatial tournament is defined on a graph where the nodes correspond to players and edges define whether or not a given player pair will have a match.
The initial work on spatial tournaments was done by Nowak and May in a 1992 paper: [Nowak1992].
Additionally, Szabó and Fáth in their 2007 paper [Szabo2007] consider a variety of graphs, such as lattices, small world, scale-free graphs and evolving networks.
Let’s create a tournament where Cooperator
and Defector
do not
play each other and neither do TitForTat
and Grudger
:
Note that the edges have to be given as a list of tuples of player indices:
>>> import axelrod as axl
>>> players = [axl.Cooperator(), axl.Defector(),
... axl.TitForTat(), axl.Grudger()]
>>> edges = [(0, 2), (0, 3), (1, 2), (1, 3)]
To create a spatial tournament you pass the edges
to the
Tournament
class:
>>> spatial_tournament = axl.Tournament(players, edges=edges)
>>> results = spatial_tournament.play()
We can plot the results:
>>> plot = axl.Plot(results)
>>> p = plot.boxplot()
>>> p.show()
We can, like any other tournament, obtain the ranks for our players:
>>> results.ranked_names
['Cooperator', 'Tit For Tat', 'Grudger', 'Defector']
Let’s run a small tournament of 2 turns
and 2 repetitions
and obtain the interactions:
>>> spatial_tournament = axl.Tournament(players ,turns=2, repetitions=2, edges=edges)
>>> results = spatial_tournament.play()
>>> results.payoffs
[[[], [], [3.0, 3.0], [3.0, 3.0]], [[], [], [3.0, 3.0], [3.0, 3.0]], [[3.0, 3.0], [0.5, 0.5], [], []], [[3.0, 3.0], [0.5, 0.5], [], []]]
As anticipated not all players interact with each other.
It is also possible to create a probabilistic ending spatial tournament:
>>> prob_end_spatial_tournament = axl.Tournament(players, edges=edges, prob_end=.1, repetitions=1, seed=10)
>>> prob_end_results = prob_end_spatial_tournament.play()
We see that the match lengths are no longer all equal:
>>> prob_end_results.match_lengths
[[[0, 0, 20.0, 1.0], [0, 0, 46.0, 13.0], [20.0, 46.0, 0, 0], [1.0, 13.0, 0, 0]]]