From 7a5b7eae6e2eafd3a73ad9736e813c46d9920500 Mon Sep 17 00:00:00 2001 From: timofej Date: Thu, 24 Aug 2023 21:47:56 +0200 Subject: [PATCH] Add init state argument --- neuropercolation/automaton.py | 9 ++++++--- neuropercolation/display.py | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/neuropercolation/automaton.py b/neuropercolation/automaton.py index 2b8f36d..ba2cbcd 100644 --- a/neuropercolation/automaton.py +++ b/neuropercolation/automaton.py @@ -37,11 +37,13 @@ class CellularAutomatonCreator(abc.ABC): def __init__(self, dimension, neighborhood: Neighborhood, + init, *args, **kwargs): super().__init__(*args, **kwargs) self._dimension = dimension self._neighborhood = neighborhood - + self.init = init + self._current_state = {} self._next_state = {} self.__make_cellular_automaton_state() @@ -229,15 +231,16 @@ class Neuropercolation(CellularAutomatonCreator, abc.ABC): class NeuropercolationCoupled(CellularAutomatonCreator, abc.ABC): - def __init__(self, dim, eps, coupling=[], *args, **kwargs): + def __init__(self, dim, eps, coupling=[], init=[[0,0],[0,0]], *args, **kwargs): super().__init__(dimension=[dim, dim, 2, 2], + init=init, neighborhood=VonNeumannNeighborhood(EdgeRule.FIRST_AND_LAST_CELL_OF_DIMENSION_ARE_NEIGHBORS)) self._evolution_step = 0 self.epsilon = eps self.coupling = coupling def init_cell_state(self, coord): # pylint: disable=no-self-use - return DEAD + return [self.init[coord[3]][coord[2]]] def get_cells(self): return self._current_state diff --git a/neuropercolation/display.py b/neuropercolation/display.py index 253ac9f..0dfac1a 100644 --- a/neuropercolation/display.py +++ b/neuropercolation/display.py @@ -70,6 +70,7 @@ class Simulate1Layer: def __init__(self, dim, eps, + init=0, steps=100, draw='pygame', res=4, @@ -88,7 +89,7 @@ class Simulate1Layer: :param state_to_color_cb: A callback to define the draw color of CA states (default: red for states != 0) """ super().__init__(*args, **kwargs) - self._cellular_automaton = Neurolattice(dim,eps) + self._cellular_automaton = Neurolattice(dim,eps,init=init) self.__active = True self.__cell_size = [res,res] self.__dimension = dim @@ -239,6 +240,7 @@ class Simulate2Layers: def __init__(self, dim, eps, + init=[0,0], steps=100, draw='pygame', res=4, @@ -257,7 +259,7 @@ class Simulate2Layers: :param state_to_color_cb: A callback to define the draw color of CA states (default: red for states != 0) """ super().__init__(*args, **kwargs) - self._cellular_automaton = Neuropercolation(dim,eps) + self._cellular_automaton = Neuropercolation(dim,eps,init=init) self.__active = True self.__cell_size = [res,res] self.__dimension = dim @@ -422,6 +424,7 @@ class Simulate4Layers: dim, eps, coupling=[], + init=[[0,0],[0,0]], steps=100, draw='pygame', res=4, @@ -440,7 +443,7 @@ class Simulate4Layers: :param state_to_color_cb: A callback to define the draw color of CA states (default: red for states != 0) """ super().__init__(*args, **kwargs) - self._cellular_automaton = NeuropercolationCoupled(dim,eps,coupling) + self._cellular_automaton = NeuropercolationCoupled(dim,eps,coupling,init) self.__active = True self.__cell_size = [res,res] self.__dimension = dim