Generate Java code from Jaamsim .cfg file

573 views
Skip to first unread message

Utsav Naha

unread,
Jun 22, 2016, 1:37:47 AM6/22/16
to Jaamsim Users Discussion Group
Hi,
Is there a way to generate a Java code from a Jaamsim .cfg file.
And is there a command which can be used to directly simulate a given model, from an editor like Eclipse?
Thanks,
Utsav

Harry King

unread,
Jun 22, 2016, 2:05:48 AM6/22/16
to Jaamsim Users Discussion Group
Utsav,

All the objects in JaamSim are compiled already. When you build a model by drag and drop, you are creating instances of the various object classes and then populating them with inputs. No compilation is involved.

It sounds like you are familiar with AnyLogic software which requires a model to be compiled before it can be executed. In my opinion, this is a big negative because it is quite possible to get compilation errors and/or software crashes with this system.

Use Eclipse if you want to build new objects for JaamSim by writing your own code. You can execute JaamSim from Eclipse, but this is necessary only for testing new code.

Harry

Utsav Naha

unread,
Jun 22, 2016, 2:22:21 AM6/22/16
to Jaamsim Users Discussion Group


Thanks Harry,
  What I actually wanted to do is to vary the parameters of my model, and then simulate them. For example, say in a resource, I want the number of units varied within a range, or the service time of a server to be varied in a range of discrete values, and then compare the outputs. But for that, I would have to manually change the model parameters every time in the .cfg file, and if i could do it, with a for loop, it would have been easier. Is there a method for this?
Utsav

Harry King

unread,
Jun 22, 2016, 12:46:19 PM6/22/16
to Jaamsim Users Discussion Group
Utsav,

Yes, you can set your model inputs to perform multiple runs in the way you describe. This feature is described in Section 13.5 "Performing Multiple Runs" in the User Manual. You can find an example of this feature in under "Examples of JaamSim Objects (v2016-12)" on the Downloads page of the website. Look for the input file "Multiple Runs Example.cfg". 

Let me know if you have any difficulties using this feature.

Harry

Utsav Naha

unread,
Jun 23, 2016, 3:45:31 AM6/23/16
to Jaamsim Users Discussion Group

Hi,
Thanks a lot for this help. But, I have another doubt, like for example, is there a way in which some stopping condition can be imposed, like I want to stop the simulation if some attribute value exceeds some amount. Is it possible to impose such a condition?

Utsav Naha

unread,
Jun 23, 2016, 7:50:37 AM6/23/16
to Jaamsim Users Discussion Group


Hi Harry,
Basically what I want to do is after building a model, and choosing some initial conditions, I want to vary those initial conditions using some external optimiser so that I would be able to optimise certain outputs which I require. But, the parameters within the simulator can be changed using only the arguments such as RunNumber, RunIndex, which are initially specified. Is there a way to change the parameters by taking input from an external source after each run, and then run the model multiple times, each time taking the input through the external source. Like, for example the initial parameters are say [1,1,1], and the external optimiser recommends that the next set of inputs be [1.1,0.9,1], and I want to feed those new values to the initial parameters of the simulation.
Thanks,
Utsav

mark

unread,
Jun 23, 2016, 8:06:53 AM6/23/16
to Jaamsim Users Discussion Group
This gets at some of the issues I brought up in this thread as well:

https://groups.google.com/forum/#!topic/jaamsim-users/-4eurpVqQeQ

If you know the different values you want to test in advance (static experiment), you can setup JaamSim to test these different values through the GUI interface. Also, you can setup a .cfg file to specify your baseline values, and then use separate files to identify just the differences in values you want to use in each treatment of your experiment.

On the other hand, if you don't know the next set of parameter values you want to try until you get the results from the current set of parameter values, then you're talking about a guided experiment. Perhaps you just want to explore the results space, spending more time in areas with lots of non-linearity for finer resolution; or perhaps you are optimizing.

The other part of your question is about the method of varying parameters. You can currently hand parameters to JaamSim from the command line. This allows you to program your loop in whatever language you want. It sounds like your preference would be to work from your IDE in Java though.

Utsav Naha

unread,
Jun 24, 2016, 1:55:57 AM6/24/16
to Jaamsim Users Discussion Group, slash...@gmail.com
Hi Mark,
Thanks for the suggestion. As I have used JaamSim to have multiple runs on my model, and it looks like I can provide the different parameters to different inputs in some order. For example, I can set a server time to be of different values using [Simulation].RunIndex() or [Simulation].RunNumber() arguments, which changes the values in some sort of defined progression. Is it possible to take the inputs from a pre-defined array, such as A = [1 3 6 11], and if I want to do the multiple simulation runs by changing one of parameter by taking values from the array A, such as ServiceTime = A[Simulation.RunIndex(1)], is it possible to have such a configuration.
And can you please shed some more light on how to hand parameters to JaamSim from the command line, like the specific commands, or something. It would be helpful.
Thanks,
Utsav

Harry King

unread,
Jun 24, 2016, 1:22:47 PM6/24/16
to Jaamsim Users Discussion Group, slash...@gmail.com
Utsav,

JaamSim does not support vector valued attributes yet. We are working on this as part of a larger upgrade of the expression system. To select from a sequence values, use the choose function in an expression. For example, for example you could enter

   choose(RunIndex(1), 1, 3, 6, 11)

To pass parameters through the command line, use the -s tag and pipe the parameters in configuration file format to JaamSim. Outputs are then piped out of JaamSim. See Section 13.9 of the user manual for details. An example was given in the post for release 2016-07. Please note the posts following this one regarding the minus sign character which can cause problems.

Harry

Utsav Naha

unread,
Jul 1, 2016, 1:01:36 AM7/1/16
to Jaamsim Users Discussion Group, slash...@gmail.com


Harry,
Thanks for the help. The multiple simulations are a huge help. But, is there a method on how to run a .cfg file on the jaamsim.exe from eclipse. Like, is there a command to make it happen or something?
Thanks,
Utsav

Harry King

unread,
Jul 1, 2016, 8:13:02 PM7/1/16
to Jaamsim Users Discussion Group, slash...@gmail.com
Utsav,

You can run JaamSim through Eclipse by simply downloading the code files from GitHub and setting up a project in Eclipse. See the Programming Manual for details on how to set up the Eclipse project.

However, what I think you want to do is to run JaamSim from an external program. This will require an API for JaamSim which we haven't added yet. See the discussion entitled "Optimisation with JaamSim Models" for more information on our plans.

Harry

Utsav Naha

unread,
Jul 4, 2016, 1:31:28 AM7/4/16
to Jaamsim Users Discussion Group, slash...@gmail.com

Harry,
I have downloaded the code from GitHub, and am able to launch the jaamsim.exe from eclipse. Is there any example codes on how to write the code for a model, like is it possible to write a code for a simple Generator - Server - Sink model in eclipse, and run it from there, instead of using the GUI?
Thanks,
Utsav

Utsav Naha

unread,
Jul 4, 2016, 2:18:15 AM7/4/16
to Jaamsim Users Discussion Group, slash...@gmail.com


Also, if I already have a .cfg file made, is there a way to run it straightaway using eclipse, instead of opening the GUI.
Thanks,
Utsav

Harry King

unread,
Jul 4, 2016, 10:53:00 PM7/4/16
to Jaamsim Users Discussion Group, slash...@gmail.com
Hi Utsav,

Yes, I've recently added an example object called "DemoEntity" that you would help you learn how to code your own objects. See the Release Notes for version 2016-14 for more information. The code is located in the Examples package.

You can load and execute a configuration file directly from the command line. See Section 13.9 in the User Manual.

Harry


Utsav Naha

unread,
Jul 5, 2016, 2:07:32 AM7/5/16
to Jaamsim Users Discussion Group, slash...@gmail.com

Harry,

Could you please help on how to access the Examples package of the latest release. The running from the command prompt is working fine.
Thanks,
Utsav

Harry King

unread,
Jul 5, 2016, 1:04:38 PM7/5/16
to Jaamsim Users Discussion Group, slash...@gmail.com
Utsav,

Just download the latest code from GitHub and look in Eclipse for JaamSim > main > com.jaamsim.Examples > DemoEntity.java for the code. Also, there is an input file under JaamSim > resources > resources.inputs > examples.inc. Edit the examples.inc file and delete the indicated line to allow the DemoEntity and Examples palette to appear in the Model Builder. This will allow you to drag and drop the DemoEntity so that you can see what it does.

If you can't find the resources folder, it is probably because Eclipse needs some additional setup. Follow the instructions in the Programming Manual to set up Eclipse.

Harry

Utsav Naha

unread,
Jul 7, 2016, 5:06:47 AM7/7/16
to Jaamsim Users Discussion Group, slash...@gmail.com
Thanks a lot for the help.
Utsav
Reply all
Reply to author
Forward
0 new messages