Package org.hlacerti.lib
Class AutomaticSimulation
- java.lang.Object
-
- ptolemy.actor.gui.ConfigurationApplication
-
- ptolemy.actor.gui.MoMLApplication
-
- ptolemy.vergil.VergilApplication
-
- org.hlacerti.lib.AutomaticSimulation
-
- All Implemented Interfaces:
ExecutionListener
public class AutomaticSimulation extends VergilApplication implements ExecutionListener
Implement an automatic simulation of any model chosen by the user. It allows the change of any parameter, making the values go from a start value to an end value with a fixed increment. The user will be able to choose the models, the parameter and the range during the execution. The parameter to be changed must be specified with exactly the same name in an item parameter in the ptolemy model, otherwise this automatic simulation will not work.- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- Tarciana Cabral de Brito Guerra
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.actor.gui.ConfigurationApplication
ConfigurationApplication.IgnoreErrorHandler
-
-
Field Summary
-
Fields inherited from class ptolemy.vergil.VergilApplication
_commandOptions
-
Fields inherited from class ptolemy.actor.gui.ConfigurationApplication
_basePath, _commandFlagsWithDescriptions, _commandTemplate, _configuration, _exit, _parser, _printPDF, _run, _run20x, _statistics, _test
-
-
Constructor Summary
Constructors Constructor Description AutomaticSimulation(java.lang.String[] args)
Parse the specified command-line arguments, creating models and frames to interact with them.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
changeParameter(int waitingTime, AutomaticSimulation vergil, java.lang.String[] modelPath, java.lang.String propertyLine, double[] values, int solver)
Change a parameter in the .xml, making it assume previously chosen values.static void
changeParameter(int waitingTime, AutomaticSimulation vergil, java.lang.String[] modelPath, java.lang.String propertyLine, float start, float end, float step, int solver)
Change a parameter in the .xml, making it vary within an interval defined by the parameters start and end.static void
changeParameters(int waitingTime, AutomaticSimulation vergil, java.lang.String[] modelPath, java.lang.String[] propertyLines, double[][] values, int solver)
Change a parameter in the .xml, making it vary within an interval defined by the parameters start and end.static java.util.ArrayList<java.lang.String>
convertFileToString(java.io.File file)
Read a file and return the contents as ano ArrayList of Strings.static java.lang.String
findParameterValue(java.io.File file, java.lang.String propertyLine)
Find a parameter value from a file.static void
main(java.lang.String[] args)
The main method.void
managerStateChanged(Manager manager)
Verify if the model is initializing, changing the variable _wait to false if this execution phase has been achieved.static boolean
runAllModels(AutomaticSimulation vergil)
Run all the models.-
Methods inherited from class ptolemy.vergil.VergilApplication
_createDefaultConfiguration, _createEmptyConfiguration, _parseArgs, _usage, errorAndExit, openLibrary
-
Methods inherited from class ptolemy.actor.gui.MoMLApplication
_initializeApplication
-
Methods inherited from class ptolemy.actor.gui.ConfigurationApplication
_configurationUsage, _configurationUsage, _openModel, _openModel, _parseArg, _printPDF, _readConfiguration, closeModelWithoutSavingOrExiting, configurationDirectories, configurationDirectoryFullOrFirst, executionError, executionFinished, getActiveCount, models, openModel, openModelOrEntity, readConfiguration, runModels, setActiveCount, specToURL, throwArgsException, waitForFinish
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.ExecutionListener
executionError, executionFinished
-
-
-
-
Constructor Detail
-
AutomaticSimulation
public AutomaticSimulation(java.lang.String[] args) throws java.lang.Exception
Parse the specified command-line arguments, creating models and frames to interact with them. Look for configurations in "ptolemy/configs"- Parameters:
args
- The command-line arguments.- Throws:
java.lang.Exception
- If command line arguments have problems.
-
-
Method Detail
-
convertFileToString
public static java.util.ArrayList<java.lang.String> convertFileToString(java.io.File file) throws java.io.IOException
Read a file and return the contents as ano ArrayList of Strings.- Parameters:
file
- The file whose content is going to be turned into String.- Returns:
- the ArrayList of Strings.
- Throws:
java.io.IOException
- If there is a problem converting the file to an ArrayList of strings.x
-
findParameterValue
public static java.lang.String findParameterValue(java.io.File file, java.lang.String propertyLine) throws IllegalActionException
Find a parameter value from a file.- Parameters:
file
- The file to be readpropertyLine
- The property line to be found- Returns:
- The parameter value.
- Throws:
IllegalActionException
- If there is a problem reading the property file.
-
changeParameter
public static void changeParameter(int waitingTime, AutomaticSimulation vergil, java.lang.String[] modelPath, java.lang.String propertyLine, double[] values, int solver) throws IllegalActionException
Change a parameter in the .xml, making it assume previously chosen values. Run a ptolemy simulation for each value that the parameter has to assume.- Parameters:
waitingTime
- The time the system will wait to close all the windows of a federation, after its execution has finished. This parameter is intended to give the user the ability to choose how long he will have to look at the simulation's results. If the variable is given a negative value, the user will be asked repetedly if he havalued time to look at the models and they will only close when he answers "yes".vergil
- An instance of vergil.modelPath
- The path to the model you want to run.propertyLine
- The xml line of the parameter that we want to change.values
- The values the new property will assume.solver
- Which RKSolver to use- Throws:
IllegalActionException
- If there is a problem reading a file.
-
changeParameter
public static void changeParameter(int waitingTime, AutomaticSimulation vergil, java.lang.String[] modelPath, java.lang.String propertyLine, float start, float end, float step, int solver) throws IllegalActionException
Change a parameter in the .xml, making it vary within an interval defined by the parameters start and end. Run a ptolemy simulation for each step between the interval.- Parameters:
waitingTime
- The time the system will wait to close all the windows of a federation, after its execution has finished. This parameter is intended to give the user the ability to choose how long he will have to look at the simulation's results. If the variable is given a negative value, the user will be asked repetedly if he had time to look at the models and they will only close when he answers "yes".vergil
- An instance of vergil.modelPath
- The path to the model you want to run.propertyLine
- The xml line of the parameter that we want to change.start
- The value of the parameter.end
- The end value of the parameter.step
- The increment of the parameter value.solver
- Which RKSolver to use- Throws:
IllegalActionException
- If there is a problem reading a file.
-
changeParameters
public static void changeParameters(int waitingTime, AutomaticSimulation vergil, java.lang.String[] modelPath, java.lang.String[] propertyLines, double[][] values, int solver) throws IllegalActionException
Change a parameter in the .xml, making it vary within an interval defined by the parameters start and end. Run a ptolemy simulation for each step between the interval.- Parameters:
waitingTime
- The time the system will wait to close all the windows of a federation, after its execution has finished. This parameter is intended to give the user the ability to choose how long he will have to look at the simulation's results. If the variable is given a negative value, the user will be asked repetedly if he had time to look at the models and they will only close when he answers "yes".vergil
- An instance of vergil.modelPath
- The path to the model you want to run.propertyLines
- The xml line of the parameter that we want to change.values
- The values the new property will assume.solver
- The Runge-Kutta solver order number.- Throws:
IllegalActionException
- If there is a problem reading a file.
-
main
public static void main(java.lang.String[] args)
The main method.- Parameters:
args
- The command-line arguments.
-
managerStateChanged
public void managerStateChanged(Manager manager)
Verify if the model is initializing, changing the variable _wait to false if this execution phase has been achieved.- Specified by:
managerStateChanged
in interfaceExecutionListener
- Overrides:
managerStateChanged
in classConfigurationApplication
- Parameters:
manager
- The manager.- See Also:
ExecutionListener
-
runAllModels
public static boolean runAllModels(AutomaticSimulation vergil)
Run all the models.- Parameters:
vergil
- The script- Returns:
- true if the models complete without throwing an exception.
-
-