public class SRDirector extends FixedPointDirector implements PeriodicDirector
Execution proceeds as follows. The director checks each actor to determine whether it is strict or not by calling its isStrict() method (here, "strict" means that all inputs must be known before the actor can specify any outputs). By default, actors are strict. Strict actors are fired only once in an iteration. Their inputs are all known (and may absent) when prefire() is invoked. If prefire() returns true, the fire() and postfire() are invoked exactly once.
Specialized actors may be non-strict, meaning that they are able to produce outputs even their inputs are not known. Such actors must conform to certain requirements in order to ensure determinacy. First, such actors should check input ports by calling their isKnown() method before calling hasToken() to determine whether the port is "absent." Only if both isKnown() and hasToken() return true should the actor call get() on that port. A non-strict actor may be prefired and 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.
Each actor's fire() method implements a (possibly state-dependent) function from input ports to output ports. At each tick of the clock, the fire() method of each non-strict actor may be evaluated multiple times, and each time, it must implement the same function. Thus, the actors are required to conform with the strict actor semantics, which means that they do not change their state in the prefire() or fire() methods, and only change their state in postfire(). This helps ensure that the actor is monotonic. Montonicity implies three constraints on the actor. First, if prefire() ever returns true during an iteration, then it will return true on all subsequent invocations of prefire() in the same iteration(). In subsequent iterations, inputs may become known, but once they are known, the value of the input and whether it is present cannot change in subsequent firings 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. Third, 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.
The SR director has a period parameter which specifies the amount of model time that elapses per iteration. If the value of period is 0.0 (the default), then it has no effect, and this director never increments time nor calls fireAt() on the enclosing director. If the period is greater than 0.0, then if this director is at the top level, it increments time by this amount in each invocation of postfire(). If it is not at the top level, then it refuses to fire at times that do not match a multiple of the period (by returning false in prefire()). If it fires, then in postfire() it calls fireAt(currentTime + period) in postfire() to request the next firing.
Note that currentTime, as usual, means local time. If this director is inside a modal model, then that current time may lag behind the time of the environment in which the modal model executes because time does not elapse while a mode is inactive. In fact, time may bounce around, since if a startTime is specified and the modal model has a reset transition, then local time may be reinitialized to the start time during execution. Moreover, if the startTime of this director inside a modal is greater than the start time of the enclosing director, then local time may actually be ahead of environment time.
This behavior gives an interesting use of SR within DE or Continuous. In particular, if set a period other than 0.0, the composite actor with this SR director will fire periodically with the specified period.
If period is greater than 0.0 and the parameter
synchronizeToRealTime is set to true
,
then the prefire() method stalls until the real time elapsed
since the model started matches the period multiplied by
the iteration count.
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.
Green (pwhitake) |
Green (pwhitake) |
NamedObj.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
Parameter |
period
The time period of each iteration.
|
_actorsAllowedToFire, _actorsFinishedFiring, _actorsFired, _index, _receivers, iterations, synchronizeToRealTime
_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 |
---|
SRDirector()
Construct a director in the default workspace with an empty string
as its name.
|
SRDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name.
|
SRDirector(Workspace workspace)
Construct a director in the given workspace with an empty name.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone(Workspace workspace)
Clone the object into the specified workspace.
|
Time |
fireAt(Actor actor,
Time time,
int microstep)
Request a firing of the given actor at the given absolute
time, and return the time at which the specified will be
fired.
|
Time |
getModelNextIterationTime()
Return the time value of the next iteration.
|
void |
initialize()
Initialize the director and all deeply contained actors by calling
the super.initialize() method.
|
double |
periodValue()
Return the value of the period as a double.
|
boolean |
postfire()
Call postfire() on all contained actors that were fired on the last
invocation of fire().
|
boolean |
prefire()
Return true if we are ready to fire, meaning that either (1) we are
at the top level, (2) the period parameter is zero (in which case we
are always ready to fire, or (3) the period parameter is nonzero,
the current time matches the next expected execution time, and the
current microstep is 1.
|
_areAllInputsKnown, _fireActor, _hasIterationConverged, _isReadyToFire, _receiverChanged, _resetAllReceivers, _sendAbsentToAllUnknownOutputsOf, _synchronizeToRealTime, fire, getIndex, implementsStrictActorSemantics, isFireFunctional, isStrict, newReceiver, setIndex, suggestedModalModelDirectors, transferInputs, transferOutputs
_setScheduler, addDebugListener, getScheduler, invalidateSchedule, isScheduleValid, removeDebugListener, resumeActor, setScheduler
_actorFinished, _consultTimeRegulators, _description, _isEmbedded, _isTopLevel, _schedule, _transferInputs, _transferOutputs, addInitializable, attributeChanged, createSchedule, defaultDependency, delayDependency, finish, fireAt, fireAt, fireAtCurrentTime, fireContainerAt, fireContainerAt, getCausalityInterface, getCurrentTime, getDeadline, getEnvironmentTime, getErrorTolerance, 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
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isEmbedded
fire, isFireFunctional, isStrict, iterate, stop, stopFire, terminate
addInitializable, preinitialize, removeInitializable, wrapup
description, getContainer, getDisplayName, getFullName, getName, getName, setName
public Parameter period
public SRDirector() 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 SRDirector(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 SRDirector(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 FixedPointDirector
workspace
- The workspace for the cloned object.java.lang.CloneNotSupportedException
- Not thrown in this base classNamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public Time fireAt(Actor actor, Time time, int microstep) throws IllegalActionException
fireAt
in class Director
actor
- The actor scheduled to be fired.time
- The requested time.microstep
- The microstep (ignored by this director).IllegalActionException
- If the operation is not
permissible (e.g. the given time is in the past).Director.fireAtCurrentTime(Actor)
,
Director.fireContainerAt(Time)
public Time getModelNextIterationTime() throws IllegalActionException
getModelNextIterationTime
in class FixedPointDirector
IllegalActionException
- If time objects cannot be created.Director.getModelTime()
public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class FixedPointDirector
IllegalActionException
- If the superclass throws it.public double periodValue() throws IllegalActionException
periodValue
in interface PeriodicDirector
IllegalActionException
- If the period parameter
cannot be evaluatedpublic boolean prefire() throws IllegalActionException
prefire
in interface Executable
prefire
in class FixedPointDirector
IllegalActionException
- If the period
parameter cannot be evaluated.public boolean postfire() throws IllegalActionException
If the period parameter is greater than 0.0, then if this director is at the top level, then increment time by the specified period, and otherwise request a refiring at the current time plus the period.
postfire
in interface Executable
postfire
in class FixedPointDirector
IllegalActionException
- If the iterations or
period parameter does not contain a legal value.