In [1]:
%matplotlib inline

In [2]:
from __future__ import division
import numpy as np

In [3]:
from localint import LocalInteraction

In [4]:
def circle_network(N):
    adj_matrix = np.zeros((N, N))
    adj_matrix[0, [1, N-1]] = 1
    for i in range(1, N-1):
        adj_matrix[i, [i-1, i+1]] = 1
    adj_matrix[N-1, [0, N-2]] = 1
    return adj_matrix

In [5]:
coord_game = [[4, 0], [2, 3]]

In [6]:
N = 10
li = LocalInteraction(coord_game, circle_network(N))

In [7]:
init_actions = np.zeros(N, dtype=int)
init_actions[[0, 1]] = 1

In [8]:
import networkx as nx
import matplotlib.pyplot as plt

G = nx.Graph(li.adj_matrix)
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(), init_actions):
    labels[i] = r'${0}$'.format(action)
nx.draw_networkx_labels(G, pos, labels)

plt.axis('off')
plt.show()



In [9]:
li.set_init_actions(init_actions)

In [10]:
li.play()
print li.current_actions


[1 1 1 0 0 0 0 0 0 1]

In [11]:
li.play(player_ind=3)
print li.current_actions


[1 1 1 1 0 0 0 0 0 1]

In [12]:
li.play(player_ind=[4, 5, 8])
print li.current_actions


[1 1 1 1 1 0 0 0 1 1]

In [13]:
ts_length = 5
for action_configuration in li.simulate_iter(ts_length):
    print action_configuration


[1 0 1 0 1 1 0 1 1 0]
[0 1 0 1 1 1 1 1 1 1]
[1 0 1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1 1 1]
[1 1 1 1 1 1 1 1 1 1]

In [14]:
N = 100
li = LocalInteraction(coord_game, circle_network(N))

In [15]:
init_actions = np.zeros(N, dtype=int)
init_actions[[0, 1]] = 1

In [16]:
ts_length = 50
x = [sum(actions) for actions in li.simulate_iter(ts_length, init_actions=init_actions)]

In [17]:
print x


[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]

In [18]:
ts_length = 5000
action_configuration_path = \
    li.simulate(ts_length, init_actions=init_actions, revision='sequential')

In [19]:
print action_configuration_path[-1]


[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]

In [20]:
ts_length = 5000
action_configuration_path = \
    li.simulate(ts_length, init_actions=init_actions)
print action_configuration_path[-1]


[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]

In [21]:
ts_length = 5000
for actions in li.simulate_iter(ts_length, init_actions=init_actions):
    pass
print actions


[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]

In [ ]: