Class CADirector
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.actor.Director
-
- ptolemy.domains.ca.kernel.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 theCAViewer
actor.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Zach Ezzell, Contributor: Christopher Brooks
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (cxh)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected Parameter
delay
The delay time between iterations in seconds.protected Parameter
initialMatrix
The initial matrix parameter.protected Parameter
iterations
The iterations parameter.protected Parameter
random
True if the matrix will be populated with random data.protected Parameter
size
An integer representing the size of the square matrix.-
Fields inherited from class ptolemy.actor.Director
_actorsFinishedExecution, _aspectForActor, _aspectsPresent, _defaultMicrostep, _executionAspects, _finishRequested, _initializables, _nextScheduleTime, _stopRequested, _tokenSentToCommunicationAspect, _zeroTime, localClock, startTime, stopTime
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description CADirector(CompositeEntity container, java.lang.String name)
Construct a new CADirector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_initParameters()
Initialize the parameters.protected boolean
_iterate()
Enforce the user-defined delay, call _showMatrix(), and check if the iteration limit has been reached.protected void
_setInitMatrix()
Set the initial matrix for the CAViewer (the actor that visualizes the grid).protected void
_showMatrix()
Set the current matrix for any MatrixViewer, Const with a DoubleMatrixToken, or CAViewer actors.java.lang.Object
clone(Workspace workspace)
Clone the object into the specified workspace.void
fire()
Iterate the relevant actors on the canvas for a single grid location.boolean
postfire()
Update the current x and yLocations of the grid.void
preinitialize()
This method performs the initialization step.-
Methods inherited from class ptolemy.actor.Director
_actorFinished, _consultTimeRegulators, _description, _isEmbedded, _isTopLevel, _schedule, _transferInputs, _transferOutputs, addInitializable, attributeChanged, createSchedule, defaultDependency, delayDependency, elapsedTimeSinceStart, finish, fireAt, fireAt, fireAt, fireAtCurrentTime, fireContainerAt, fireContainerAt, getCausalityInterface, getCurrentTime, getDeadline, getEnvironmentTime, getExecutionAspect, getGlobalTime, getModelNextIterationTime, getModelStartTime, getModelStopTime, getModelTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, implementsStrictActorSemantics, initialize, initialize, invalidateResolvedTypes, invalidateSchedule, isEmbedded, isFireFunctional, isStopRequested, isStrict, iterate, mutexLockObject, newReceiver, notifyTokenSentToCommunicationAspect, prefire, preinitialize, removeInitializable, requestInitialization, resume, resumeActor, scheduleContainedActors, setContainer, setCurrentTime, setEmbedded, setModelTime, setTimeResolution, stop, stopFire, suggestedModalModelDirectors, supportMultirateFiring, suspend, terminate, transferInputs, transferOutputs, transferOutputs, wrapup
-
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
-
-
-
-
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.
-
-
Constructor Detail
-
CADirector
public CADirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct a new CADirector.- Parameters:
container
- The container.name
- The name of the director.- Throws:
IllegalActionException
- If the name has a period in it, or the director is not compatible with the specified container.NameDuplicationException
- If the container already contains an entity with the specified name.
-
-
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 classDirector
- 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 interfaceExecutable
- Overrides:
fire
in classDirector
- Throws:
IllegalActionException
- If an actor is unable to iterate().
-
preinitialize
public void preinitialize() throws IllegalActionException
This method performs the initialization step. This includes creating the matrix according to the user-defined parameters.- Specified by:
preinitialize
in interfaceInitializable
- Overrides:
preinitialize
in classDirector
- Throws:
IllegalActionException
- If exception occurs in base class.
-
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 interfaceExecutable
- Overrides:
postfire
in classDirector
- Returns:
- True to continue execution, and false otherwise.
- Throws:
IllegalActionException
- If an exception occurs in the base class.
-
_initParameters
protected void _initParameters() throws IllegalActionException, NameDuplicationException
Initialize the parameters.- Throws:
IllegalActionException
- If the parameters names are invalid.NameDuplicationException
- If parameters already exist with a specified name.
-
_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
-
-