1. Run a solution with different values |
Top Previous Next |
In the previous section you learned how to use ModelSolutions, now we'll see how to execute one ModelSolution multiple times changing some variables via SimulationProject.
In the first task for creating a project we will use the following approach:
- we define each run and its parameters in a file (in our case a text file).
- then we configure a SimulationProject to read this file as an <interface> and <resource>
- the resource id names in the SimulationProject must match the name of the variables in the target ModelSolution
- then they can be executed together, with either a unittest or java application:
package net.simplace.sim.runs.training.WorkingWithProjects;
import net.simplace.sim.runs.ModulesStandardRun;
public class Run_01_Project_DifferentValues extends ModulesStandardRun
{
public static void main(String[] args)
{
String tSolutionFileName = "${_WORKDIR_}/training/solution/2_WorkingWithProjects/01_DifferentValues.sol.xml";
String tProjectFileName = "${_WORKDIR_}/training/project/Project1.proj.xml";
setUp();
showMessage("Starting: Simple Project.");
runSimulation(tSolutionFileName, tProjectFileName);
showMessage("Finished Run: Simple Project.");
exit();
}
}
Note that now we provide both the names of the ModelSolution and SimulationProject in the command runSimulation(tSolutionFileName, tProjectFileName);
Task 1.1 Run solution simplace_modules/test/training/solution/2_WorkingWithProjects/01_DifferentValues.sol.xml with 4 different values of STTIME, DOYEM, IRRIGF and WSO, which are defined in simplace_modules/test/training/data/lintul2/runs.txt.
- Create a SimulationProject XML file with two interfaces (one for the project data file runs.txt and one for output files).
<filename>${_WORKDIR_}/training/data/lintul2/runs.txt</filename>
- Add a resource with all variables that are used in the file runs.txt.
<resource id="projectdata" interface="projectdatafile">
<header>
<var id="projectid" datatype="CHAR" key="projectid" />
<var id="simulationname" datatype="CHAR" key="simulationname" />
<var id="vLocation" datatype="CHAR" />
<var id="startdate" datatype="DATE" />
<var id="enddate" datatype="DATE" />
<var id="vSTTIME" datatype="INT" />
<var id="vDOYEM" datatype="INT" />
<var id="vIRRIGF" datatype="DOUBLE" />
<var id="vControlWSO" datatype="DOUBLE" />
</header>
</resource>
- At the beginning of the variable declaration(creation) section also add two variables with keys(one for projectid and one for simulationname, see above).
Hints
- Put all variables in between <projects><resource><header>...</header></resource></projects> tags.
- Variable for the projectid would look like <var id="projectid" datatype="CHAR" key="projectid">
Solution
Open the simplace_modules/test/training/project/Project1.proj.xml to see how it should be done.
Task 1.2 Create a JUnit test using the simplace_modules/test/training/solution/2_WorkingWithProjects/01_DifferentValues.sol.xml solution and
simplace_modules/test/training/project/Project1.proj.xml
Run created test to see the results.
Hints
- Initialize new variable, e.g.: String tProjectFileName = "${_WORKDIR_}/training/project/Project1.proj.xml";
- Dont forget to prescribe the tProjectFileName
Solution
Open simplace_modules\unittest\net\simplace\sim\tests\training\RunProj.java to see how it should be done.
*SimulationProjects are found in simplace_modules\test\training\solution\2_WorkingWithProjects