public class DDFDirector extends Director
The dynamic scheduler implemented in this director fires all enabled and non-deferrable actors once in a basic iteration. A deferrable actor is one that will not help one of the downstream actors become enabled because that downstream actor either already has enough tokens on the channel connecting those two actors or is waiting for tokens on another channel. If no actor fires so far, which means there is no enabled and non-deferrable actor, then among all enabled and deferrable actors, this director fires those which have the smallest maximum number of tokens on their output channels which satisfy the demand of destination actors. If still no actor fires, then there is no enabled actor. A user can treat several such basic iterations as a single iteration by adding a parameter with name requiredFiringsPerIteration to an actor (which is often a sink actor or an actor directly connected to output port of the composite actor) and specifying the number of times this actor must be fired in a single iteration. If the value of the parameter runUntilDeadlockInOneIteration is a BooleanToken with value true, one single iteration consists of repeating the basic iteration until deadlock is reached (thus overriding the previous definition of one iteration), which is the status of the model where all active actors under the control of this director are unable to fire because their firing rules are not satisfied. However, they may be able to fire again during next iteration when tokens are transferred in from an outside domain. Note runUntilDeadlockInOneIteration can be set to true only when this director is not on the top level.
The algorithm implementing one basic iteration goes like this:
E = set of enabled actors D = set of deferrable enabled actorsOne basic(default) iteration consists of:
if (E\D != empty set) { fire (E\D) } else if (D != empty set) { fire minimax(D) } else { declare deadlock }The function "minimax(D)" returns a subset of D with the smallest maximum number of tokens on their output channels which satisfy the demand of destination actors.
Note that any SDF model can be run with a DDF Director. However, the notion of iteration is different. One could try to imitate the SDF iteration in the DDF domain by controlling the number of firings in one iteration for some actors, such as requiring a plotter to plot a fixed number of points in each iteration.
In the DDF domain, the firing rule of any actor is specified by the token consumption rates of its input ports. A general DDF actor could change the consumption rates of its input ports after each firing of this actor. For multiports, an array token could be used to specify different rates for different channels connected to the same multiport. Note that in SDF, all channels connected to the same multiport have the same rate.
Based on DDFSimpleSched in Ptolemy Classic, by Edward Lee. See E. A. Lee et al., "The Almagest," documentation for Ptolemy Classic, Vol. 1, Chapter 7, 1997.
Yellow (cxh) |
Yellow (zgang) |
NamedObj.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
Parameter |
iterations
A Parameter representing the number of times that postfire() may
be called before it returns false.
|
Parameter |
maximumReceiverCapacity
A Parameter representing the maximum capacity of each receiver
controlled by this director.
|
Parameter |
runUntilDeadlockInOneIteration
A parameter indicating whether one iteration consists of
repeated basic iterations until deadlock.
|
_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 |
---|
DDFDirector()
Construct a director in the default workspace with an empty string
as its name.
|
DDFDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name.
|
DDFDirector(Workspace workspace)
Construct a director in the workspace with an empty name.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
_fireActor(Actor actor)
Iterate the actor once.
|
protected ActorEnablingStatus |
_getActorStatus(Actor actor)
Determine actor enabling status.
|
protected boolean |
_isDeferrable(Actor actor)
Check each remote receiver to see whether the number of tokens
in the receiver is greater than or equal to the
tokenConsumptionRate of the containing port.
|
protected boolean |
_isEnabled(Actor actor)
Check to see whether the actor is enabled.
|
protected void |
_updateConnectedActorsStatus(Actor actor)
Update the enabling status of the given actor and all actors
connected to this actor.
|
void |
attributeChanged(Attribute attribute)
If the attribute being changed is runUntilDeadlockInOneIteration
and it is set to be true, then verify this director is not at the
top level.
|
java.lang.Object |
clone(Workspace workspace)
Clone the director into the specified workspace.
|
void |
disableTypeResolution(boolean flag)
Set the flag indicating whether type resolution is disabled or not.
|
void |
fire()
Execute the model for one iteration.
|
void |
initialize()
Initialize the model controlled by this director.
|
void |
initialize(Actor actor)
Initialize the given actor.
|
void |
invalidateResolvedTypes()
Call base class method to invalidate resolved types if the flag to
disable type resolution is set to false.
|
void |
merge(DDFDirector insideDirector)
Merge an opaque composite actor controlled by an inside DDFDirector
with the outside domain controlled by this director.
|
Receiver |
newReceiver()
Return a new QueueReceiver.
|
boolean |
postfire()
Increment the number of iterations.
|
boolean |
prefire()
Check the input ports of the container composite actor (if there
are any) to see whether they have enough tokens, and return true
if they do.
|
java.lang.String[] |
suggestedModalModelDirectors()
Return an array of suggested directors to use with an embedded
ModalModel.
|
boolean |
supportMultirateFiring()
Return true to indicate that a ModalModel under control
of this director supports multirate firing.
|
boolean |
transferInputs(IOPort port)
Override the base class method to transfer enough tokens to complete
an internal iteration.
|
boolean |
transferOutputs(IOPort port)
Override the base class method to transfer enough tokens to
fulfill the output production rate.
|
_actorFinished, _consultTimeRegulators, _description, _isEmbedded, _isTopLevel, _schedule, _transferInputs, _transferOutputs, addInitializable, createSchedule, defaultDependency, delayDependency, finish, fireAt, fireAt, fireAt, fireAtCurrentTime, fireContainerAt, fireContainerAt, getCausalityInterface, getCurrentTime, getDeadline, getEnvironmentTime, getErrorTolerance, getExecutionAspect, getGlobalTime, getModelNextIterationTime, getModelStartTime, getModelStopTime, getModelTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, implementsStrictActorSemantics, invalidateSchedule, isEmbedded, isFireFunctional, isStopRequested, isStrict, iterate, mutexLockObject, notifyTokenSentToCommunicationAspect, preinitialize, preinitialize, removeInitializable, requestInitialization, resume, resumeActor, scheduleContainedActors, setContainer, setCurrentTime, setEmbedded, setModelTime, setTimeResolution, stop, stopFire, 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, 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
public Parameter iterations
public Parameter maximumReceiverCapacity
public Parameter runUntilDeadlockInOneIteration
public DDFDirector() 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 DDFDirector(Workspace workspace) throws IllegalActionException, NameDuplicationException
workspace
- The workspace of 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 DDFDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container of this director.name
- Name of this director.IllegalActionException
- Not thrown in this base class.
May be thrown in the derived classes if the director
is not compatible with the specified container.NameDuplicationException
- If the name collides with
an attribute that already exists in the given container.public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class Director
attribute
- The changed parameter.IllegalActionException
- If this director is at top
level and runUntilDeadlockInOneIteration is set to be true,
or getToken() throws IllegalActionException.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class Director
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 disableTypeResolution(boolean flag)
flag
- The flag to be set.public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class Director
IllegalActionException
- If any actor executed by this
actor returns false in prefire().public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class Director
IllegalActionException
- If the initialize() method of
one of the associated actors throws it.public void initialize(Actor actor) throws IllegalActionException
initialize
in class Director
actor
- The actor to be initialized.IllegalActionException
- If the
requiredFiringsPerIteration parameter does not contain
an IntToken.public void invalidateResolvedTypes()
invalidateResolvedTypes
in class Director
public void merge(DDFDirector insideDirector)
insideDirector
- The inside DDFDirector to be merged.public Receiver newReceiver()
newReceiver
in class Director
public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class Director
IllegalActionException
- If the iterations parameter
does not contain a legal value.public boolean prefire() throws IllegalActionException
prefire
in interface Executable
prefire
in class Director
IllegalActionException
- If any called method throws
IllegalActionException.public java.lang.String[] suggestedModalModelDirectors()
suggestedModalModelDirectors
in class Director
Director.suggestedModalModelDirectors()
public boolean supportMultirateFiring()
supportMultirateFiring
in class Director
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, or if there are not enough input tokens available.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, or if there are not enough output tokens available.protected boolean _fireActor(Actor actor) throws IllegalActionException
actor
- The actor to be fired.IllegalActionException
- If any called method throws
IllegalActionException or the actor is not ready.protected ActorEnablingStatus _getActorStatus(Actor actor) throws IllegalActionException
actor
- The actor to be checked.IllegalActionException
- If any called method throws
IllegalActionException.protected boolean _isDeferrable(Actor actor) throws IllegalActionException
actor
- The actor to be checked.IllegalActionException
- If any called method throws
IllegalActionException.protected boolean _isEnabled(Actor actor) throws IllegalActionException
actor
- The actor to be checked.IllegalActionException
- If any called method throws
IllegalActionException.protected void _updateConnectedActorsStatus(Actor actor) throws IllegalActionException
actor
- The actor to te checked.IllegalActionException
- If _getActorStatus(Actor) throws
IllegalActionException.