Esempio n. 1
0
import netomaton as ntm

if __name__ == '__main__':
    adjacency_matrix = ntm.network.cellular_automaton2d(
        rows=60, cols=60, r=1, neighbourhood='von Neumann')
    initial_conditions = ntm.init_simple2d(60, 60)
    activities, _ = ntm.evolve(
        initial_conditions,
        adjacency_matrix,
        timesteps=30,
        activity_rule=lambda ctx: ntm.rules.totalistic_ca(ctx, k=2, rule=26))
    # the evolution of a 2D cellular automaton can be animated
    ntm.animate(activities, shape=(60, 60), interval=150)

    adjacency_matrix = ntm.network.cellular_automaton(n=200)
    initial_conditions = [0] * 100 + [1] + [0] * 99
    activities, _ = ntm.evolve(
        initial_conditions,
        adjacency_matrix,
        timesteps=100,
        activity_rule=lambda ctx: ntm.rules.nks_ca_rule(ctx, 30))
    # the evolution of a 1D cellular automaton can be animated
    ntm.animate(activities, shape=(200, ))

    adjacency_matrix = ntm.network.cellular_automaton(n=225)
    initial_conditions = [0] * 112 + [1] + [0] * 112
    activities, _ = ntm.evolve(
        initial_conditions,
        adjacency_matrix,
        timesteps=100,
        activity_rule=lambda ctx: ntm.rules.nks_ca_rule(ctx, 30))
Esempio n. 2
0
 def test_init_simple2d_2x2(self):
     arr = ntm.init_simple2d(rows=2, cols=2)
     self.assertEqual(len(arr), 4)
     self.assertEqual(arr, [0, 0, 0, 1])
Esempio n. 3
0
 def test_init_simple2d_2x3(self):
     arr = ntm.init_simple2d(rows=2, cols=3)
     self.assertEqual(len(arr), 6)
     self.assertEqual(arr, [0, 0, 0, 0, 1, 0])
Esempio n. 4
0
 def test_init_simple2d_1x1_val2(self):
     arr = ntm.init_simple2d(rows=1, cols=1, val=2)
     self.assertEqual(len(arr), 1)
     self.assertEqual(arr[0], 2)