Class CADirector

  • All Implemented Interfaces:
    java.lang.Cloneable, Executable, Initializable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class CADirector
    extends Director
    A Cellular Automata director.

    The CADirector is to be used in conjunction with the CA2DConvolution Actor. To use this director, it is highly recommended to start with one of the examples. The director contains a matrix. At each iteration, every entry in the matrix is updated according to the CA2DConvolution actor. This functionality can be useful when simulating cellular automata or other grid-based phenomena.

    This director assumes the following parameters are added to the canvas:

    xLocation: the xLocation in the grid (the 2D matrix) that is currently being updated.

    yLocation: the yLocation in the grid (the 2D matrix) that is currently being updated.

    currentValue: the currentValue in the grid at location (xLocation, yLocation).

    newValue: the updated value in the grid at location (xLocation, yLocation).

    neighbor1: the value of the top-left neighbor of grid location (xLocation, yLocation).

    neighbor2: the value of the top neighbor of grid location (xLocation, yLocation).

    neighbor3: the value of the top-right neighbor of grid location (xLocation, yLocation).

    neighbor4: the value of the left neighbor of grid location (xLocation, yLocation).

    neighbor5: the value of the right neighbor of grid location (xLocation, yLocation).

    neighbor6: the value of the bottom-left neighbor of grid location (xLocation, yLocation).

    neighbor7: the value of the bottom neighbor of grid location (xLocation, yLocation).

    neighbor8: the value of the bottom-right neighbor of grid location (xLocation, yLocation).

    The director sets the variables for each entry in the matrix every iteration. The number of high-level iterations (that scan the entire matrix once) can be set as a parameter in the director. Other parameters include: delay, the time delay between iterations; randomize matrix, which determines if the matrix will be populated randomly; matrix size, the dimension of the square matrix; and initial values, the initial values of the matrix with all values not explicitly defined set to 0.0.

    See also the documentation on the CA2DConvolution actor and the CAViewer actor.

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Zach Ezzell, Contributor: Christopher Brooks
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Red (cxh)
    • Field Detail

      • delay

        protected Parameter delay
        The delay time between iterations in seconds. The initial default value is a double with value 0.5, indicating a delay of half a second between iterations.
      • initialMatrix

        protected Parameter initialMatrix
        The initial matrix parameter.
      • iterations

        protected Parameter iterations
        The iterations parameter.
      • random

        protected Parameter random
        True if the matrix will be populated with random data. The default value is false, indicating that all values in the matrix will be initially set to 0.0.
      • size

        protected Parameter size
        An integer representing the size of the square matrix. The initial value is 10, indicating a 10 x 10 matrix.
    • Method Detail

      • clone

        public java.lang.Object clone​(Workspace workspace)
                               throws java.lang.CloneNotSupportedException
        Clone the object into the specified workspace. The new object is not added to the directory of that workspace (you must do this yourself if you want it there). The result is an object with no container.
        Overrides:
        clone in class Director
        Parameters:
        workspace - The workspace for the cloned object.
        Returns:
        The new object.
        Throws:
        java.lang.CloneNotSupportedException - Not thrown in this base class
        See Also:
        NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)
      • fire

        public void fire()
                  throws IllegalActionException
        Iterate the relevant actors on the canvas for a single grid location.

        This method is invoked once per location in the matrix per iteration (i.e., Matrix size x iteration count).

        This method sets the appropriate values on the canvas and iterates the appropriate actors (e.g., the CA2DConvolution actor) and updates grid values accordingly.

        Specified by:
        fire in interface Executable
        Overrides:
        fire in class Director
        Throws:
        IllegalActionException - If an actor is unable to iterate().
      • postfire

        public boolean postfire()
                         throws IllegalActionException
        Update the current x and yLocations of the grid. It also updates the iteration count when necessary. If all matrix _cells have been updated for this iteration, then _iterate() is called.
        Specified by:
        postfire in interface Executable
        Overrides:
        postfire in class Director
        Returns:
        True to continue execution, and false otherwise.
        Throws:
        IllegalActionException - If an exception occurs in the base class.
      • _iterate

        protected boolean _iterate()
                            throws IllegalActionException
        Enforce the user-defined delay, call _showMatrix(), and check if the iteration limit has been reached. This method is called every time the entire matrix has been updated.
        Returns:
        boolean false is the iteration limit has been reached and execution should stop, true otherwise.
        Throws:
        IllegalActionException - If the matrix cannot be shown.
      • _setInitMatrix

        protected void _setInitMatrix()
        Set the initial matrix for the CAViewer (the actor that visualizes the grid).
      • _showMatrix

        protected void _showMatrix()
                            throws IllegalActionException
        Set the current matrix for any MatrixViewer, Const with a DoubleMatrixToken, or CAViewer actors.
        Throws:
        IllegalActionException - If thrown while reading a token or iterating the actors