Setting up neighborhoods
parent
fbc9cdc435
commit
cfb43944d3
|
@ -8,6 +8,17 @@ import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
class Bit:
|
||||||
|
"""
|
||||||
|
Represents a "bit" in a bitplane.
|
||||||
|
|
||||||
|
Note we keep track of the index for vectorization purposes. By maintaining each index
|
||||||
|
and batch updating via the given index, we can much more efficiently update the entire
|
||||||
|
bitplane.
|
||||||
|
"""
|
||||||
|
def __init__(self, value, *index):
|
||||||
|
self.value = value
|
||||||
|
self.index = index
|
||||||
|
|
||||||
|
|
||||||
class BitPlane:
|
class BitPlane:
|
||||||
|
@ -27,8 +38,24 @@ class BitPlane:
|
||||||
masters can exist in separate CAMs that can interact with one another.
|
masters can exist in separate CAMs that can interact with one another.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *dimensions):
|
@staticmethod
|
||||||
|
@np.vectorize
|
||||||
|
def _populate(*indices):
|
||||||
|
"""
|
||||||
|
The following joins indices in N-dimensions together.
|
||||||
|
|
||||||
|
This information is stored in a bit (with initial value False) in order for batch processing
|
||||||
|
to be performed when actually updating values and computing whether a bit is on or off. For
|
||||||
|
example, if exploring a 4D array, we want to be able to know which bits we need to check the
|
||||||
|
status of, but this is relative to the current bit, whose position we do not know unless that
|
||||||
|
information is stored with the current bit.
|
||||||
|
"""
|
||||||
|
return Bit(False, *indices)
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, dimen):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.grid = np.zeros(dimensions)
|
self.grid = BitPlane._populate(*np.indices(dimen))
|
||||||
|
|
||||||
|
|
19
src/cam.py
19
src/cam.py
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from bitplane import Bitplane
|
||||||
|
|
||||||
|
|
||||||
class CAM:
|
class CAM:
|
||||||
|
@ -14,8 +14,23 @@ class CAM:
|
||||||
all methods needed (i.e. supported) to interact/configure the cellular automata as desired.
|
all methods needed (i.e. supported) to interact/configure the cellular automata as desired.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, bps=1, dimen=(100,100)):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
self._dimen = dimen
|
||||||
|
self._bitplanes = [BitPlane(dimen) for i in bps]
|
||||||
|
self._master = self._bitplanes[0].grid if bps > 0 else None
|
||||||
|
|
||||||
|
|
||||||
|
def tick(self, ruleset, neighborhood):
|
||||||
|
"""
|
||||||
|
The tick function should be called whenever we want to change the current status of the grid.
|
||||||
|
|
||||||
|
Every time the tick is called, the ruleset is applied to each cell and the next configuration
|
||||||
|
is placed into the master grid. Depending on the timing specifications set by the user, this
|
||||||
|
may also change secondary bitplanes (the master is always updated on each tick).
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,6 @@ class Cells(enum.Enum):
|
||||||
FORWARD = 1 << 10
|
FORWARD = 1 << 10
|
||||||
BACKWARD = 1 << 11
|
BACKWARD = 1 << 11
|
||||||
|
|
||||||
# Shortcuts
|
|
||||||
NEUMANN = NORTH | EAST | SOUTH | WEST
|
|
||||||
MOORE = NORTH | NORTHEAST | EAST | SOUTHEAST | SOUTH | SOUTHWEST | WEST | NORTHWEST | NORTH
|
|
||||||
|
|
||||||
|
|
||||||
class Neighborhood:
|
class Neighborhood:
|
||||||
"""
|
"""
|
||||||
|
@ -52,5 +48,7 @@ class Neighborhood:
|
||||||
This allows indexing at levels beyond 3D, which the Cells enumeration does not allow, though visualization
|
This allows indexing at levels beyond 3D, which the Cells enumeration does not allow, though visualization
|
||||||
at this point isn't possible.
|
at this point isn't possible.
|
||||||
"""
|
"""
|
||||||
pass
|
def __init__(self, grid):
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue