hSimulator.library
Class SimulatedTS

java.lang.Object
  extended by hSimulator.library.SimulatedTS
All Implemented Interfaces:
Serializable, Cloneable

public class SimulatedTS
extends Object
implements Serializable, Cloneable

This object implements an optimized data structures for storing simulated time series.

Version:
1.0
Author:
Luca Marchetti
See Also:
Serialized Form

Constructor Summary
SimulatedTS(Model model, int tMax, double timeSampling)
          Constructs a new object.
SimulatedTS(Model model, List<String> varsToBeSaved, int tMax, double timeSampling)
          Constructs a new object.
 
Method Summary
 void clear()
          Clears the object.
 SimulatedTS clone()
          Clones the time series.
 void exportToExcel(String fileName)
          Exports the time series in an Excel document.
 void exportToTxt(String fileName)
          Exports the time series in a txt document.
static SimulatedTS getAveragedDynamics(SimulatedTS[] dynamics, boolean roundToInteger)
          Returns a time series of averaged values.
 double getComputationTime()
          Returns the time (in seconds) spent for computing the stored time series.
 double[][] getDynamicsTs()
          Returns a matrix storing the time series of the system dynamics.
 double[] getDynamicsTs(String varID)
          Returns an array storing the time series of the dynamics of a specified variable.
 double getFirstTimeInstant()
          Returns the first time instant stored in the object.
 double[] getInitialState()
          Returns the initial (first) system state stored in the object.
 double[] getLastState()
          Returns the last system state stored in the object.
 double getLastTimeInstant()
          Returns the last time instant stored in the object.
 List<String> getSavedVariables()
          Returns the list of variable IDs whose time series are stored in the object (in the corresponding order).
 org.jfree.chart.JFreeChart getSimulationPlot(String plotTitle, boolean logScale)
          Returns the plot of the time series stored in the object.
 double[] getState(double time)
          Returns the system state related to the given time instant.
 Iterator<double[]> getStates()
          Returns an iterator providing all the system states stored in the object.
 Iterator<Double> getTimeInstants()
          Returns an iterator providing all the time instants stored in the object.
 double getTimeSampling()
          Returns the time sampling used for storing the time series.
 double[] getTimeTs()
          Returns an array storing the time instants of the time series.
 boolean isEmpty()
          Returns true if the time series stored in the object are empty.
static SimulatedTS loadTimeSeries(String filePath)
          Loads a time series from file.
 void plotSimulation(String windowTitle)
          Plots the time series stored in the object.
 void plotSimulation(String windowTitle, boolean logScale)
          Plots the time series stored in the object.
 void put(double time, double[] state)
          Puts a new state.
 void put(Double time, double[] state)
          Puts a new state.
static void saveTimeSeries(SimulatedTS ts, String filePath)
          Saves a time series to file.
 int size()
          Returns the length of the time series stored in the object.
 int stateSize()
          Returns the number of variables whose time series are stored in the object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimulatedTS

public SimulatedTS(Model model,
                   int tMax,
                   double timeSampling)
Constructs a new object.

Parameters:
model - the model which will be simulated
tMax - maximum time instant that will be stored (the insertion of subsequent time instants will be not optimized)
timeSampling - the time sampling used for storing time series
See Also:
Model

SimulatedTS

public SimulatedTS(Model model,
                   List<String> varsToBeSaved,
                   int tMax,
                   double timeSampling)
Constructs a new object. Variable IDs has to be indicated according to the following notation: variableName + Model.variableCompartmentSeparator + compartmentName.

Parameters:
model - the model which will be simulated
varsToBeSaved - the list of variable IDs whose time series will be stored in the object (in the corresponding order)
tMax - maximum time instant that will be stored (the insertion of subsequent time instants will be not optimized)
timeSampling - the time sampling used for storing time series
See Also:
Model
Method Detail

clear

public void clear()
Clears the object.


clone

public SimulatedTS clone()
                  throws CloneNotSupportedException
Clones the time series.

Overrides:
clone in class Object
Returns:
the cloned time series
Throws:
CloneNotSupportedException

getTimeSampling

public double getTimeSampling()
Returns the time sampling used for storing the time series.

Returns:
the time sampling

getSavedVariables

public List<String> getSavedVariables()
Returns the list of variable IDs whose time series are stored in the object (in the corresponding order). Variable IDs are indicated according to the following notation: variableName + Model.variableCompartmentSeparator + compartmentName.

Returns:
the list of variable IDs

getComputationTime

public double getComputationTime()
Returns the time (in seconds) spent for computing the stored time series.

Returns:
the computation time in seconds

stateSize

public int stateSize()
Returns the number of variables whose time series are stored in the object.

Returns:
the number of variables

put

public void put(Double time,
                double[] state)
Puts a new state.

Parameters:
time - time instant
state - system state that has to be stored

put

public void put(double time,
                double[] state)
Puts a new state.

Parameters:
time - time instant
state - system state that has to be stored

size

public int size()
Returns the length of the time series stored in the object.

Returns:
the length of the time series

isEmpty

public boolean isEmpty()
Returns true if the time series stored in the object are empty.

Returns:
a boolean indicating if time series are empty

getTimeInstants

public Iterator<Double> getTimeInstants()
Returns an iterator providing all the time instants stored in the object.

Returns:
the iterator

getStates

public Iterator<double[]> getStates()
Returns an iterator providing all the system states stored in the object.

Returns:
the iterator

getLastState

public double[] getLastState()
Returns the last system state stored in the object.

Returns:
the last state (null if the data structure is empty)

getInitialState

public double[] getInitialState()
Returns the initial (first) system state stored in the object.

Returns:
the initial state (null if the data structure is empty)

getState

public double[] getState(double time)
Returns the system state related to the given time instant. If the required state is not stored in the object, the code calculates it by means of linear interpolation.

Parameters:
time - the time instant of the required system state
Returns:
the required system state (null in case of error)

getFirstTimeInstant

public double getFirstTimeInstant()
Returns the first time instant stored in the object.

Returns:
the first time instant (-1 if the data structure is empty)

getLastTimeInstant

public double getLastTimeInstant()
Returns the last time instant stored in the object.

Returns:
the last time instant (-1 if the data structure is empty)

getTimeTs

public double[] getTimeTs()
Returns an array storing the time instants of the time series.

Returns:
the array of time instants (null if the data structure is empty)

getDynamicsTs

public double[][] getDynamicsTs()
Returns a matrix storing the time series of the system dynamics. Each row of the matrix corresponds to a different time instant (in the same order of this.getTimeTs()); each column corresponds to a different system variable (in the same order of this.getSavedVariables()).

Returns:
the matrix storing the dynamics (null if the data structure is empty)

getDynamicsTs

public double[] getDynamicsTs(String varID)
Returns an array storing the time series of the dynamics of a specified variable. Each element of the array corresponds to a different time instant (in the same order of this.getTimeTs()).

Parameters:
varID - the ID of the required variable
Returns:
variable dynamics (null if no variable with the specified ID is stored in the object)

getSimulationPlot

public org.jfree.chart.JFreeChart getSimulationPlot(String plotTitle,
                                                    boolean logScale)
Returns the plot of the time series stored in the object.

Parameters:
plotTitle - the title of the plot
logScale - indicates if the values of the domain axis has to be in log10 scale
Returns:
the plot as an instance of JFreeChart

plotSimulation

public void plotSimulation(String windowTitle)
Plots the time series stored in the object.

Parameters:
windowTitle - the title of the window containing the chart

plotSimulation

public void plotSimulation(String windowTitle,
                           boolean logScale)
Plots the time series stored in the object.

Parameters:
windowTitle - the title of the window containing the chart
logScale - indicates if the values of the domain axis has to be in log10 scale

saveTimeSeries

public static void saveTimeSeries(SimulatedTS ts,
                                  String filePath)
                           throws FileNotFoundException,
                                  IOException
Saves a time series to file.

Parameters:
ts - the SimulatedTS object which needs to be saved
filePath - path pointing out the resource where the time series needs to be saved
Throws:
FileNotFoundException - if the file specified in filePath exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
IOException - if an input/output error occurred while writing the object

loadTimeSeries

public static SimulatedTS loadTimeSeries(String filePath)
                                  throws FileNotFoundException,
                                         IOException,
                                         ClassNotFoundException
Loads a time series from file.

Parameters:
filePath - path pointing out the resource where the time series is saved
Returns:
the loaded SimulatedTS object
Throws:
FileNotFoundException - if the file specified in filePath exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
IOException - if an input/output error occurred while reading the object
ClassNotFoundException - if the object saved in filePath is not a SimulatedTS object

getAveragedDynamics

public static SimulatedTS getAveragedDynamics(SimulatedTS[] dynamics,
                                              boolean roundToInteger)
Returns a time series of averaged values. The computation time of the averaged time series is set to the median of the computation times of each time series provided in dynamics.

Parameters:
dynamics - array of time series that has to be averaged
roundToInteger - boolean indicating if variable averaged values have to be rounded to integers
Returns:
an object storing the average of the provided time series

exportToTxt

public void exportToTxt(String fileName)
                 throws IOException
Exports the time series in a txt document. Data are formatted TAB spaced.

Parameters:
fileName - the name of the Excel file to create
Throws:
IOException - if an input/output error occurred during the exportation process

exportToExcel

public void exportToExcel(String fileName)
                   throws IOException
Exports the time series in an Excel document.

Parameters:
fileName - the name of the Excel file to create
Throws:
IOException - if an input/output error occurred during the exportation process