tenua.simulator
Class Mechanism

java.lang.Object
  extended by tenua.simulator.AbstractDataGenerator
      extended by tenua.simulator.Mechanism
All Implemented Interfaces:
java.lang.Runnable, DataGenerator

public class Mechanism
extends AbstractDataGenerator

a class that simulates a set of chemical reactions

Author:
Daniel Wachsstock

Nested Class Summary
 
Nested classes/interfaces inherited from interface tenua.simulator.DataGenerator
DataGenerator.Listener
 
Field Summary
static java.lang.String CHEMICAL_RATES
           
static java.lang.String OUTPUTS
           
static java.lang.String PARAMETERS
           
static java.lang.String RATE_CONSTANTS
           
static java.lang.String SPECIES
           
static java.lang.String TIME_CONSTANTS
           
 
Constructor Summary
Mechanism(java.util.Hashtable variableNames, Expression calculations, Expression derivativeCalculations, SymbolTable st, bsh.Interpreter interpreter)
          Creates a new instance of Mechanism
 
Method Summary
 DoubleBean doubleBean(java.lang.String name)
          creates a #util.DoubleBean for a variable
 java.lang.Object eval(java.lang.String s)
          executes a string in the mechanism's interpreter.
 java.lang.Object get(java.lang.String name)
          returns the value of a variable in this mechanism or its script interpreter.
 int getCount()
          Get the number of times the simulation has been run with goSimulate() since creation.
 double getInitial(java.lang.String name)
          returns the initial value of a variable in this mechanism.
 double getLatest(java.lang.String name)
          returns the most recently determined value of a variable in this mechanism.
 java.lang.Object getMemento()
          returns the current state of the simulation.
 java.lang.String getMinimizer()
          returns the name of the current minimization algorithm.
 java.lang.String getSolver()
          returns the name of the current ODE solver.
 void goSimulate()
          actually runs the simulation; called by the interpreter
 void goVarying(int n, java.lang.String[] names)
          runs the simulation while varying a given list of variables, multiple times.
 void goVarying(java.lang.String[] names)
          runs the simulation while varying a given list of variables.
 void put(java.lang.String name, double d)
          assigns a value to a variable
 void put(java.lang.String name, java.lang.Object o)
          assigns a value to a variable
 void putInitial(java.lang.String name, double d)
          assigns a value to use for the initial value for a variable.
 void putLatest(java.lang.String name, double d)
          assigns a value to a variable.
 void renameOutput(int i, java.lang.String newName)
          Renames an output datum.
 void resetVariables()
          Resets all the variables' initial values to their default values.
 void setMinimizer(java.lang.String name)
          Set the minimization algorithm.
 void setSolver(java.lang.String name)
          set the ODE solver to use.
 void start(java.lang.Object memento)
          generates data by calling script() in the interpreter, which generally calls goSimulate().
 java.util.List variableNames(java.lang.String listName)
          returns a List of the names of all the variables defined of a given type.
 
Methods inherited from class tenua.simulator.AbstractDataGenerator
addListener, getNames, removeListener, run
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIME_CONSTANTS

public static final java.lang.String TIME_CONSTANTS

SPECIES

public static final java.lang.String SPECIES

RATE_CONSTANTS

public static final java.lang.String RATE_CONSTANTS

CHEMICAL_RATES

public static final java.lang.String CHEMICAL_RATES

PARAMETERS

public static final java.lang.String PARAMETERS

OUTPUTS

public static final java.lang.String OUTPUTS
Constructor Detail

Mechanism

public Mechanism(java.util.Hashtable variableNames,
                 Expression calculations,
                 Expression derivativeCalculations,
                 SymbolTable st,
                 bsh.Interpreter interpreter)
Creates a new instance of Mechanism

Method Detail

start

public void start(java.lang.Object memento)
generates data by calling script() in the interpreter, which generally calls goSimulate().

Specified by:
start in interface DataGenerator
Overrides:
start in class AbstractDataGenerator
Parameters:
memento - the VariableMemento to use. If null, ignored

goSimulate

public void goSimulate()
                throws java.lang.InterruptedException,
                       java.lang.NoSuchMethodException,
                       java.lang.InstantiationException,
                       java.lang.IllegalAccessException
actually runs the simulation; called by the interpreter

Throws:
java.lang.InterruptedException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.IllegalAccessException

goVarying

public void goVarying(java.lang.String[] names)
runs the simulation while varying a given list of variables.

Parameters:
names - the array of variable names to vary On return, the initial variables will be set such that the variables named minimize the script function called fitFunction(), which should return a double.

goVarying

public void goVarying(int n,
                      java.lang.String[] names)
               throws bsh.EvalError
runs the simulation while varying a given list of variables, multiple times.

Parameters:
names - the array of variable names to vary On return, the initial variables will be set such that the variables named minimize the script function called fitFunction(), which should return a double. Also, a double array parameters is created in the interpreter such that parameters[i][j] is the value of the jth variable after the ith run. Also, double arrays mean, stddev and stddev1 are created, such than mean[j] is the mean of the jth variable in all the runs, stddev[j] is the standard deviation, and stddev1[j] is the standard deviation assuming that parameters[0] is the true value of the variables. This would be the case if the first run fit to the actual data and the other runs fit to simulated or selected data.
Throws:
bsh.EvalError

renameOutput

public void renameOutput(int i,
                         java.lang.String newName)
Renames an output datum.

Parameters:
i - the index of the output to change
newName - the name to change to Does nothing if the name is not found

getMemento

public java.lang.Object getMemento()
returns the current state of the simulation.

Specified by:
getMemento in interface DataGenerator
Overrides:
getMemento in class AbstractDataGenerator
Returns:
a memento of the simulation's state

getSolver

public java.lang.String getSolver()
returns the name of the current ODE solver.

Returns:
the name

setSolver

public void setSolver(java.lang.String name)
set the ODE solver to use. The names "fast", "normal" and "stiff" are guaranteed to be defined

Parameters:
name - the name of the ODE solver
Throws:
java.lang.IllegalArgumentException - if the name is undefined

getMinimizer

public java.lang.String getMinimizer()
returns the name of the current minimization algorithm.

Returns:
the name

setMinimizer

public void setMinimizer(java.lang.String name)
Set the minimization algorithm. Does no error checking now; it will throw IllegalArgumentException when we call goVarying if the name is invalid.

Parameters:
name - the name of the minimizer

doubleBean

public DoubleBean doubleBean(java.lang.String name)
creates a #util.DoubleBean for a variable

Parameters:
name - the name of the variable
Throws:
java.lang.IllegalArgumentException - if name is not a variable
java.lang.ClassCastException - if name does not evaluate to a number

get

public java.lang.Object get(java.lang.String name)
                     throws java.lang.IllegalArgumentException
returns the value of a variable in this mechanism or its script interpreter.

Parameters:
name - the name of the variable to search for
Returns:
the value. For mechanism variables, returns the value in the current run if we are running; otherwise the initial value.
Throws:
java.lang.IllegalArgumentException - if name is not found

getInitial

public double getInitial(java.lang.String name)
                  throws java.lang.IllegalArgumentException
returns the initial value of a variable in this mechanism.

Parameters:
name - the name of the variable to search for
Returns:
the value in the initial memento
Throws:
java.lang.IllegalArgumentException - if name is not found

getLatest

public double getLatest(java.lang.String name)
                 throws java.lang.IllegalArgumentException
returns the most recently determined value of a variable in this mechanism.

Parameters:
name - the name of the variable to search for
Returns:
the value in the most recent memento if we are running
Throws:
java.lang.IllegalArgumentException - if name is not found

put

public void put(java.lang.String name,
                double d)
assigns a value to a variable

Parameters:
name - the name of the variable to seach for
d - the value to assign. For mechanism variables, uses the most recent memento if we are running; otherwise the initial memento. Any name not defined in the mechanism is assumed to be defined in the script interpreter.
Throws:
java.lang.IllegalArgumentException - if name is not found

put

public void put(java.lang.String name,
                java.lang.Object o)
assigns a value to a variable

Parameters:
name - the name of the variable to seach for
o - the value to assign. For mechanism variables, uses the most recent memento if we are running; otherwise the initial memento. Any name not defined in the mechanism is assumed to be defined in the script interpreter.
Throws:
java.lang.IllegalArgumentException - if name is not found, or a non-number is assigned to a mechanism variable.

putInitial

public void putInitial(java.lang.String name,
                       double d)
assigns a value to use for the initial value for a variable.

Parameters:
name - the name of the variable to seach for
d - the value to assign. Uses the initial memento.
Throws:
java.lang.IllegalArgumentException - if name is not found

putLatest

public void putLatest(java.lang.String name,
                      double d)
assigns a value to a variable.

Parameters:
name - the name of the variable to seach for
d - the value to assign. Uses the most recent memento
Throws:
java.lang.IllegalArgumentException - if name is not found

resetVariables

public void resetVariables()
Resets all the variables' initial values to their default values.


variableNames

public java.util.List variableNames(java.lang.String listName)
returns a List of the names of all the variables defined of a given type.

Parameters:
listName - the type of variable to return
Returns:
the List of Strings. Returns an empty List (not null) if the type is not defined or is empty This should be entirely read-only; but that's not enforceable in Java

eval

public java.lang.Object eval(java.lang.String s)
executes a string in the mechanism's interpreter.

Parameters:
s - the String to evaluate
Returns:
the result of the evaluation

getCount

public int getCount()
Get the number of times the simulation has been run with goSimulate() since creation.