Class CausalityInterfaceForComposites
- java.lang.Object
-
- ptolemy.actor.util.DefaultCausalityInterface
-
- ptolemy.actor.util.CausalityInterfaceForComposites
-
- All Implemented Interfaces:
CausalityInterface
- Direct Known Subclasses:
FSMCausalityInterface
,MirrorCausalityInterface
,TDLCausalityInterface
public class CausalityInterfaceForComposites extends DefaultCausalityInterface
This class elaborates its base class by providing an algorithm for inferring the causality interface of a composite actor from the causality interfaces of its component actors and their interconnection topology.- Since:
- Ptolemy II 8.0
- Version:
- $Id$
- Author:
- Edward A. Lee
- Pt.AcceptedRating:
- Red (eal)
- Pt.ProposedRating:
- Yellow (eal)
-
-
Field Summary
Fields Modifier and Type Field Description protected long
_actorDepthVersion
Workspace version when actor depth was last computed.protected java.util.Map<Actor,java.lang.Integer>
_actorToDepth
A table giving the depths of actors.protected long
_dependencyVersion
The workspace version where the dependency was last updated.protected java.util.Map<IOPort,java.util.Collection<IOPort>>
_equivalenceClasses
Computed equivalence classes of input ports.protected java.util.Map<IOPort,java.util.Map<IOPort,Dependency>>
_forwardDependencies
Computed dependencies between input ports and output ports of the associated actor.protected java.util.Map<IOPort,java.util.Map<IOPort,Dependency>>
_reverseDependencies
Computed reverse dependencies (the key is now an output port).-
Fields inherited from class ptolemy.actor.util.DefaultCausalityInterface
_actor, _backwardPrunedDependencies, _defaultDependency, _delayDependencies, _EMPTY_COLLECTION, _forwardPrunedDependencies
-
-
Constructor Summary
Constructors Constructor Description CausalityInterfaceForComposites(Actor actor, Dependency defaultDependency)
Construct a causality interface for the specified actor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_computeActorDepth()
Compute the depth of ports and actors.void
checkForCycles()
Check the associated composite actor for causality cycles.java.util.Collection<IOPort>
dependentPorts(IOPort port)
Return a collection of the ports in the associated actor that depend on or are depended on by the specified port.java.lang.String
describeDepths()
Return a string that describes the depths of actors and their ports.java.util.Collection<IOPort>
equivalentPorts(IOPort input)
Return a set of the input ports in this actor that are in an equivalence class with the specified input.Dependency
getDependency(IOPort input, IOPort output)
Return the dependency between the specified input port and the specified output port.int
getDepthOfActor(Actor actor)
Return the depth of an actor contained (deeply) by the associated composite actor.int
getDepthOfPort(IOPort ioPort)
Return the depth of a port of the associated actor or an actor contained by it.void
invalidate()
Indicate that the cached causality information is invalid.void
removeDependency(IOPort inputPort, IOPort outputPort)
Remove the dependency that the specified output port has on the specified input port.java.util.List<Actor>
topologicalSort()
Return a list of the actors deeply contained within the associated composite actor sorted by actor depth.-
Methods inherited from class ptolemy.actor.util.DefaultCausalityInterface
_growDependencies, declareDelayDependency, getActor, getDefaultDependency, toString
-
-
-
-
Field Detail
-
_actorDepthVersion
protected long _actorDepthVersion
Workspace version when actor depth was last computed.
-
_actorToDepth
protected java.util.Map<Actor,java.lang.Integer> _actorToDepth
A table giving the depths of actors.
-
_dependencyVersion
protected long _dependencyVersion
The workspace version where the dependency was last updated.
-
_equivalenceClasses
protected java.util.Map<IOPort,java.util.Collection<IOPort>> _equivalenceClasses
Computed equivalence classes of input ports.
-
_forwardDependencies
protected java.util.Map<IOPort,java.util.Map<IOPort,Dependency>> _forwardDependencies
Computed dependencies between input ports and output ports of the associated actor.
-
_reverseDependencies
protected java.util.Map<IOPort,java.util.Map<IOPort,Dependency>> _reverseDependencies
Computed reverse dependencies (the key is now an output port).
-
-
Constructor Detail
-
CausalityInterfaceForComposites
public CausalityInterfaceForComposites(Actor actor, Dependency defaultDependency) throws java.lang.IllegalArgumentException
Construct a causality interface for the specified actor.- Parameters:
actor
- The actor for which this is a causality interface. This is required to be an instance of CompositeEntity.defaultDependency
- The default dependency of an output port on an input port.- Throws:
java.lang.IllegalArgumentException
- If the actor parameter is not an instance of CompositeEntity.
-
-
Method Detail
-
checkForCycles
public void checkForCycles() throws IllegalActionException
Check the associated composite actor for causality cycles. If a cycle is found, throw an exception. This method has as a side effect computing the depths of actors and ports within the composite, so subsequent queries for those depths will be low cost.- Throws:
IllegalActionException
- If a cycle is found.
-
dependentPorts
public java.util.Collection<IOPort> dependentPorts(IOPort port) throws IllegalActionException
Return a collection of the ports in the associated actor that depend on or are depended on by the specified port. A port X depends on a port Y if X is an output and Y is an input and getDependency(X,Y) returns oTimesIdentity() of the default dependency specified in the constructor.This class presumes (but does not check) that the argument is a port contained by the associated actor. If the actor is an input, then it returns a collection of all the outputs. If the actor is output, then it returns a collection of all the inputs.
Derived classes may override this, but they may need to also override
getDependency(IOPort, IOPort)
andequivalentPorts(IOPort)
to be consistent.- Specified by:
dependentPorts
in interfaceCausalityInterface
- Overrides:
dependentPorts
in classDefaultCausalityInterface
- Parameters:
port
- The port to find the dependents of.- Returns:
- a collection of ports that depend on or are depended on by the specified port.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
describeDepths
public java.lang.String describeDepths() throws IllegalActionException
Return a string that describes the depths of actors and their ports.- Returns:
- s string that describes the depths of actors and their ports.
- Throws:
IllegalActionException
- If there is a causality loop.- See Also:
getDepthOfActor(Actor)
,getDepthOfPort(IOPort)
-
equivalentPorts
public java.util.Collection<IOPort> equivalentPorts(IOPort input) throws IllegalActionException
Return a set of the input ports in this actor that are in an equivalence class with the specified input. The returned result includes the specified input port.An equivalence class is defined as follows. If input ports X and Y each have a dependency equal to oTimesIdentity() on any common port or on two equivalent ports or on the state of the associated actor, then they are in an equivalence class. That is, there is a causal dependency. They are also in the same equivalence class if there is a port Z in an equivalence class with X and in an equivalence class with Y. Moreover, if the actor has any instance of ParameterPort among its input ports, then all input ports are in an equivalence class. Otherwise, they are not in the same equivalence class. In this base class, we assume the actor has no state and return the equivalence classes determined only by the common dependence of output ports.
- Specified by:
equivalentPorts
in interfaceCausalityInterface
- Overrides:
equivalentPorts
in classDefaultCausalityInterface
- Parameters:
input
- The port to find the equivalence class of.- Returns:
- set of the input ports in this actor that are in an equivalence class with the specified input.
- Throws:
IllegalActionException
- If the argument is not contained by the associated actor.
-
getDependency
public Dependency getDependency(IOPort input, IOPort output) throws IllegalActionException
Return the dependency between the specified input port and the specified output port. This is done by traversing the network of actors from the input ports. For each output port reachable from an input port, its dependency on the input port is determined by composing the dependencies along all paths from the input port to the output port using oPlus() and oTimes() operators of the dependencies. For any output port that is not reachable from an input port, the dependency on that input port is set to the oPlusIdentity() of the default dependency given in the constructor.When called for the first time since a change in the model structure, this method performs the complete analysis of the graph and caches the result. Subsequent calls just look up the result. Note that the complete analysis can be quite expensive. For each input port, it traverses the graph to find all ports reachable from that input port, and tracks the dependencies. In the worst case, the complexity can be N*M^2, where N is the number of input ports and M is the total number of ports in the composite (including the ports of all contained actors). The algorithm used, however, is optimized for typical Ptolemy II models, so in most cases the algorithm completes in time on the order of N*D, where D is the length of the longest chain of ports from an input port to an output port.
- Specified by:
getDependency
in interfaceCausalityInterface
- Overrides:
getDependency
in classDefaultCausalityInterface
- Parameters:
input
- The input port.output
- The output port, or null to update the dependencies (and record equivalence classes) without requiring there to be an output port.- Returns:
- The dependency between the specified input port and the specified output port, or null if a null output is port specified.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
getDepthOfActor
public int getDepthOfActor(Actor actor) throws IllegalActionException
Return the depth of an actor contained (deeply) by the associated composite actor. The depth of an actor is the minimum depth of the output ports. If there are no output ports, then the depth of the actor is the maximum depth of the input ports. If there are no input ports or output ports, the depth is zero.- Parameters:
actor
- An actor whose depth is requested.- Returns:
- An integer indicating the depth of the given actor.
- Throws:
IllegalActionException
- If the actor is not within the associated actor.- See Also:
getDepthOfPort(IOPort)
-
getDepthOfPort
public int getDepthOfPort(IOPort ioPort) throws IllegalActionException
Return the depth of a port of the associated actor or an actor contained by it. The depth of an output port is the maximum of the depth of all the input ports it directly depends on, or zero if there are no such input ports. The depth of an input port is maximum of the "source depths" of all the input ports in the same equivalence class with the specified port. The "source depth" of an input port is one plus the maximum depth of all output ports that directly source data to it, or zero if there are no such ports.- Parameters:
ioPort
- A port whose depth is requested.- Returns:
- An integer representing the depth of the specified ioPort.
- Throws:
IllegalActionException
- If the ioPort does not have a depth (this should not occur if the ioPort is under the control of this director).- See Also:
getDepthOfActor(Actor)
-
invalidate
public void invalidate()
Indicate that the cached causality information is invalid.
-
removeDependency
public void removeDependency(IOPort inputPort, IOPort outputPort)
Remove the dependency that the specified output port has on the specified input port. Specifically, calling this method ensures that subsequent calls to getDependency(inputPort, outputPort) will return defaultDependency.oPlusIdentity(). It also adjusts what is returned byequivalentPorts(IOPort)
anddependentPorts(IOPort)
.- Specified by:
removeDependency
in interfaceCausalityInterface
- Overrides:
removeDependency
in classDefaultCausalityInterface
- Parameters:
inputPort
- The input port.outputPort
- The output port that does not depend on the input port.- See Also:
getDependency(IOPort, IOPort)
-
topologicalSort
public java.util.List<Actor> topologicalSort() throws IllegalActionException
Return a list of the actors deeply contained within the associated composite actor sorted by actor depth. For actors that have the same depth, the ordering is the order returned byCompositeEntity.deepEntityList()
. This method always creates a new list.- Returns:
- A sorted list of actors.
- Throws:
IllegalActionException
- If a cycle is found.
-
_computeActorDepth
protected void _computeActorDepth() throws IllegalActionException
Compute the depth of ports and actors. The actor depth is typically used to prioritize firings in response to pure events (fireAt() calls). The port depth is used to prioritize firings due to input events. Lower depths translate into higher priorities, with the lowest value being zero. The depth of an actor is the minimum depth of the output ports. This typically causes the actor to fire as early as possible to produce an output on those output ports in response to a pure event, but no earlier than the firings of actors that may source it data that the firing may depend on. If there are no output ports, then the depth of the actor it is the maximum depth of the input ports. This typically delays the response to fireAt() until all input events with the same tag have arrived. If there are no input ports or output ports, the depth is zero.- Throws:
IllegalActionException
- If a zero-delay loop is found.
-
-