ptolemy.backtrack.automatic.ptolemy.actor.lib
Class PoissonClock

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.lib.Source
                              extended by ptolemy.backtrack.automatic.ptolemy.actor.lib.RandomSource
                                  extended by ptolemy.backtrack.automatic.ptolemy.actor.lib.PoissonClock
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TimedActor, TypedActor, Rollbackable, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class PoissonClock
extends RandomSource
implements TimedActor, Rollbackable

This actor produces discrete events according to a Poisson process. The time between events is given by independent and identically distributed exponential random variables. The values produced rotate sequentially through those given in the values parameter, which is an array of anything and defaults to {1, 0}. The type of the output can be any token type. This type is inferred from the element type of the values parameter. The mean time between events is given by the meanTime parameter, which defaults to 1.0.

In the initialize() method and postfire() methods, the actor uses the fireAt() method of the director to request the next firing. The first firing is always at the start time, unless the parameter fireAtStart is changed to false.

If the trigger input is connected, then any event on it will cause the Poisson process to immediately produce the next event, as if the time for that event had arrived.

If this actor is inactive at the time at which it would have otherwise produced an output, then it will stop producing outputs. This should not happen.

Since:
Ptolemy II 1.0
Version:
$Id: PoissonClock.java 57046 2010-01-27 23:35:53Z cxh $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Yellow (yuhong)
Proposed Rating:
Yellow (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  double _current
           
private  boolean _executing
           
private  int _length
           
private  Time _nextFiringTime
           
private  int _nextOutputIndex
           
private  Time _stopTime
           
private  FieldRecord $RECORD$_current
           
private  FieldRecord $RECORD$_executing
           
private  FieldRecord $RECORD$_length
           
private  FieldRecord $RECORD$_nextFiringTime
           
private  FieldRecord $RECORD$_nextOutputIndex
           
private  FieldRecord $RECORD$_stopTime
           
private  FieldRecord[] $RECORDS
           
 Parameter fireAtStart
          If true, then this actor will request a firing at the start time.
 Parameter meanTime
          The mean time between events, where the output value transitions.
 Parameter stopTime
          The time at which postfire() should return false.
 Parameter values
          The values that will be produced at the output.
 
Fields inherited from class ptolemy.backtrack.automatic.ptolemy.actor.lib.RandomSource
_generatorSeed, _needNew, _needNewGenerator, _random, $CHECKPOINT, $RECORD$$CHECKPOINT, resetOnEachRun, seed
 
Fields inherited from class ptolemy.actor.lib.Source
output, trigger
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _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
PoissonClock(CompositeEntity container, java.lang.String name)
          Construct an actor with the specified container and name.
 
Method Summary
protected  void _generateRandomNumber()
          Generate a new random number.
private  Token _getValue(int index)
           
private  double $ASSIGN$_current(double newValue)
           
private  boolean $ASSIGN$_executing(boolean newValue)
           
private  int $ASSIGN$_length(int newValue)
           
private  Time $ASSIGN$_nextFiringTime(Time newValue)
           
private  int $ASSIGN$_nextOutputIndex(int newValue)
           
private  Time $ASSIGN$_stopTime(Time newValue)
           
private  int $ASSIGN$SPECIAL$_nextOutputIndex(int operator, long newValue)
           
 void $COMMIT(long timestamp)
          Commit changes up to the given timestamp, but not including changes made at timestamp and afterward.
 void $RESTORE(long timestamp, boolean trim)
          Restore a previous state to all the private fields of this rollbackable object.
 void attributeChanged(Attribute attribute)
          If the argument is the meanTime parameter, check that it is positive.
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 void fire()
          Output the current value.
 Time getModelStopTime()
          Get the stop time.
 double getStopTime()
          Deprecated. As of Ptolemy II 4.1, replaced by{
 void initialize()
          Request the first firing either at the start time or at a random time, depending on fireAtStart.
 boolean postfire()
          Generate an exponential random number and schedule the next firing.
 boolean prefire()
          If the current time matches the expected time for the next output, then return true.
 void wrapup()
          Override the base class to reset a flag that indicates that the model is executing.
 
Methods inherited from class ptolemy.backtrack.automatic.ptolemy.actor.lib.RandomSource
_createGenerator, $GET$CHECKPOINT, $SET$CHECKPOINT
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, preinitialize, 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
_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, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, 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, propagateValue, propagateValues, removeChangeListener, removeDebugListener, 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.backtrack.Rollbackable
$GET$CHECKPOINT, $SET$CHECKPOINT
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

fireAtStart

public Parameter fireAtStart
If true, then this actor will request a firing at the start time. Otherwise, the first firing will be requested at the first random time. This is a boolean-valued parameter that defaults to true.


meanTime

public Parameter meanTime
The mean time between events, where the output value transitions. This parameter must contain a DoubleToken.


stopTime

public Parameter stopTime
The time at which postfire() should return false. This is a double that defaults to Infinity, which means that postfire() never returns false (or at least, doesn't do so due to stopTime having been exceeded).


values

public Parameter values
The values that will be produced at the output. This parameter can contain any ArrayToken, and it defaults to {1, 0}.


_current

private double _current

_executing

private boolean _executing

_length

private transient int _length

_nextFiringTime

private transient Time _nextFiringTime

_nextOutputIndex

private transient int _nextOutputIndex

_stopTime

private Time _stopTime

$RECORD$_current

private transient FieldRecord $RECORD$_current

$RECORD$_executing

private transient FieldRecord $RECORD$_executing

$RECORD$_length

private transient FieldRecord $RECORD$_length

$RECORD$_nextFiringTime

private transient FieldRecord $RECORD$_nextFiringTime

$RECORD$_nextOutputIndex

private transient FieldRecord $RECORD$_nextOutputIndex

$RECORD$_stopTime

private transient FieldRecord $RECORD$_stopTime

$RECORDS

private transient FieldRecord[] $RECORDS
Constructor Detail

PoissonClock

public PoissonClock(CompositeEntity container,
                    java.lang.String name)
             throws NameDuplicationException,
                    IllegalActionException
Construct an actor with the specified container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the entity cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
If the argument is the meanTime parameter, check that it is positive.

Overrides:
attributeChanged in class RandomSource
Parameters:
attribute - The attribute that changed.
Throws:
IllegalActionException - If the meanTime value is not positive.

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace. This calls the base class and then sets the parameter public members to refer to the parameters of the new actor.

Overrides:
clone in class RandomSource
Parameters:
workspace - The workspace for the new object.
Returns:
A new actor.
Throws:
java.lang.CloneNotSupportedException - If a derived class contains an attribute that cannot be cloned.
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

fire

public void fire()
          throws IllegalActionException
Output the current value.

Specified by:
fire in interface Executable
Overrides:
fire in class RandomSource
Throws:
IllegalActionException - If there is no director.

getStopTime

public double getStopTime()
Deprecated. As of Ptolemy II 4.1, replaced by{

Get the stop time.

Returns:
The stop time.

getModelStopTime

public Time getModelStopTime()
Get the stop time.

Returns:
The stop time.

initialize

public void initialize()
                throws IllegalActionException
Request the first firing either at the start time or at a random time, depending on fireAtStart.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class RandomSource
Throws:
IllegalActionException - If the fireAt() method of the director throws it, or if the director does not agree to fire the actor at the specified time.

postfire

public boolean postfire()
                 throws IllegalActionException
Generate an exponential random number and schedule the next firing.

Specified by:
postfire in interface Executable
Overrides:
postfire in class RandomSource
Returns:
True if it is ok to continue.
Throws:
IllegalActionException - If the director throws it when scheduling the next firing, or if the director does not agree to fire the actor at the specified time.

prefire

public boolean prefire()
                throws IllegalActionException
If the current time matches the expected time for the next output, then return true. Also return true if the trigger input is connected and has events. Otherwise, return false.

Specified by:
prefire in interface Executable
Overrides:
prefire in class Source
Returns:
True, unless the trigger input is connected and has no input.
Throws:
IllegalActionException - If there is no director.

wrapup

public void wrapup()
            throws IllegalActionException
Override the base class to reset a flag that indicates that the model is executing. This method is invoked exactly once per execution of an application. None of the other action methods should be be invoked after it.

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class AtomicActor
Throws:
IllegalActionException - Not thrown in this base class.

_generateRandomNumber

protected void _generateRandomNumber()
                              throws IllegalActionException
Generate a new random number.

Specified by:
_generateRandomNumber in class RandomSource
Throws:
IllegalActionException - If parameter values are incorrect.

_getValue

private Token _getValue(int index)
                 throws IllegalActionException
Throws:
IllegalActionException

$ASSIGN$_current

private final double $ASSIGN$_current(double newValue)

$ASSIGN$_executing

private final boolean $ASSIGN$_executing(boolean newValue)

$ASSIGN$_length

private final int $ASSIGN$_length(int newValue)

$ASSIGN$_nextFiringTime

private final Time $ASSIGN$_nextFiringTime(Time newValue)

$ASSIGN$_nextOutputIndex

private final int $ASSIGN$_nextOutputIndex(int newValue)

$ASSIGN$SPECIAL$_nextOutputIndex

private final int $ASSIGN$SPECIAL$_nextOutputIndex(int operator,
                                                   long newValue)

$ASSIGN$_stopTime

private final Time $ASSIGN$_stopTime(Time newValue)

$COMMIT

public void $COMMIT(long timestamp)
Description copied from interface: Rollbackable
Commit changes up to the given timestamp, but not including changes made at timestamp and afterward.

Specified by:
$COMMIT in interface Rollbackable
Overrides:
$COMMIT in class RandomSource
Parameters:
timestamp - The timestamp.

$RESTORE

public void $RESTORE(long timestamp,
                     boolean trim)
Description copied from interface: Rollbackable
Restore a previous state to all the private fields of this rollbackable object.

Specified by:
$RESTORE in interface Rollbackable
Overrides:
$RESTORE in class RandomSource
Parameters:
timestamp - The timestamp taken at the time when the previous state was recorded.
trim - Whether to delete the records used for the rollback.
See Also:
Checkpoint.rollback(long, boolean)