public class FixedPointDirector extends StaticSchedulingDirector implements SuperdenseTimeDirector
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.
NamedObj.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
protected java.util.Set |
_actorsAllowedToFire
The set of actors that have returned true in their prefire() methods
in the current iteration.
|
protected java.util.Set |
_actorsFinishedFiring
The set of actors that have been fired in this iteration with
all inputs known.
|
protected java.util.Set |
_actorsFired
Actors that were fired in the most recent invocation of the fire() method.
|
protected int |
_index
The current index of the model.
|
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.
|
_postfireReturns, _prefire
_actorsFinishedExecution, _aspectForActor, _aspectsPresent, _defaultMicrostep, _executionAspects, _finishRequested, _initializables, _nextScheduleTime, _stopRequested, _tokenSentToCommunicationAspect, _zeroTime, localClock, startTime, stopTime
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
_areAllInputsKnown(Actor actor)
Return true if all the inputs of the specified actor are known.
|
protected void |
_fireActor(Actor actor)
Fire an actor.
|
protected boolean |
_hasIterationConverged()
Return true if this iteration has converged.
|
protected boolean |
_isReadyToFire(Actor actor)
Return true if the specified actor is ready to fire.
|
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.
|
protected 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.
|
Time |
getModelNextIterationTime()
Return the next time of interest in the model being executed by
this director or the director of any enclosing model up the
hierarchy.
|
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.
|
_setScheduler, addDebugListener, getScheduler, invalidateSchedule, isScheduleValid, removeDebugListener, resumeActor, setScheduler
_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, getModelStartTime, getModelStopTime, getModelTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, initialize, invalidateResolvedTypes, isEmbedded, isStopRequested, iterate, mutexLockObject, notifyTokenSentToCommunicationAspect, preinitialize, preinitialize, removeInitializable, requestInitialization, resume, scheduleContainedActors, setContainer, setCurrentTime, setEmbedded, setModelTime, setTimeResolution, stop, stopFire, supportMultirateFiring, suspend, terminate, transferOutputs, wrapup
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, 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, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
public Parameter iterations
public Parameter synchronizeToRealTime
protected java.util.Set _actorsAllowedToFire
protected java.util.Set _actorsFired
protected int _index
protected java.util.List _receivers
protected java.util.Set _actorsFinishedFiring
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.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 Time getModelNextIterationTime() throws IllegalActionException
This method is useful for domains that perform speculative execution (such as Continuous itself). Such a domain in a hierarchical model (i.e. CT inside DE) uses this method to determine how far into the future to execute. This is simply an optimization that reduces the likelihood of having to roll back.
The base class implementation in Director is almost right, but not quite, because at the top level it returns current time. However, this director should not constrain any director below it from speculatively executing into the future. Instead, it assumes that any director below it implements a strict actor semantics. Note in particular that the implementation below would block time advancement in a Continuous in DE in Continuous model because the top-level model will usually only invoke the DE model during a zero-step execution, which means that the returned next iteration time will always be current time, which will force the inside Continuous director to have a zero step size always.
getModelNextIterationTime
in class Director
IllegalActionException
- If creating a Time object fails.Director.getModelTime()
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 StaticSchedulingDirector
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
input port, or if there are not enough input tokens available.protected boolean _areAllInputsKnown(Actor actor) throws IllegalActionException
actor
- The specified actor.IllegalActionException
- If thrown while checking if an input
port is known.protected void _fireActor(Actor actor) throws IllegalActionException
actor
- The actor to be fired.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.protected boolean _hasIterationConverged() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.protected boolean _isReadyToFire(Actor actor) throws IllegalActionException
actor
- The actor that is checked for being ready to fire.IllegalActionException
- If thrown while determining
if actors are finished firing, or while determining if the actor is
strict, or while determining if all the inputs are known.protected void _receiverChanged()
protected void _resetAllReceivers()
protected void _sendAbsentToAllUnknownOutputsOf(Actor actor) throws IllegalActionException
actor
- The actor.IllegalActionException
- If thrown while getting
the width of a port, determining if a port is known
or while sending data.protected void _synchronizeToRealTime() throws IllegalActionException
SynchronizeToRealTime
attribute, which implements the
TimeRegulator
interface.IllegalActionException
- If the synchronizeToRealTime
parameter is ill formed.