How to call a optimization solver

467 views
Skip to first unread message

Andres Felipe Osorio Muriel

unread,
Mar 6, 2017, 7:53:23 AM3/6/17
to Jaamsim Users Discussion Group
Hello,

In one of my models, I have to call a solver (Gurobi) to solve an optimization problem and return the results into the simulation. This has to be repeated each day in the simulation horizon. I wonder which is the easiest way to call the solver library from JaamSim, do I need to run the model using the Java interface? Or this can be done in some way in the graphical interface?. I would appreciate your comments.

Best wishes,

Andres

Mark

unread,
Mar 6, 2017, 10:35:53 AM3/6/17
to Jaamsim Users Discussion Group
This is not something that can be done yet from the GUI. 
Like you, the ability to run a simulation that includes a nested, dynamically-generated optimization problem is on my wish list for JaamSim.
If you know the structure of your optimization problem in advance, you could probably build it as part of an object using the Gurobi Java interface, and then populate it with values from the simulation.
In your case, it sounds like you have a natural boundary at the end of each day, so the optimizer object would just be an entity created every day.
If you look at the existing programming manual you can probably figure out how to trigger the optimization on entity creation or at an event.  
I am not aware of any examples that show how to do this, so you will largely be on your own - but I'd love to see what you come up with.
It might be that you will require functionality that doesn't exist yet, such as the improved JaamSim API that the devs are currently working on.
This API should make it a lot easier for power-users to push the limits of what JaamSim can do.
The easiest case would be if you can run the optimization separate from the simulation model, and then just pass the results as input parameters.
I don't know if you can break your simulation into single-day pieces.  If so, you could run 1 day, get the results, run the optimizer, and then hand in the solution as the input values for the next simulation for the next day.

Andres Felipe Osorio Muriel

unread,
Mar 8, 2017, 9:49:04 AM3/8/17
to Jaamsim Users Discussion Group
Dear Mark, 

Thank you so much for your comments. I will explore both options, creating an object from Java and trying to run the models separately. In any case I will let you know the results.

Best wishes,

Andres

dylan...@gmail.com

unread,
Apr 4, 2017, 7:56:48 AM4/4/17
to Jaamsim Users Discussion Group
I am considering using Jaamsim for a research project on simulation optimization. Is there any documentation regarding your suggested approach (it would be important to process outputs and adjust inputs during run-time)?:

Mark

unread,
Apr 4, 2017, 8:14:10 AM4/4/17
to Jaamsim Users Discussion Group, dylan...@gmail.com
There's nothing yet on doing the optimization itself; that can come in many different forms and is left to the user.
However, you can interact with JaamSim via the command line between each replication or batch of replications, interpret the results, and then execute a new treatment.
This gives you the maximum possible control.
For the time being you're probably best creating your experimental setup in another language that facilitates the optimizer, such as Python, R, etc.
You can then call JaamSim from a sub-process and pass it command line arguments - the command line arguments part is documented.

Note: Everything I've mentioned is for offline optimization.  If you want to do online optimization, you'll have to work with the source code and create JaamSim objects.

dylan...@gmail.com

unread,
Apr 4, 2017, 8:35:03 AM4/4/17
to Jaamsim Users Discussion Group, dylan...@gmail.com
Thank you for the swift response! Offline optimization would suffice as the real optimization part would happen between replications/batch of replications. So as long as it would be easy to retrieve outputs and give new inputs it would suit my purpose.

Arnaldo Matute

unread,
Apr 26, 2018, 12:40:56 PM4/26/18
to Jaamsim Users Discussion Group
Hi Mark, Hi everyone,

I am assessing JaamSim for modelling but I know here will be a demand of optimization in the project I am working on.
Can I build a model in JaamSim and then take it to R, GAMS, Gurobi or OptQuest for optimization?
Is the output model's format of JaamSim compatible with R? GAMS, Gurobi, OptQuest?

Thanks!

Arnaldo

Mark

unread,
Apr 26, 2018, 12:59:16 PM4/26/18
to Jaamsim Users Discussion Group
Yes, JaamSim is a generic discrete event simulation package, so you can definitely do black-box (simulation) optimization easily.
Tell me a little more about the nature of your project (system description, decision variables, objective function) and I'll try to assess the suitability.

Arnaldo Matute

unread,
Apr 26, 2018, 3:04:23 PM4/26/18
to Jaamsim Users Discussion Group
Hi Mark,

Thanks for the good news.
My project is about the modeling, simulation and optimization of the supply chain of a fertilizer factory where port operations are also taken into account. Statistical fitting of inputs are also part of it. The client has not told me yet about the decision variables and objective functions but thet are interesting in free software options for the project since they are reluctant to invest in a licence of ProModel, FlexSim, Arena or SIMIO. I'm thinking of using R or Octave for statistical fitting and JaamSim for modeling and that's why I was wondering about utilizing also R (or Octave) for optimizing the model that could come out of JaamSim.

Thanks for your advice.

Arnaldo 

Mark

unread,
Apr 26, 2018, 3:48:36 PM4/26/18
to Jaamsim Users Discussion Group
Sounds like you are on the right track.  You can build your input analysis (distribution fitting, etc) in an R script and your experiment design / optimization oracle, launch JaamSim as an external process from R handing it command line arguments (there's a section in the documentation on how to run multiple JaamSim replications in batch mode).  You can configure the output to include just the decision variables and objective function value, parse that into R, rinse and repeat.  Gurobi just released version 8 which makes its R interface near as extensive as the other languages, so that should no longer limit you.
Reply all
Reply to author
Forward
0 new messages