ptolemy.actor.util
Class ConstVariableModelAnalysis

java.lang.Object
  extended byptolemy.actor.util.ConstVariableModelAnalysis

public class ConstVariableModelAnalysis
extends java.lang.Object

An analysis that traverses a model to determine all the constant variables in a hierarchical model. Basically, a constant variable in a particular model is any variable in the model that is defined by a expression of constants, or any variable that is defined by an expression of constants and identifiers that reference other constant variables.

This class computes the set of constant variables by computing the set of variables that are not constant and then performing the complement. This is somewhat easier to compute. The computation is performed in two passes, the first of which extracts the set of variables which must be not-constant either by not being evaluatable, by inclusion in an initial set, by virtue of being a PortParameter with an external connection, or by assignment from within a modal model. The second pass collects all the variables which are not constant because they depend on other variables which are not constant. This class also recognizes dependence declarations represented by the DependencyDeclaration class.

This class also keeps track of the "change context" of each dynamic variable. The change context of a variable is an actor that contains that variable. During a firing of the actor, the variable's value should not change. This is important for supporting parameter changes in the context of domains that perform scheduling based on parameter values, like SDF. The change context of a PortParameter with an external connection is the container of the PortParameter. The change context of a variable assigned by a finite state machine in a modal model is the container of the finite state machine. The change context of asserted not constant variables and variables with no expression are assumed to be the toplevel of the model.

Since:
Ptolemy II 4.0
Version:
$Id: ConstVariableModelAnalysis.java,v 1.28.2.1 2004/07/29 13:25:14 eal Exp $
Author:
Stephen Neuendorffer
Accepted Rating:
Yellow (neuendor)
Proposed Rating:
Yellow (neuendor)

Constructor Summary
ConstVariableModelAnalysis(Entity model)
          Analyze the given model to determine which variables must be constants and which variables may change dynamically during execution.
ConstVariableModelAnalysis(Entity model, java.util.Set variableSet)
          Analyze the given model to determine which variables must be constants and which variables may change dynamically during execution, given that all variables in the given set may change dynamically.
 
Method Summary
 void addDependencyDeclaration(DependencyDeclaration declaration)
          Add the information in the given dependency declaration to the dependence graph of this analysis.
static ConstVariableModelAnalysis getAnalysis(NamedObj object)
          Return the analysis that is active for the given object.
 Entity getChangeContext(Variable variable)
          Return the change context of the given variable.
 java.util.Set getConstVariables(NamedObj container)
          Return the computed constant variables for the given container.
 DirectedGraph getDependencyGraph()
          Return the parameter dependency graph constructed through this analysis.
 java.util.Set getNotConstVariables(NamedObj container)
          Return the computed not constant variables for the given container.
 java.util.Set getVariablesWithChangeContext(NamedObj container)
          Return the set of variables anywhere in the model that have the given container as least change context.
 boolean isIndependent(Variable variable)
          Return true if the variable has been analyzed by this analysis and it depends on no other parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConstVariableModelAnalysis

public ConstVariableModelAnalysis(Entity model)
                           throws IllegalActionException
Analyze the given model to determine which variables must be constants and which variables may change dynamically during execution. In addition, store the intermediate results for contained actors so they can be retrieved by the getConstVariables() method.

Parameters:
model - The model to be analyzed.
Throws:
IllegalActionException - If an exception occurs during analysis.

ConstVariableModelAnalysis

public ConstVariableModelAnalysis(Entity model,
                                  java.util.Set variableSet)
                           throws IllegalActionException
Analyze the given model to determine which variables must be constants and which variables may change dynamically during execution, given that all variables in the given set may change dynamically. In addition, store the intermediate results for contained actors so they can be retrieved by the getConstVariables() method.

Throws:
IllegalActionException - If an exception occurs during analysis.
Method Detail

addDependencyDeclaration

public void addDependencyDeclaration(DependencyDeclaration declaration)
                              throws IllegalActionException
Add the information in the given dependency declaration to the dependence graph of this analysis. This method can be called by users of this class to update the analysis without recomputing all of the information from scratch.

Throws:
IllegalActionException

getAnalysis

public static ConstVariableModelAnalysis getAnalysis(NamedObj object)
                                              throws IllegalActionException
Return the analysis that is active for the given object.

Throws:
IllegalActionException

getChangeContext

public Entity getChangeContext(Variable variable)
Return the change context of the given variable. This an actor containing the variable, such that the variable is guaranteed not to change values during a firing of the actor.


getConstVariables

public java.util.Set getConstVariables(NamedObj container)
Return the computed constant variables for the given container.

Throws:
java.lang.RuntimeException - If the constant variables for the container have not already been computed.

getDependencyGraph

public DirectedGraph getDependencyGraph()
Return the parameter dependency graph constructed through this analysis.


getNotConstVariables

public java.util.Set getNotConstVariables(NamedObj container)
Return the computed not constant variables for the given container.

Throws:
java.lang.RuntimeException - If the constant variables for the container have not already been computed.

getVariablesWithChangeContext

public java.util.Set getVariablesWithChangeContext(NamedObj container)
Return the set of variables anywhere in the model that have the given container as least change context.


isIndependent

public boolean isIndependent(Variable variable)
Return true if the variable has been analyzed by this analysis and it depends on no other parameters.