ptolemy.actor.util
Class ConstVariableModelAnalysis

java.lang.Object
  extended by ptolemy.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 determines the "least change context" of each dynamic variable. The least change context of a variable is typically an actor that contains that variable. During a firing of the least change context, the variable's value is guaraunteed to not change. This analysis is important for supporting parameter changes in the context of domains that perform scheduling based on parameter values, like SDF and PSDF. The least change context of a PortParameter with an external connection must be a container of the PortParameter. The least change context of a variable assigned by a finite state machine in a modal model must be a 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. Note that in some cases (typically when a variable is modified from multiple sources which are not hierarchically related), no least change context may exist.

Since:
Ptolemy II 4.0
Version:
$Id: ConstVariableModelAnalysis.java 59156 2010-09-21 14:33:12Z cxh $
Author:
Stephen Neuendorffer
Accepted Rating:
Yellow (neuendor)
Proposed Rating:
Yellow (neuendor)

Field Summary
private  DirectedGraph _dependencyGraph
           
private  java.util.Map _variableToChangeContext
           
 
Constructor Summary
ConstVariableModelAnalysis()
          Create a dummy analysis for actors that are not contained in a model.
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
private  void _addDependencyDeclaration(DependencyDeclaration declaration)
           
private  void _analyzeAllVariables()
           
private  void _collectConstraints(NamedObj container)
           
private  void _collectVariableConstraints(Variable variable)
           
private  Entity _computeBound(Entity entity1, Entity entity2)
           
private  Node _getNode(Variable variable)
           
private  boolean _updateChangeContext(Variable variable, Entity changeContext)
           
 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.
 Token getConstantValue(Variable variable)
          Return the constant value of the given parameter, if the parameter is actually constant.
 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 isConstant(Variable variable)
          Return true if the given variable is not reconfigured in the model.
 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
 

Field Detail

_dependencyGraph

private DirectedGraph _dependencyGraph

_variableToChangeContext

private java.util.Map _variableToChangeContext
Constructor Detail

ConstVariableModelAnalysis

public ConstVariableModelAnalysis()
Create a dummy analysis for actors that are not contained in a model.


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.

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

addDependencyDeclaration

public void addDependencyDeclaration(DependencyDeclaration declaration)
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.

Parameters:
declaration - The given dependency declaration.

getAnalysis

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

Parameters:
object - The given object.
Returns:
The active analysis for the given object.
Throws:
IllegalActionException - If an exception occurs during analysis.

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. If the variable is constant, or no change context exists, then return null.

Parameters:
variable - The given variable.
Returns:
The change context of the given variable.

getConstantValue

public Token getConstantValue(Variable variable)
                       throws IllegalActionException
Return the constant value of the given parameter, if the parameter is actually constant.

Parameters:
variable - The given variable.
Returns:
The constant value of the given variable.
Throws:
IllegalActionException - If the given parameter is not a constant parameter, as determined by this analysis.

getConstVariables

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

Parameters:
container - The given container.
Returns:
The computed constant variables.
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.

Returns:
The parameter dependency graph.

getNotConstVariables

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

Parameters:
container - The given container.
Returns:
The computed not constant variables.
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.

Parameters:
container - The given container.
Returns:
The set of variables anywhere in the model that have the given container as least change context.

isConstant

public boolean isConstant(Variable variable)
Return true if the given variable is not reconfigured in the model. The variable is assumed to be contained by the model this analysis was created with.

Parameters:
variable - The given variable.
Returns:
True If the given variable is not reconfigured in the model.

isIndependent

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

Parameters:
variable - The given variable.
Returns:
True If the variable has been analyzed by this analysis and it depends on no other parameters

_addDependencyDeclaration

private void _addDependencyDeclaration(DependencyDeclaration declaration)

_collectVariableConstraints

private void _collectVariableConstraints(Variable variable)

_collectConstraints

private void _collectConstraints(NamedObj container)
                          throws IllegalActionException
Throws:
IllegalActionException

_analyzeAllVariables

private void _analyzeAllVariables()

_getNode

private Node _getNode(Variable variable)

_updateChangeContext

private final boolean _updateChangeContext(Variable variable,
                                           Entity changeContext)

_computeBound

private final Entity _computeBound(Entity entity1,
                                   Entity entity2)