Class 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
    • 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 read
        propertyLine - 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.
      • 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.