ptolemy.moml.unit
Class Solution

java.lang.Object
  extended by ptolemy.moml.unit.Solution

public class Solution
extends java.lang.Object

An instance of this class contains a "solution" of Unit constraints. In essence, the solution represents the constraints between a set of Unit variables, and a set of Units. The table below illustrates this.

V1 V2 ... Vl
C1 P11 P12 ... P1l U1
C2 P21 P22 ... P2l U2
: : : ... : :
Ck Pk1 Pk2 ... Pkl Uk
Here, the columns V1, V2, ..., Vl represent l variables. The columns C1, C2, ..., Ck represent k constraints. The U1, U2, ..., Uk on the right represent Units. The meaning of the ith row is that V1^Pi1 + V2^pi2 + .. +Vk^pik = Uk.

Generally, this class is used by creating an instance that is derived from the Units specifications of a model. Then, a method is invoked that results in other instances being created that are transformations of the original instance. These transformed instances are equivalent, in a sense, to the original instance. The difference is that they provide a different perspective than that of the original instance. In particular, some of the transformed instances can be used to highlight inconsistencies not apparent in the original instance.

Since:
Ptolemy II 8.0
Version:
$Id: Solution.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Rowland R Johnson
Accepted Rating:
Red (rowland)
Proposed Rating:
Red (rowland)

Nested Class Summary
private static class Solution.Index
          Class that represents an index in the P array.
 
Field Summary
(package private)  double[][] _arrayP
           
(package private)  Solution.Index _branchPoint
           
(package private)  java.util.Vector _branchPoints
           
private static int _CONSISTENT
           
(package private)  java.lang.String[] _constraintExplanations
           
(package private)  java.util.Vector _constraints
           
(package private)  int[] _constraintState
           
(package private)  boolean _debug
           
(package private)  boolean[] _done
           
private static int _INCONSISTENT
           
(package private)  TypedCompositeActor _model
           
private static int _NONUNIQUE
           
(package private)  int _numConstraints
           
(package private)  int _numVariables
           
private static java.text.DecimalFormat _pFormat
           
private  int _solveState
           
(package private)  NamedObj[] _source
           
(package private)  java.lang.String _stateDescription
           
private static int _UNKNOWN
           
(package private)  Solution _upper
           
(package private)  java.lang.String[] _varBindings
           
(package private)  java.lang.String[] _variables
           
(package private)  int[] _varState
           
(package private)  Unit[] _vectorA
           
private static java.text.DecimalFormat _vNumFormat
           
 
Constructor Summary
private Solution()
          Construct an empty solution.
  Solution(TypedCompositeActor model, java.lang.String[] vLabels, java.util.Vector constraints)
          Construct a Solution from a set of variables, and a set of constraints.
 
Method Summary
private  void _analyzeState()
           
private  int[] _branchesFrom(Solution.Index g)
           
private  void _checkForInConsistency()
           
private  void _debug(java.lang.String msg)
           
private  void _eliminate(Solution.Index g)
           
private  java.util.Vector _findAllG()
          Finds all Index(i, l) such that P[i][l] !
private  java.util.Vector _findAllGInRows(int[] rows)
           
private  Solution.Index _findG()
          Finds an Index(i, l) such that P[i][l] !
private  Solution.Index _findGInRow(int k)
           
private  java.lang.String _momlAnnotate(NamedObj entity, java.lang.String color, java.lang.String expression)
           
private  java.util.Vector _partialSolveRecursively(int level, Solution.Index g)
           
 void annotateGraph()
          Annotates the model so that when it is displayed it will be color coded and have tooltips that will convey various aspects of the solution.
 Solution completeSolution()
          Search for a complete solution.
 Solution copy()
          Make a copy of this solution.
 java.lang.String getShortStateDesc()
          Get the state of the solution.
 java.lang.String getStateDesc()
          Get the state of the solution.
 java.lang.StringBuffer headerInfo()
          Create a human readable presentation of the parts of the solution that won't change as a result of the operations necessary to carry out the Gaussian elimination.
 java.util.Vector minimalSpanSolutions()
          Produce all of the minimal span solutions that can be generated from this instance.
 java.lang.StringBuffer stateInfo()
          The current state of the solver.
 void trace()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_UNKNOWN

private static final int _UNKNOWN
See Also:
Constant Field Values

_CONSISTENT

private static final int _CONSISTENT
See Also:
Constant Field Values

_INCONSISTENT

private static final int _INCONSISTENT
See Also:
Constant Field Values

_NONUNIQUE

private static final int _NONUNIQUE
See Also:
Constant Field Values

_arrayP

double[][] _arrayP

_branchPoint

Solution.Index _branchPoint

_branchPoints

java.util.Vector _branchPoints

_constraints

java.util.Vector _constraints

_constraintExplanations

java.lang.String[] _constraintExplanations

_constraintState

int[] _constraintState

_debug

boolean _debug

_done

boolean[] _done

_model

TypedCompositeActor _model

_numConstraints

int _numConstraints

_numVariables

int _numVariables

_pFormat

private static final java.text.DecimalFormat _pFormat

_solveState

private int _solveState

_source

NamedObj[] _source

_stateDescription

java.lang.String _stateDescription

_upper

Solution _upper

_varBindings

java.lang.String[] _varBindings

_variables

java.lang.String[] _variables

_varState

int[] _varState

_vectorA

Unit[] _vectorA

_vNumFormat

private static final java.text.DecimalFormat _vNumFormat
Constructor Detail

Solution

private Solution()
Construct an empty solution. This constructor is used only by the copy() method, and, can therefore, be made private.


Solution

public Solution(TypedCompositeActor model,
                java.lang.String[] vLabels,
                java.util.Vector constraints)
         throws IllegalActionException
Construct a Solution from a set of variables, and a set of constraints.

Parameters:
model - The model that is the source of the variables and constraints.
vLabels - The variables.
constraints - The constraints.
Throws:
IllegalActionException - If there are problems with transforming a constraint to canonical form.
Method Detail

annotateGraph

public void annotateGraph()
Annotates the model so that when it is displayed it will be color coded and have tooltips that will convey various aspects of the solution.


completeSolution

public Solution completeSolution()
Search for a complete solution.

Returns:
The solution.

copy

public Solution copy()
Make a copy of this solution.

Returns:
The copy.

getShortStateDesc

public java.lang.String getShortStateDesc()
Get the state of the solution.

Returns:
The state of the solution.

getStateDesc

public java.lang.String getStateDesc()
Get the state of the solution.

Returns:
The state of the solution.

headerInfo

public java.lang.StringBuffer headerInfo()
Create a human readable presentation of the parts of the solution that won't change as a result of the operations necessary to carry out the Gaussian elimination. I.e. the variable names, and the constraints.

Returns:
A StringBuffer with a human readable presentation of the invariant parts of the solution.

minimalSpanSolutions

public java.util.Vector minimalSpanSolutions()
Produce all of the minimal span solutions that can be generated from this instance. A minimal span solution is one in which a minimal number of constraints that are connected yield an inconsistency.

Returns:
The vector of minimal span solutions.

stateInfo

public java.lang.StringBuffer stateInfo()
The current state of the solver. A StringBuffer is produced that shows the variables, done vector, P array, and A vector in a human readable arrangement.

Returns:
A StringBuffer with the state of the solver.

trace

public void trace()

_analyzeState

private void _analyzeState()

_branchesFrom

private int[] _branchesFrom(Solution.Index g)

_checkForInConsistency

private void _checkForInConsistency()

_debug

private void _debug(java.lang.String msg)

_eliminate

private void _eliminate(Solution.Index g)
Parameters:
g -

_findAllG

private java.util.Vector _findAllG()
Finds all Index(i, l) such that P[i][l] != 0 and 1) all other P in row i is equal to 0

Returns:
Index(i, l)

_findAllGInRows

private java.util.Vector _findAllGInRows(int[] rows)
Parameters:
rows -
Returns:
A vector of Indexes.

_findG

private Solution.Index _findG()
Finds an Index(i, l) such that P[i][l] != 0 and 1) all other P in row i is equal to 0

Returns:
Index(i, l)

_findGInRow

private Solution.Index _findGInRow(int k)

_momlAnnotate

private java.lang.String _momlAnnotate(NamedObj entity,
                                       java.lang.String color,
                                       java.lang.String expression)

_partialSolveRecursively

private java.util.Vector _partialSolveRecursively(int level,
                                                  Solution.Index g)