|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.util.Attribute
ptolemy.actor.Director
ptolemy.actor.sched.StaticSchedulingDirector
ptolemy.actor.sched.FixedPointDirector
public class FixedPointDirector
A base class for directors that have fixed point semantics at each iteration. An iteration consists of repeated firings of the actors controlled by this director until a fixed point is reached. An iteration has converged if firing actors will not change signal status any more.
At the beginning of each iteration, the status of all inputs and outputs is unknown. Upon firing an actor, the status of its output signals may become known. Once the status of a signal becomes known, it cannot be changed back to unknown in the iteration. This monotonicity constraint ensures the existence and uniqueness of the fixed point. During an iteration, the prefire() and fire() methods of the controlled actors may be repeatedly invoked, but the postfire() method will be invoked exactly once after the fixed point has been found. The postfire() methods of the contained actors are invoked only in the postfire() method of this director, and they are invoked in arbitrary order.
If the prefire() method of an actor returns false, then this director assumes that all the outputs of the actor are absent. The actor has declined to fire.
Although this director does not require any specific ordering of actor firings, a scheduler is used to choose an efficient ordering.
By default, actors are strict, which means that all their input signals must be known before the actor can be fired. Here, what we mean by "fired" is that prefire() is invoked, and if it returns true, then fire() is invoked. Such actors will be fired only once in an iteration. A non-strict actor can be fired regardless of the status of its inputs, and may be fired repeatedly in an iteration if some of the inputs are unknown. Once an actor is fired with all its inputs known, it will not be fired again in the same iteration. A composite actor containing this director is a non-strict actor.
For an actor to be used under the control of this director, it must either be strict, or if it is non-strict, it must be monotonic. Montonicity implies two constraints on the actor. First, if prefire() ever returns true during an iteration, then it will return true on all subsequent invocations in the same iteration(). Second, if either prefire() or fire() call clear() on an output port, then no subsequent invocation in the same iteration can call put() on the port. If prefire() or fire() call put() on an output port with some token, then no subsequent invocation in the same iteration can call clear() or put() with a token with a different value. These constraints ensure determinacy.
If synchronizeToRealTime is set to true
,
then the postfire() method stalls until the real time elapsed
since the model started matches the current time.
This ensures that the director does not get ahead of real time. However,
of course, this does not ensure that the director keeps up with real time.
Note that this synchronization occurs after actors have been fired,
but before they have been postfired.
This class is based on the original SRDirector, written by Paul Whitaker.
Yellow (eal) |
Green (hyzheng) |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
---|
NamedObj.ContainedObjectsIterator |
Field Summary | |
---|---|
private java.util.Set |
_actorsAllowedToFire
The set of actors that have returned true in their prefire() methods in the current iteration. |
private java.util.Set |
_actorsFinishedFiring
The set of actors that have been fired in this iteration with all inputs known. |
private java.util.Set |
_actorsFired
Actors that were fired in the most recent invocation of the fire() method. |
private java.util.Set |
_cachedAllInputsKnown
The set of actors that have all inputs known in the given iteration. |
private boolean |
_cachedFunctionalProperty
The cache of the functional property of the container of this director. |
private int |
_currentIteration
The count of iterations executed. |
private int |
_currentNumberOfKnownReceivers
The current number of receivers with known state. |
private long |
_functionalPropertyVersion
Version number for the cached functional property. |
protected int |
_index
The current index of the model. |
private int |
_lastNumberOfKnownReceivers
The number of receivers with known state on the last phase of actor firings. |
private long |
_realStartTime
The real time at which the model begins executing. |
protected java.util.List |
_receivers
List of all receivers this director has created. |
Parameter |
iterations
The number of times that postfire may be called before it returns false. |
Parameter |
synchronizeToRealTime
Specify whether the execution should synchronize to the real time. |
Fields inherited from class ptolemy.actor.sched.StaticSchedulingDirector |
---|
_postfireReturns |
Fields inherited from class ptolemy.actor.Director |
---|
_actorsFinishedExecution, _currentTime, _finishRequested, _initializables, _stopRequested, timeResolution |
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 | |
---|---|
FixedPointDirector()
Construct a director in the default workspace with an empty string as its name. |
|
FixedPointDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name. |
|
FixedPointDirector(Workspace workspace)
Construct a director in the given workspace with an empty name. |
Method Summary | |
---|---|
private boolean |
_areAllInputsKnown(Actor actor)
Return true if all the inputs of the specified actor are known. |
private void |
_fireActor(Actor actor)
Fire an actor. |
private boolean |
_hasIterationConverged()
Return true if this iteration has converged. |
private void |
_init()
Initialize the director by creating the parameters and setting their values and types. |
private boolean |
_isReadyToFire(Actor actor)
Return true if the specified actor is ready to fire. |
private boolean |
_postfireActor(Actor actor)
Return the result of the postfire() method of the specified actor if it is allowed to be fired in the current iteration. |
protected void |
_receiverChanged()
React to the change in receiver status by incrementing the count of known receivers. |
protected void |
_resetAllReceivers()
Reset all receivers to unknown status and clear out variables used to track which actors fired in the last iteration. |
private void |
_sendAbsentToAllUnknownOutputsOf(Actor actor)
Call the send(index, null) method of each output port with unknown status of the specified actor |
protected void |
_synchronizeToRealTime()
Synchronize to real time, if appropriate. |
java.lang.Object |
clone(Workspace workspace)
Clone the director into the specified workspace. |
void |
fire()
Prefire and fire actors in the order given by the scheduler until the iteration converges. |
int |
getIndex()
Return the current index of the director. |
boolean |
implementsStrictActorSemantics()
Return true, indicating that this director assumes and exports the strict actor semantics, as described in this paper: A. |
void |
initialize()
Initialize the director and all deeply contained actors by calling the super.initialize() method. |
boolean |
isFireFunctional()
Return true if all the controlled actors' isFireFunctional() methods return true. |
boolean |
isStrict()
Return false. |
Receiver |
newReceiver()
Return a new FixedPointReceiver. |
boolean |
postfire()
Call postfire() on all contained actors that were fired in the current iteration. |
boolean |
prefire()
Return true if the director is ready to fire. |
void |
setIndex(int index)
Set the superdense time index. |
java.lang.String[] |
suggestedModalModelDirectors()
Return an array of suggested directors to be used with ModalModel. |
boolean |
transferInputs(IOPort port)
Transfer data from the specified input port of the container to the ports it is connected to on the inside. |
boolean |
transferOutputs(IOPort port)
Transfer data from the specified output port of the container to the ports it is connected to on the outside. |
Methods inherited from class ptolemy.actor.sched.StaticSchedulingDirector |
---|
_setScheduler, addDebugListener, getScheduler, invalidateSchedule, isScheduleValid, removeDebugListener, setScheduler |
Methods inherited from class ptolemy.kernel.util.Attribute |
---|
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public Parameter iterations
public Parameter synchronizeToRealTime
protected int _index
protected java.util.List _receivers
private java.util.Set _actorsAllowedToFire
private java.util.Set _actorsFinishedFiring
private java.util.Set _actorsFired
private java.util.Set _cachedAllInputsKnown
private boolean _cachedFunctionalProperty
private int _currentNumberOfKnownReceivers
private int _currentIteration
private transient long _functionalPropertyVersion
private int _lastNumberOfKnownReceivers
private long _realStartTime
Constructor Detail |
---|
public FixedPointDirector() throws IllegalActionException, NameDuplicationException
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.public FixedPointDirector(Workspace workspace) throws IllegalActionException, NameDuplicationException
workspace
- The workspace for this object.
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.public FixedPointDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- Container of the director.name
- Name of this director.
IllegalActionException
- If the director is not compatible
with the specified container.
NameDuplicationException
- If the name collides with an
attribute in the container.Method Detail |
---|
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class StaticSchedulingDirector
workspace
- The workspace for the new director.
java.lang.CloneNotSupportedException
- If a derived class contains
an attribute that cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class StaticSchedulingDirector
IllegalActionException
- If an actor violates the
monotonicity constraints, or the prefire() or fire() method
of the actor throws it.public int getIndex()
getIndex
in interface SuperdenseTimeDirector
setIndex(int)
,
SuperdenseTimeDirector
public boolean implementsStrictActorSemantics()
A. Goderis, C. Brooks, I. Altintas, E. A. Lee, and C. Goble, "Heterogeneous Composition of Models of Computation," EECS Department, University of California, Berkeley, Tech. Rep. UCB/EECS-2007-139, Nov. 2007. http://www.eecs.berkeley.edu/Pubs/TechRpts/2007/EECS-2007-139.html
In particular, a director that implements this interface guarantees that it will not invoke the postfire() method of an actor until all its inputs are known at the current tag. Moreover, it it will only do so in its own postfire() method, and in its prefire() and fire() methods, it does not change its own state. Thus, such a director can be used within a model of computation that has a fixed-point semantics, such as SRDirector and ContinuousDirector.
implementsStrictActorSemantics
in class Director
public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class Director
IllegalActionException
- If the superclass throws it.public boolean isFireFunctional()
isFireFunctional
in interface Executable
isFireFunctional
in class Director
public boolean isStrict()
isStrict
in interface Executable
isStrict
in class Director
public Receiver newReceiver()
newReceiver
in class Director
public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class StaticSchedulingDirector
IllegalActionException
- If the iterations parameter does
not have a valid token, or if there still some unknown inputs (which
indicates a causality loop).public boolean prefire() throws IllegalActionException
prefire
in interface Executable
prefire
in class StaticSchedulingDirector
IllegalActionException
- Not thrown in this base class.public void setIndex(int index) throws IllegalActionException
setIndex
in interface SuperdenseTimeDirector
index
- The index of the superdense time object.
Events that occur at the same time have different indicies.
IllegalActionException
- Not thrown in this base class.getIndex()
,
SuperdenseTimeDirector
public java.lang.String[] suggestedModalModelDirectors()
suggestedModalModelDirectors
in class Director
Director.suggestedModalModelDirectors()
public boolean transferInputs(IOPort port) throws IllegalActionException
transferInputs
in class Director
port
- The port to transfer tokens from.
IllegalActionException
- If the port is not an opaque
input port.public boolean transferOutputs(IOPort port) throws IllegalActionException
transferOutputs
in class Director
port
- The port to transfer tokens from.
IllegalActionException
- If the port is not an opaque
output port.protected void _receiverChanged()
protected void _resetAllReceivers()
protected void _synchronizeToRealTime() throws IllegalActionException
IllegalActionException
- If the synchronizeToRealTime
parameter is ill formed.private boolean _areAllInputsKnown(Actor actor) throws IllegalActionException
IllegalActionException
private void _fireActor(Actor actor) throws IllegalActionException
IllegalActionException
- If the prefire() method
returns false having previously returned true in the same
iteration, or if the prefire() or fire() method of the actor
throws it.private boolean _hasIterationConverged()
private void _init() throws IllegalActionException, NameDuplicationException
IllegalActionException
NameDuplicationException
private boolean _isReadyToFire(Actor actor) throws IllegalActionException
IllegalActionException
private boolean _postfireActor(Actor actor) throws IllegalActionException
IllegalActionException
private void _sendAbsentToAllUnknownOutputsOf(Actor actor) throws IllegalActionException
actor
- The actor.
IllegalActionException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |