Hello everyone,
I hope you’ve had a good start to the week!
I want to incorporate a Monte Carlo Simulation in my linear programming model. Based on the minimum, maximum, alpha and beta values I have created 100 random values for my parameters (A, B, C) in an excel datasheet.
However, I am now struggling to specify the parameters with the 100 random values to subsequently run (loop) the model over 100 iterations (with the different random values for the parameters).
Thank you very much in advance I am thankful for any kind of suggestions!
Enclosed:
- GAMS file Test_model (an
TEST_LP.gms (604 Bytes)
LP model for explanatory reasons)
- Excel file with the 100 random values for parameters A,B,C
Thank you very much!
Best wishes,
Philip
DATA_model.xlsx (26.4 KB)
You need to work with scalars in the equation algebra and copy the content of A(iter), etc into the scalars. Also this is not an LP. EFG is clearly non-linear. For all iterations the optimal solution is 0, but that’s besides the point. You asked for the technique. I have attached the modified model.
-Michael
TEST_LP.gms (851 Bytes)
Dear Michael,
Thank you very much for your help! It’s well appreciated! Yes, indeed the model was rubbish and more for the purpose to understand how to do it. I’ve tried to implement the technique in an actual LP model but now I run into the problem of getting error messages concerning the indices in the loop statement (as now variables are also controlled by sets). I don’t know how to specify for example land within the loop in a way I don’t receive the error code 148.
rep(iter,'land') = land.l;
Thank you very much in advance!
allocation of land to crops_test.gms (2.77 KB)
The Excel input file stays the same.
Best wishes,
Philip
land is an indexed variable, i.e. land(i), so you either make a secondary report that is indexed with i, i.e. repi(iter,‘land’,i) = land.l(i) or add an index to the current rep, i.e. rep(iter,‘land’,i) = land.l(i) and rep(iter,‘prof’,‘’) = prof.l;
-Michael
Dear Michael,
Thank you very much for your suggestions! The issues with the indices in the loop file are gone now. However, I am stuck now assigning the random values for each iteration to the parameters. I assume they are not loaded correctly as the GDX file looks alright to me (enclosed) but when displaying the parameter A,B,C they are all zero.
Also when I use the
$loaddc
I get the error message 649 domain violation when loading from gdx file. Do you have an idea of how to fix that?
Thank you again for your help!
Best wishes,
Philip
DATA_model.xlsx (24.4 KB)
DATA_model.gdx (4.14 KB)
TEST_LP.gms (911 Bytes)