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 :

../../_images/spatial.png

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 call the SpatialTournamnent class:

>>> spatial_tournament = axl.SpatialTournament(players, edges=edges)
>>> results = spatial_tournament.play(keep_interactions=True)

We can plot the results:

>>> plot = axl.Plot(results)
>>> p = plot.boxplot()
>>> p.show()
../../_images/spatial_results.png

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 5 repetitions and obtain the interactions:

>>> spatial_tournament = axl.SpatialTournament(players ,turns=2, repetitions=2, edges=edges)
>>> results = spatial_tournament.play(keep_interactions=True)
>>> for index_pair, interaction in sorted(results.interactions.items()):
...     player1 = spatial_tournament.players[index_pair[0]]
...     player2 = spatial_tournament.players[index_pair[1]]
...     print('%s vs %s: %s' % (player1, player2, interaction))
Cooperator vs Tit For Tat: [[('C', 'C'), ('C', 'C')], [('C', 'C'), ('C', 'C')]]
Cooperator vs Grudger: [[('C', 'C'), ('C', 'C')], [('C', 'C'), ('C', 'C')]]
Defector vs Tit For Tat: [[('D', 'C'), ('D', 'D')], [('D', 'C'), ('D', 'D')]]
Defector vs Grudger: [[('D', 'C'), ('D', 'D')], [('D', 'C'), ('D', 'D')]]

As anticipated Cooperator does not interact with Defector neither TitForTat with Grudger.

It is also possible to create a probabilistic ending spatial tournament with the ProbEndSpatialTournament class:

>>> prob_end_spatial_tournament = axl.ProbEndSpatialTournament(players, edges=edges, prob_end=.1, repetitions=1)
>>> prob_end_results = prob_end_spatial_tournament.play(keep_interactions=True)

We see that the match lengths are no longer all equal:

>>> axl.seed(0)
>>> lengths = []
>>> for interaction in prob_end_results.interactions.values():
...     lengths.append(len(interaction[0]))
>>> min(lengths) != max(lengths)
True