1. Running a solution

Top  Previous  Next

In this tutorial we show how to work with SIMPLACE using the Eclipse IDE. Both ModelSolution and SimulationProject are defined in separate XML files and can be executed by a java application or a unit test which are defined in java files (e.g. file.java). Please note that we often say 'run a solution' as an abbreviation for running a simulation defined by the ModelSolution XML file.

 

So let's run our first SIMPLACE solution.

 

To run our first example you should open Eclipse and navigate to the java file:

simplace_modules/runs/net/simplace/sim/runs/training/WorkingWithSolutions/Run_01_FirstSolution.java

To run java application, right click on the and run the "Run_01_FirstSolution.java " and choose "Run As -> Java Application" (See details and screenshot below)

 

version 4_1

Fig. For running a Java Application: open Eclipse -> open Package Explorer window -> go to simplace_modules/runs/net/simplace/sim/runs/training/WorkingWithSolutions/Run_01_FirstSolution.java

-> right click over the file Run As -> Java Application.

 

This will run the simulation defined by the ModelSolution in the XML file "01_FirstSolution.sol.xml" that is located in "simplace_modules\test\training\solution\1_WorkingWithSolutions" folder. The output of the the simulation can be found in "simplace_modules\output\training\simple1.txt". Please note that as we use relative paths, you can also access these files directly on your file explorer. It should be located in the _WORKDIR_ directory defined when configuring Eclipse. For simplace_portable_v5.0, it should be the same directory where the package is located.

 

In the running process some information will pop up on the Console window of Eclipse. It indicates that the simulations are being executed showing information, warnings and sometimes error messages. It's always recommended to check the Console window of Eclipse for any errors or important warnings during the execution of your simulations. More information and tips on how to handle simulation errors are provided on Error Handling topic.

 

 

consoleEclipse

 

 

Now let's explore a bit more the java application file that we just executed. Double-click the Run_01_FirstSolution.java file to open it in Eclipse:

 

clip0022

 

 

This application contains:

The java class named Run_01_FirstSolution that contains a main method that takes a string variable as argument (String[] args)

In the main method the name of the ModelSolution and its full path are declared in string variables tSolutionName and tSolutionFileName

The tSolutionFileName is then passed to the command runSimulation(tSolutionFileName)which executes SIMPLACE using the provided ModelSolution

The setUp() command just define the standard messaging information and other paths (e.g. output) and the exit() command end the java application

It also imports the java class net.simplace.sim.runs.ModulesStandardRun (e.g. Line 3) and extends it to the Run_01_FirstSolution class (e.g. Line 5)

 

 


 

How to run your own solution?

 

To run your own solution, you have to create a new java application file containing the java class containing the method where the ModelSolution file name is declared and passed to SIMPLACE. This new Java class can be created by two methods:

 

1.Navigate to 'simplace_modules/runs/net/simplace/sim/runs/training', right click on this folder and select New -> Class (fourth from top). A new tab will appear where you have to give the name of the class. Do not forget to check the option 'public static void main(String[]args)' under the  option 'Which method stubs would you like to create?'. Press finish to complete the process.

 

clip0023

 

Now open the new java application file (double-click) and include:

The import net.simplace.sim.runs.ModulesStandardRun

Extend it to the new java class (e.g. extends ModulesStandardRun)

Declare the filename and commands to run the ModelSolution in the main(String[] args) class. You can just copy from an existing example (e.g. Run_01_FirstSolution) and modify the filename of your desire.

Save the file

Done. After these steps the java application can also be executed like for Run_01_FirstSolution.java (right-click "Run As -> Java Application")

 

clip0024

 

 

 

2.Another way is to simply copy an existing java application file, paste it with a different name and edit it just like in method 1. Taking Run_01_FirstSolution.java as example in Eclipse:

 

Right-click on the Run_01_FirstSolution.java file and select 'copy'

Then right-click on the location you want to place the new java copied file (lets use the same location 'WorkingWithSolutions') and select 'paste'

This will open a dialog window prompting for the name of the new java class (provide a unique name, e.g. MyFirstJavaApp2)

 

clip0025

 

Now you can just change the variables filename of your desired solution as in method 1

Save the file

Done. After these steps the java application can also be executed like for Run_01_FirstSolution.java (right-click "Run As -> Java Application")

 

 

IMPORTANT: Please note that the file name and the java class name must be same (e.g. MyFirstJavaApp.java and public class MyFirstJavaApp), otherwise Eclipse will automatically flag an error. Always pay attention to these flags as they are very helpful to finding the misspelling errors:

 

clip0026

 

 

 

As we progress with this training you will see that it is also possible to run simulation for more than one ModelSolution at a time (See Task 2) using this method. Accordingly, you also have to change the solution file content as per your simulation from this directory.

 

 


 

 

Now try out the below tasks to test your knowledge for this topic

 

Task 1. Create a new java application to run the ModelSolution defined in simplace_modules\test\training\solution\02_StartEndDates.sol.xml.

Then try to create a new method in the existing Class and again run the same solution file.

 

 Hints:

      - Have you created the new class in this folder: simplace_modules/runs/net/simplace/sim/runs/training ?

  - Have you changed the variable name with the solution that you want run?

        - Is the path to the solution file correct?

  - Does the name of the main class and java file match?

        - Do you run it as a Java Application?

 

Task 2. (Optional) Try to create more than one variable using the same method and run the solution again.

 

 Hints:

      - You have to keep the remaining code and copy/paste only the variable name (String tSolutionFileName) and the setup commands.

  - Change the tSolutionFileName in the copied codes for both main method and runSimulation command according to the solution you want to check.

  - Do not forget to define the new path for the solution file.

 

Solution

   Follow this link.

 

*ModelSolutions are found in simplace_modules\test\training\solution\1_WorkingWithSolutions