How to quickly load data over a loop (different scenarios
How to quickly load data over a loop (different scenarios
Dear Antho,
Please tell me the best answer you find. Many of us would like to do the same problem, something like running a base model, then looping over scenarios, such as
1. Alternative prices
2. Alternative production costs
3. Alternative water supplies/climate scenarios
4. Alternative technical advance possibilities
5. Alternative government policy proposals
Looping over all those sets is a common need many of us have. It lets us find optimized response patterns to a bundle of future uncertainties.
Frank
From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Anthony
Sent: Thursday, February 04, 2016 12:22 PM
To: gamsworld
Subject: How to quickly load data over a loop (different scenarios)???
Dear Gents,
All I need is to run 1000 scenarios on a model with various values for two parameters (a(i) and b(j)) in each run and save the results of each run separately. In need to set a mechanism so that GAMS read and put each row of the parameter in the model in each run and save the results to end.
For example in the Transport example, I need to run the model in 1000 different scenarios (1000 different problem sizes defined in excel rows) with different value for a(i) and b(j) over a loop and save the Z.L to different rows in a spreadsheet.
/////////////////////////////////////////////////////////
a(i) = /
i1 i2 i3
Scenario1 100 200 300
Scenario2 120 240 270
. . .
. . .
. . .
Scenario1000 115 213 310
///////////////////////////////////////////////////////////////////
b(j)
J1 J2 J3
Scenario1 100 200 300
Scenario2 120 240 270
. . .
. . .
. . .
Scenario1000 115 213 310
//////////////////////////////////////////////////////////////////
Consider the code is like below:
Set sc /Scenario1*Scenario1000/
Parameter A(i),B(j), Total_cost;
Equatios;
Objective Max X =z.l;
Cons1.. A(i)x < B(j)
Loop(sc,
A(i) = A(scenario(sc))
B(j) = B(scenario(sc))
Solve model MIP Maximising Total_cost;
Total_cost(sc,"Z.L")=z.l;
);
Putclose;
Display Total_cost;
Execute_Unload "All_scenarios.gdx",Total_cost;
Execute 'GDXXRW.EXE All_scenarios.gdx epsOut=0 par=Total_cost rng=Total_costs!a1 trace=0'
Just wondering how to import each row to the model in each scenario(sc)? Is there any proper trick?
Looking forward to hearing back from you guys.
Cheers,
Antho
--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Re: How to quickly load data over a loop (different scenarios
Reply-to: gamsworld@googlegroups.com
Dear Antho; Dear Frank,
I had very similar problems.
And, Frank, I am exactly working from 3-5 in your list. I am working CGE model.
Amsalu
On Friday, 5 February 2016 18:35:32 UTC+1, Frank Ward wrote:
Dear Antho,
Please tell me the best answer you find. Many of us would like to do the same problem, something like running a base model, then looping over scenarios, such as
1. Alternative prices
2. Alternative production costs
3. Alternative water supplies/climate scenarios
4. Alternative technical advance possibilities
5. Alternative government policy proposals
Looping over all those sets is a common need many of us have. It lets us find optimized response patterns to a bundle of future uncertainties.
Frank
From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of Anthony
Sent: Thursday, February 04, 2016 12:22 PM
To: gamsworld
Subject: How to quickly load data over a loop (different scenarios)???
Dear Gents,
All I need is to run 1000 scenarios on a model with various values for two parameters (a(i) and b(j)) in each run and save the results of each run separately. In need to set a mechanism so that GAMS read and put each row of the parameter in the model in each run and save the results to end.
For example in the Transport example, I need to run the model in 1000 different scenarios (1000 different problem sizes defined in excel rows) with different value for a(i) and b(j) over a loop and save the Z.L to different rows in a spreadsheet.
/////////////////////////////////////////////////////////
a(i) = /
i1 i2 i3
Scenario1 100 200 300
Scenario2 120 240 270
. . .
. . .
. . .
Scenario1000 115 213 310
///////////////////////////////////////////////////////////////////
b(j)
J1 J2 J3
Scenario1 100 200 300
Scenario2 120 240 270
. . .
. . .
. . .
Scenario1000 115 213 310
//////////////////////////////////////////////////////////////////
Consider the code is like below:
Set sc /Scenario1*Scenario1000/
Parameter A(i),B(j), Total_cost;
Equatios;
Objective Max X =z.l;
Cons1.. A(i)x < B(j)
Loop(sc,
A(i) = A(scenario(sc))
B(j) = B(scenario(sc))
Solve model MIP Maximising Total_cost;
Total_cost(sc,"Z.L")=z.l;
);
Putclose;
Display Total_cost;
Execute_Unload "All_scenarios.gdx",Total_cost;
Execute 'GDXXRW.EXE All_scenarios.gdx epsOut=0 par=Total_cost rng=Total_costs!a1 trace=0'
Just wondering how to import each row to the model in each scenario(sc)? Is there any proper trick?
Looking forward to hearing back from you guys.
Cheers,
Antho
--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Dear Antho; Dear Frank,
I had very similar problems.
And, Frank, I am exactly working from 3-5 in your list. I am working CGE model.
Amsalu
On Friday, 5 February 2016 18:35:32 UTC+1, Frank Ward wrote:
Dear Antho,
Please tell me the best answer you find. Many of us would like to do the same problem, something like running a base model, then looping over scenarios, such as
1. Alternative prices
2. Alternative production costs
3. Alternative water supplies/climate scenarios
4. Alternative technical advance possibilities
5. Alternative government policy proposals
Looping over all those sets is a common need many of us have. It lets us find optimized response patterns to a bundle of future uncertainties.
Frank
From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of Anthony
Sent: Thursday, February 04, 2016 12:22 PM
To: gamsworld
Subject: How to quickly load data over a loop (different scenarios)???
Dear Gents,
All I need is to run 1000 scenarios on a model with various values for two parameters (a(i) and b(j)) in each run and save the results of each run separately. In need to set a mechanism so that GAMS read and put each row of the parameter in the model in each run and save the results to end.
For example in the Transport example, I need to run the model in 1000 different scenarios (1000 different problem sizes defined in excel rows) with different value for a(i) and b(j) over a loop and save the Z.L to different rows in a spreadsheet.
/////////////////////////////////////////////////////////
a(i) = /
i1 i2 i3
Scenario1 100 200 300
Scenario2 120 240 270
. . .
. . .
. . .
Scenario1000 115 213 310
///////////////////////////////////////////////////////////////////
b(j)
J1 J2 J3
Scenario1 100 200 300
Scenario2 120 240 270
. . .
. . .
. . .
Scenario1000 115 213 310
//////////////////////////////////////////////////////////////////
Consider the code is like below:
Set sc /Scenario1*Scenario1000/
Parameter A(i),B(j), Total_cost;
Equatios;
Objective Max X =z.l;
Cons1.. A(i)x < B(j)
Loop(sc,
A(i) = A(scenario(sc))
B(j) = B(scenario(sc))
Solve model MIP Maximising Total_cost;
Total_cost(sc,"Z.L")=z.l;
);
Putclose;
Display Total_cost;
Execute_Unload "All_scenarios.gdx",Total_cost;
Execute 'GDXXRW.EXE All_scenarios.gdx epsOut=0 par=Total_cost rng=Total_costs!a1 trace=0'
Just wondering how to import each row to the model in each scenario(sc)? Is there any proper trick?
Looking forward to hearing back from you guys.
Cheers,
Antho
--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
RE: How to quickly load data over a loop (different scenarios
I probably don’t understand but here my input:
If you have the parameter A and B in your excel sheet as you describe, you just load them using gdxxrw into the parameters A0(scenario,i) and B0(scenario,j) and then just use them in the equations accordingly.
Parameter a,b;
Equation Cons1.. Ax
Cc: anthoy.optimizer@gmail.com; fward@nmsu.edu
Subject: Re: How to quickly load data over a loop (different scenarios
Dear Antho; Dear Frank,
I had very similar problems.
And, Frank, I am exactly working from 3-5 in your list. I am working CGE model.
Amsalu
On Friday, 5 February 2016 18:35:32 UTC+1, Frank Ward wrote:
Dear Antho,
Please tell me the best answer you find. Many of us would like to do the same problem, something like running a base model, then looping over scenarios, such as
1. Alternative prices
2. Alternative production costs
3. Alternative water supplies/climate scenarios
4. Alternative technical advance possibilities
5. Alternative government policy proposals
Looping over all those sets is a common need many of us have. It lets us find optimized response patterns to a bundle of future uncertainties.
Frank
From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of Anthony
Sent: Thursday, February 04, 2016 12:22 PM
To: gamsworld
Subject: How to quickly load data over a loop (different scenarios)???
Dear Gents,
All I need is to run 1000 scenarios on a model with various values for two parameters (a(i) and b(j)) in each run and save the results of each run separately. In need to set a mechanism so that GAMS read and put each row of the parameter in the model in each run and save the results to end.
For example in the Transport example, I need to run the model in 1000 different scenarios (1000 different problem sizes defined in excel rows) with different value for a(i) and b(j) over a loop and save the Z.L to different rows in a spreadsheet.
/////////////////////////////////////////////////////////
a(i) = /
i1 i2 i3
Scenario1 100 200 300
Scenario2 120 240 270
. . .
. . .
. . .
Scenario1000 115 213 310
///////////////////////////////////////////////////////////////////
b(j)
J1 J2 J3
Scenario1 100 200 300
Scenario2 120 240 270
. . .
. . .
. . .
Scenario1000 115 213 310
//////////////////////////////////////////////////////////////////
Consider the code is like below:
Set sc /Scenario1*Scenario1000/
Parameter A(i),B(j), Total_cost;
Equatios;
Objective Max X =z.l;
Cons1.. A(i)x < B(j)
Loop(sc,
A(i) = A(scenario(sc))
B(j) = B(scenario(sc))
Solve model MIP Maximising Total_cost;
Total_cost(sc,"Z.L")=z.l;
);
Putclose;
Display Total_cost;
Execute_Unload "All_scenarios.gdx",Total_cost;
Execute 'GDXXRW.EXE All_scenarios.gdx epsOut=0 par=Total_cost rng=Total_costs!a1 trace=0'
Just wondering how to import each row to the model in each scenario(sc)? Is there any proper trick?
Looking forward to hearing back from you guys.
Cheers,
Antho
--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.