Skip to main content
Solved

how to store solutions in Monte Carlo simulation

  • March 23, 2022
  • 6 replies
  • 147 views

Forum|alt.badge.img+4

Hi, 

I was trying to play around with Monte Carlo simulation in AIMMS. I can save the results from MP.Objective for every run. But, how can I save the solution for every run? I tried to use something like below for every run:

Variable_Result(run, param1, param2) := Variable(param1,param2);

It’s in the procedure “RunMonteCarlo” in the attached file. 

But, it doesn’t work. Any idea?

Thanks,

Zulfan

Best answer by Marcel Hunting

Hi @zulfan.adiputra . It seems that the solution is always the same, expect for the objective variable and the (superfluous) variable TotalCostMC. You can check this by printing the constraint listing plus the variables values by setting the following Solvers General options:

  • 'Constraint Listing' to 'At every solve' (or 'At first solve')
  • 'Constraint Listing Variable Values' to 'Print variable values'

If you change the definition of UnitTransportCostMC to

uniform(0.5,1.5)*UnitTransportCost(p,c);

then the solution will change some times.

6 replies

Marcel Hunting
AIMMSian
Forum|alt.badge.img+4
  • AIMMSian
  • 258 replies
  • March 23, 2022

Hi @zulfan.adiputra , if Variable_Result is a variable then it will be emptied before the next solve (because you defined AllVariables as the set of variables for the mathematical program LeastCostTransportPlan, which includes Variable_Result). There are ways to work around that but better would be to make Variable_Result a parameter.


Forum|alt.badge.img+4
  • Author
  • Enthusiast
  • 14 replies
  • March 24, 2022

Hi Marcel @Marcel Hunting

Thanks for this. Indeed, the “Variable_Result” is a parameter. I wrote it wrongly here. So, for every run, I write: Parameter_Result(run, param1, param2) := Variable(param1, param2).

What’s recorded in the Parameter_Result is only the latest solution from the Variable (repeated for all runs). I was hoping to capture the solutions for each solution. 

 


Marcel Hunting
AIMMSian
Forum|alt.badge.img+4
  • AIMMSian
  • 258 replies
  • Answer
  • March 24, 2022

Hi @zulfan.adiputra . It seems that the solution is always the same, expect for the objective variable and the (superfluous) variable TotalCostMC. You can check this by printing the constraint listing plus the variables values by setting the following Solvers General options:

  • 'Constraint Listing' to 'At every solve' (or 'At first solve')
  • 'Constraint Listing Variable Values' to 'Print variable values'

If you change the definition of UnitTransportCostMC to

uniform(0.5,1.5)*UnitTransportCost(p,c);

then the solution will change some times.


Forum|alt.badge.img+4
  • Author
  • Enthusiast
  • 14 replies
  • March 25, 2022

Hi @Marcel Hunting , so basically what you’re saying is that there is nothing wrong in the code. It’s just the solution is the same for all scenarios. Why didn’t I think of that, hahahaha… thanks a lot


luispinto
AIMMSian
Forum|alt.badge.img+6
  • Customer Success Manager
  • 65 replies
  • March 28, 2022

Hello @zulfan.adiputra 

Not sure if you are working on this locally or on cloud, but if the later, I suggest you read:

 

About breaking up into smaller jobs, which I imagine you do in a MC simulation.

Cheers,


Forum|alt.badge.img+4
  • Author
  • Enthusiast
  • 14 replies
  • March 30, 2022

Thanks @luispinto . This particular exercise is local. But, we’ll do real projects in cloud. 

Thanks



Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator