Package ptolemy.actor.lib
Class PublisherNonStrictTest
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity<T>
-
- ptolemy.actor.AtomicActor<TypedIOPort>
-
- ptolemy.actor.TypedAtomicActor
-
- ptolemy.actor.lib.Publisher
-
- ptolemy.actor.lib.PublisherNonStrictTest
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
PublisherTest
public class PublisherNonStrictTest extends Publisher
This actor publishes input tokens on a named channel and compares the inputs against the value specified by the correctValues parameter.This actor combines the
Publisher
actor and theNonStrictTest
actor. Thus, it has quite a bit of duplicated code from the NonStrictTest actor.Note that in the superclass (Publisher), the input is a multiport, whereas in this class it is a regular non-multiport. To use a multiport input, use
PublisherTest
- Since:
- Ptolemy II 6.1
- Version:
- $Id$
- Author:
- Christopher Brooks, based on Test, which has Edward A. Lee and Jim Armstrong as authors
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (cxh)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_firedOnce
Set to true if fire() is called once.protected boolean
_initialized
Set to true when initialized() is called.protected int
_iteration
Count of iterations.protected int
_numberOfInputTokensSeen
Number of input tokens seen by this actor in the fire method.protected double
_tolerance
A double that is read from the tolerance parameter specifying how close the input has to be to the value given by correctValues.protected java.util.List
_trainingTokens
List to store tokens for training mode.Parameter
correctValues
A matrix specifying what the input should be.Parameter
tolerance
A double specifying how close the input has to be to the value given by correctValues.SharedParameter
trainingMode
If true, then do not check inputs, but rather collect them into the correctValues array.-
Fields inherited from class ptolemy.actor.lib.Publisher
channel, global, input, output, propagateNameChanges
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
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 PublisherNonStrictTest(CompositeEntity container, java.lang.String name)
Construct a publisher with the specified container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeChanged(Attribute attribute)
If the attribute is the channel, increment the workspace version to force cached receiver lists to be updated, and invalidate the schedule and resolved types of the director, if there is one.void
fire()
Read at most one input token from each input channel and send it to the subscribers, if any.void
initialize()
Override the base class to set the iteration counter to zero.boolean
postfire()
Read one token from each input channel and compare against the value specified in correctValues.void
preinitialize()
Override the base class to ensure that links to subscribers have been updated.void
wrapup()
If trainingMode is true, then take the collected training tokens and store them as an array in correctValues.-
Methods inherited from class ptolemy.actor.lib.Publisher
clone, subscribers
-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, removeInitializable
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
correctValues
public Parameter correctValues
A matrix specifying what the input should be. This defaults to a one-by-one array containing a boolean true.
-
tolerance
public Parameter tolerance
A double specifying how close the input has to be to the value given by correctValues. This is a DoubleToken, with default value 10-9. During training, if a correct value is greater than 10 orders of magnitude than the tolerance, then the tolerance is changed to a value 9 orders of magnitude less than the correct value. This helps avoid comparisons beyond the precision of a Java double.
-
trainingMode
public SharedParameter trainingMode
If true, then do not check inputs, but rather collect them into the correctValues array. This parameter is a boolean, and it defaults to false. It is a shared parameter, meaning that changing it for any one instance in a model will change it for all instances in the model.
-
_firedOnce
protected boolean _firedOnce
Set to true if fire() is called once. If fire() is not called at least once, then throw an exception in wrapup().
-
_initialized
protected boolean _initialized
Set to true when initialized() is called.
-
_iteration
protected int _iteration
Count of iterations.
-
_numberOfInputTokensSeen
protected int _numberOfInputTokensSeen
Number of input tokens seen by this actor in the fire method.
-
_tolerance
protected double _tolerance
A double that is read from the tolerance parameter specifying how close the input has to be to the value given by correctValues. This is a double, with default value 10-9.
-
_trainingTokens
protected java.util.List _trainingTokens
List to store tokens for training mode.
-
-
Constructor Detail
-
PublisherNonStrictTest
public PublisherNonStrictTest(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct a publisher with the specified container and name.- Parameters:
container
- The container actor.name
- The name of the actor.- Throws:
IllegalActionException
- If the actor is not of an acceptable class for the container.NameDuplicationException
- If the name coincides with an actor already in the container.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
If the attribute is the channel, increment the workspace version to force cached receiver lists to be updated, and invalidate the schedule and resolved types of the director, if there is one.- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the change is not acceptable to this container.
-
fire
public void fire() throws IllegalActionException
Read at most one input token from each input channel and send it to the subscribers, if any.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classPublisher
- Throws:
IllegalActionException
- If there is no director.
-
initialize
public void initialize() throws IllegalActionException
Override the base class to set the iteration counter to zero.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the base class throws it or if we are running under the test suite and the trainingMode parameter is set to true.- See Also:
MessageHandler.isNonInteractive()
-
preinitialize
public void preinitialize() throws IllegalActionException
Override the base class to ensure that links to subscribers have been updated.- Specified by:
preinitialize
in interfaceInitializable
- Overrides:
preinitialize
in classPublisher
- Throws:
IllegalActionException
- If there is already a publisher publishing on the same channel.
-
postfire
public boolean postfire() throws IllegalActionException
Read one token from each input channel and compare against the value specified in correctValues. If the token count is larger than the length of correctValues, then return immediately, indicating that the inputs correctly matched the values in correctValues and that the test succeeded.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- Returns:
- True if execution can continue into the next iteration.
- Throws:
IllegalActionException
- If an input does not match the required value or if the width of the input is not 1.
-
wrapup
public void wrapup() throws IllegalActionException
If trainingMode is true, then take the collected training tokens and store them as an array in correctValues.- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If initialized() was called and fire() was not called or if the number of inputs tokens seen is not greater than or equal to the number of elements in the correctValues array.
-
-