In [1]:
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
from __future__ import division
from localint import LocalInteraction
%matplotlib inline
In [2]:
def drawg(li, pos=None):
G = nx.Graph(li.adj_matrix)
if pos is None:
pos=nx.circular_layout(G)
nx.draw_networkx_nodes(G, pos, nodelist=G.nodes(), node_size=500, node_color='w')
nx.draw_networkx_edges(G, pos, arrows=True)
labels={}
for i, action in zip(G.nodes(), li.current_actions):
labels[i] = r'${0}$'.format(action)
nx.draw_networkx_labels(G, pos, labels)
plt.axis('off')
plt.show()
In [3]:
cost2 = 3
payoff_matrix2 = np.asarray([[11, 11, 0], [11-cost2, 11-cost2, 10-cost2], [3, 10, 10]])
In [4]:
G5 = nx.wheel_graph(8)
nx.draw(G5)
plt.show()
In [5]:
li5 = LocalInteraction(payoff_matrix2, nx.adjacency_matrix(G5))
li5.set_init_actions([0,2,2,0,0,0,0,0])
drawg(li5)
In [6]:
for i in range(500):
outcome = li5.simulate(ts_length=10000,epsilon=0, init_actions=[0,2,2,0,0,0,0,0], revision='sequential')[-1]
if all(outcome == 2):
break
print i
In [7]:
for i in range(500):
outcome = li5.simulate(ts_length=10000,epsilon=0, init_actions=[0,2,2,2,0,0,0,0], revision='sequential')[-1]
if all(outcome == 2):
break
print i
In [ ]: