public class CausalityInterfaceForComposites extends DefaultCausalityInterface
Modifier and Type | Field and 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).
|
_actor, _backwardPrunedDependencies, _defaultDependency, _delayDependencies, _EMPTY_COLLECTION, _forwardPrunedDependencies
Constructor and Description |
---|
CausalityInterfaceForComposites(Actor actor,
Dependency defaultDependency)
Construct a causality interface for the specified actor.
|
Modifier and Type | Method and 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.
|
_growDependencies, declareDelayDependency, getActor, getDefaultDependency, toString
protected long _actorDepthVersion
protected java.util.Map<Actor,java.lang.Integer> _actorToDepth
protected long _dependencyVersion
protected java.util.Map<IOPort,java.util.Collection<IOPort>> _equivalenceClasses
protected java.util.Map<IOPort,java.util.Map<IOPort,Dependency>> _forwardDependencies
protected java.util.Map<IOPort,java.util.Map<IOPort,Dependency>> _reverseDependencies
public CausalityInterfaceForComposites(Actor actor, Dependency defaultDependency) throws java.lang.IllegalArgumentException
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.java.lang.IllegalArgumentException
- If the actor parameter is not
an instance of CompositeEntity.public void checkForCycles() throws IllegalActionException
IllegalActionException
- If a cycle is found.public java.util.Collection<IOPort> dependentPorts(IOPort port) throws IllegalActionException
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)
and equivalentPorts(IOPort)
to be consistent.
dependentPorts
in interface CausalityInterface
dependentPorts
in class DefaultCausalityInterface
port
- The port to find the dependents of.IllegalActionException
- Not thrown in this base class.public java.lang.String describeDepths() throws IllegalActionException
IllegalActionException
- If there is a causality loop.getDepthOfActor(Actor)
,
getDepthOfPort(IOPort)
public java.util.Collection<IOPort> equivalentPorts(IOPort input) throws IllegalActionException
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.
equivalentPorts
in interface CausalityInterface
equivalentPorts
in class DefaultCausalityInterface
input
- The port to find the equivalence class of.IllegalActionException
- If the argument is not
contained by the associated actor.public Dependency getDependency(IOPort input, IOPort output) throws IllegalActionException
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.
getDependency
in interface CausalityInterface
getDependency
in class DefaultCausalityInterface
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.IllegalActionException
- Not thrown in this base class.public int getDepthOfActor(Actor actor) throws IllegalActionException
actor
- An actor whose depth is requested.IllegalActionException
- If the actor is not within
the associated actor.getDepthOfPort(IOPort)
public int getDepthOfPort(IOPort ioPort) throws IllegalActionException
ioPort
- A port whose depth is requested.IllegalActionException
- If the ioPort does not have
a depth (this should not occur if the ioPort is under the control
of this director).getDepthOfActor(Actor)
public void invalidate()
public void removeDependency(IOPort inputPort, IOPort outputPort)
equivalentPorts(IOPort)
and
dependentPorts(IOPort)
.removeDependency
in interface CausalityInterface
removeDependency
in class DefaultCausalityInterface
inputPort
- The input port.outputPort
- The output port that does not depend on the
input port.getDependency(IOPort, IOPort)
public java.util.List<Actor> topologicalSort() throws IllegalActionException
CompositeEntity.deepEntityList()
.
This method always creates a new list.IllegalActionException
- If a cycle is found.protected void _computeActorDepth() throws IllegalActionException
IllegalActionException
- If a zero-delay loop is found.