Optimisation with JaamSim Models

1,103 views
Skip to first unread message

Harry King

unread,
Jun 8, 2016, 2:54:14 PM6/8/16
to Jaamsim Users Discussion Group
JaamSim Users,

This post is intended to start a discussion on how optimisation should be done with JaamSim models.

Many of the commercial simulation software packages have included an optimisation package such as OptQuest. An integrated optimiser is convenient, but it can easily become a limitation if the optimiser does not provide exactly the capability you want. The approach we would prefer for JaamSim is to let users to select or code their own optimisation software and have that software to launch JaamSim runs and to collect model outputs iteratively. The first step towards this goal was the introduction of the "script" tag ("-s") that allows inputs to be piped to JaamSim on the command line and for JaamSim to return selected outputs back to the command line. A further step in that direction is the "headless" tag ("-h") that allows JaamSim to run on servers with no graphics.

What I would like to see next is a simple demonstration of this arrangement. For example, the model could be a single server with constant service time and Poisson arrivals, and the optimisation problem could be to find the average arrival rate for which the average queue time is equal to the average service time. Since none of the JaamSim team has any professional experience with this type of optimisation, it would be best if the JaamSim users take the lead at this point. We will be happy provide any new features that are required.

Harry

TD

unread,
Jun 9, 2016, 12:59:39 AM6/9/16
to Jaamsim Users Discussion Group
Hi Harry

Thank you for bringing this up, it would be fantastic for JaamSim to have more capability in this space.

I believe the best way to enable this would be an API that would allow a user to control JaamSim directly through Java. Perhaps it is currently possible to include JaamSim as a Java library in your own Java code, but (if it is possible at all) you would need to have knowledge of the source code to control JaamSim. 


I imagine that with an API (or JaamSim library) I would be able to set a model by feeding a function setModel() a .cfg file. This could be your single server model. Then I would be able to call runSimulation(), but I would also be able to adjust the arrival rate.


For instance, something like this:

model.setModel(myCfgFile); // suppose the arrival process is controlled by ExponentialDistribution1 with mean interarrival time equal to 1

simulationOutput1 = model.runSimulation();

model.ExponentialDistribution1.Mean = 2; // change the interarrival mean from 1 to 2

simulationOutput2 = model.runSimulation();


One question is how SimulationOutput objects should look. I am not sure how this is currently done internally, but through it I'd like to be able to get access to the output of ExpressionLoggers and EntityLoggers.


You're probably not able to implement a call such as model.ExponentialDistribution1 since the variable names are not known at compile time. Perhaps you need Maps, I'm not proficient enough with Java to tell.


Anyhow, once this is possible, I can build my own search algorithm to identify the arrival rate with the required properties. (The example you gave doesn't require optimization but it does require a root finding algorithm. In your example I could use Newton-Raphson or bisection.)


One issue with what I have just described is that you'll probably want to allow the user to control the random number generator, so that the user can choose to use common random numbers if desirable.

TD

TD

unread,
Jun 17, 2016, 9:18:13 AM6/17/16
to Jaamsim Users Discussion Group

Hi Harry,

I've given it some more thought.

The following alternative to my previous message:
1) would offer a similar functionality
2) would probably be much less implementation work since it exploits the functionality you've already implemented in the InputAgent class (which is currently hidden for a user)
3) would probably be more user friendly since it uses the same commands as in the model configuration file.

It's probably best to see it in my example: (which I've also cleaned up a bit, the important part is the string that changes the model)

JaamSimModel model = new JaamSimModel(myCfgFile); // suppose the arrival process is controlled by ExponentialDistribution1 with mean interarrival time equal to 1
SimulationOutput simulationOutput1 = new SimulationOutput(model);

model.put("ExponentialDistribution1 Mean { 2  h }") // change the interarrival mean from 1 to 2

SimulationOutput simulationOutput2 = new SimulationOutput(model);


----

Perhaps one could do something similar with the output. (I'm not that familiar with JaamSim output yet.) One could imagine that
simulationOutput1.get("EntityLogger1")
returns an array of doubles with whatever has been recorded by EntityLogger1.

----

It looks like you can control the number generator within the configuration file. In this alternative proposal, unless you change the seed, JaamSim would always work with common random numbers. I'm not sure if that is desirable, this may lead users to use common random numbers without realizing it.

TD

slash...@gmail.com

unread,
Jun 17, 2016, 4:06:45 PM6/17/16
to Jaamsim Users Discussion Group
I think it might be a good idea to list some of the different dimensions along which use cases may vary:

1) Environment of the parent optimizer.
2) Static Experiment vs. Guided Experiment.
3) Proficiency of the user with tools / Time Investment of Learning.
4) Level of automation of optimization applications.
5) Black-box vs White-box optimization.

In the first case, let's consider that users might not want to be limited to Java for their optimization.
One can obtain optimization algorithms in most languages, and some black box optimizers can interact through plug-ins or via the command line.
So a question is to what degree do we want to facilitate users of different systems?
Shelling out to the command line is probably the easiest way to accomodate the use of calling Jaamsim from different systems.
The pros and cons of this are probably worth discussing here.
It goes without saying that the maximum amount of flexibility would come from working with Java Source code directly, or an exposed API.
There are options that fall in the middle, such as Protocol Buffers, allowing communication between different languages. I'd be open to hearing
about other options for inter-process communication, it's not my strong suit.

The second case is whether or not the user knows all of the treatments (scenarios) they want to test in advance.
Full-factorial experiments can be handled by the existing UI, more complicated experimental designs like latin hypercubes may be a little
more challenging to implement. Most optimization, however, requires feedback in the form of results from each treatment to progress efficiently
making it a guided experiment where the treatments can't be specified in advance. Therefore, there needs to be a friendly way to pass inputs and
outputs back and forth between the optimizer and the simulation at regular intervals.

We should also consider that many users who come to Jaamsim are here because it's free and has a friendly GUI and thus doesn't require coding in Java.
Allowing these users to optimize simulations will require some sort of GUI or external pre-packaged scripts with easy input files. This is a good
reason to consider making a Java API that facilitates optimization. It will make optimization easier for those who do code, and possible for those
who don't (provided the API is then consumed by a optimization GUI).

I would speculate that the majority of simulation optimization projects have a person-in-the-loop at least for the early stages,
and so the command line seems sufficient for the situation of a single person tweaking some hyper-parameters and launching the optimizer.
As the project lifecycle continues, some may wish to use Jaamsim as part of a production system where it is run exclusively in batch mode and
acts as a function evaluator. Now we're getting into the realm of data pipelines and servers, and so shelling out to the command line may not be
a good option. Also, I'm not a security specialist but I can guess that if security is a concern that there may be issues there as well at any
point in the project lifecycle.

A final dimension I can think of revolves around how much interaction needs to occur between the optimizer and the simulation.
Most simulation optimization is black-box meaning your optimizer has a set of inputs to vary, receives some output and then has to figure out
how to alter the inputs so as to improve the output. This is just fine for search algorithms. As long as your optimization algorithm is
offline (meaning it only makes decisions when the simulation isn't running) this works. There are however some optimization algorithms that
are online, and these would need a way to be baked right into the simulation. The best way to do this is probably to create a new Jaamsim
object that learns over the course of the simulation.

There are probably other dimensions I haven't thought of. The main question in my mind is which direction should be focused upon first?
I'd encourage anyone who is interested in simulation optimization to weigh-in on where they fit on the spectrum of use cases.

Harry King

unread,
Jun 23, 2016, 11:42:22 PM6/23/16
to Jaamsim Users Discussion Group, slash...@gmail.com
All,

Harvey and I have discussed the idea of an API for JaamSim and we both think it is a good idea. However, it will take a fair amount of work by Harvey to restructure the code to make an API possible, and his time is in short supply these days. My estimate is that an API won't be available until September.

Harry

TD

unread,
Jun 27, 2016, 5:59:52 AM6/27/16
to Jaamsim Users Discussion Group, slash...@gmail.com
The email by slash... is very comprehensive.

In response to your last question, here is where I would be:
- I'd be happy to work with Java. I'm not sure how much extra work it would take to make an API that can work from different programming languages. From my perspective this is not important.
- I'm currently primarily interested in static experiments but I think the ability to interact with JaamSim on a deeper level is important and should eventually be included as part of the API.
- Including optimization in the GUI is also important (although I don't think I would personally use it), but I think the first step should be to build the infrastructure so that people can start building algorithms for JaamSim. A subsequent step is to embed (some of) them in the GUI.
- I've personally never encountered security as a major concern.

TD

Harry King

unread,
Mar 19, 2019, 3:43:25 PM3/19/19
to Jaamsim Users Discussion Group
Ton,

The API discussed in the above posts is available finally in release 2019-03.

Harry

prasa...@gmail.com

unread,
Jun 21, 2019, 12:42:35 PM6/21/19
to Jaamsim Users Discussion Group

Could anyone tell how to access the API?

Message has been deleted

Clever Alves

unread,
Oct 2, 2019, 5:19:33 AM10/2/19
to Jaamsim Users Discussion Group
Hi, Harry!

I've just run into this thread and it's really called my attention...Sorry if I should've created another post though...

"An integrated optimiser is convenient, but it can easily become a limitation if the optimiser does not provide exactly the capability you want" => It could be changed via coding, just as we can change, say, a gate...Couldn't it? I'd love an integrated optimiser...Furthermore, such online optimiser could help make decisions within the simulation...

"let users to select or code their own optimisation software and have that software to launch JaamSim runs and to collect model outputs iteratively" => Is it what the 2019-03's API does (https://groups.google.com/forum/#!searchin/jaamsim-users/release$202019-03%7Csort:date/jaamsim-users/O4BApLMXYpM/uzYEkolLAwAJ)? Any limitation regarding the JaamSim's optimiser/language client?

Would there be any example as to the steps to put this API into practice?

Thank you for your attention.

Regards,

Clever. 

Clever Alves

unread,
Oct 31, 2019, 7:04:14 PM10/31/19
to Jaamsim Users Discussion Group

Good day, Harry! 


I'd appreciate very much if I could receive any feedback from you. 


I'm really interested in combining JaamSim with, say, MILP, and would like to learn more about this API. 


Thank you for your attention. 


Regards, 


Clever.


Harry King

unread,
Nov 1, 2019, 3:17:13 PM11/1/19
to Jaamsim Users Discussion Group
The API gives a programmer the ability to launch one or more JaamSim runs from a wrapper program written in Java. Runs can be performed simultaneously on separate threads if desired.

The API is described in the Release Notes which you can obtain from the 'Downloads' web page. Look for releases 2019-03 and -04. The unit test method 'TestAPI()' in TestSimulation give a simple example of the how the API can be used.

Harry

Clever Alves

unread,
Nov 5, 2019, 2:26:44 AM11/5/19
to Jaamsim Users Discussion Group
Thank you for your reply, Harry!

As far as I could find out at https://jaamsim.com/docs/JaamSim%20Release%20Notes%202019-10.pdf, and based on "ability to launch one or more JaamSim runs from a wrapper program written in Java", my conclusion is that this API has nothing to do with optimisers, does it?

Please, confirm whether my conclusion is correct. This information is very important.

Regards,

Clever.

Harry King

unread,
Nov 6, 2019, 1:41:10 PM11/6/19
to Jaamsim Users Discussion Group
Clever,

The API would allow someone to write an optimizer in Java. That is all.

Harry
Reply all
Reply to author
Forward
0 new messages