SOLVE statement in a loop

Archive of Gamsworld Google Group
Post Reply
Archiver
User
User
Posts: 7876
Joined: 7 years ago

SOLVE statement in a loop

Post by Archiver »



Dear friends,

I am writing a program in GAMS, in which I need to change a parameter to a certain range, and for each value of this parameter i am evaluating results.
For this sensitivity analysis is it possible to use solve statement in a loop, so that for each input I can get results.
--
With Regards,

Parul Mathuria
Research Scholar



--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: SOLVE statement in a loop

Post by Archiver »


Well yes this is indeed quite simple.
Define a set which will be the loop index -- for instance

SET ITER /i01 * i10/;" for 10 iterations.

Define the values of your parameter in some data structure indexed over "ITER"

PARAMETER MYDATA(..., ITER)

(where ... represent whatever indices you need in your model)
and define a parameter structure which will be able to "host" the results :

PARAMETER MYRESULTS(..., ITER)

Then you just need to use something like:

loop (iter,
modeldata(...) = mydata(..., iter) ;
solve mymodel using ... minimising ... ;
myresults(..., iter) = X.l(...) ;
);

where "modeldata" is the parameter you want to change in your model, and "X" is the name of the variable you want to keep track of.
Hope this helps
cheers


Le mercredi 10 octobre 2012 11:13:28 UTC+2, parul mathuria a écrit :


Dear friends,

I am writing a program in GAMS, in which I need to change a parameter to a certain range, and for each value of this parameter i am evaluating results.
For this sensitivity analysis is it possible to use solve statement in a loop, so that for each input I can get results.
--
With Regards,

Parul Mathuria
Research Scholar



--
To view this discussion on the web visit https://groups.google.com/d/msg/gamswor ... 53XwosttMJ.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: SOLVE statement in a loop

Post by Archiver »


thanks a lot for your help. it works for my model.



On Thu, Oct 11, 2012 at 12:53 PM, Dax wrote:

Well yes this is indeed quite simple.
Define a set which will be the loop index -- for instance

SET ITER /i01 * i10/;" for 10 iterations.

Define the values of your parameter in some data structure indexed over "ITER"

PARAMETER MYDATA(..., ITER)

(where ... represent whatever indices you need in your model)
and define a parameter structure which will be able to "host" the results :

PARAMETER MYRESULTS(..., ITER)

Then you just need to use something like:

loop (iter,
modeldata(...) = mydata(..., iter) ;
solve mymodel using ... minimising ... ;
myresults(..., iter) = X.l(...) ;
);

where "modeldata" is the parameter you want to change in your model, and "X" is the name of the variable you want to keep track of.
Hope this helps
cheers


Le mercredi 10 octobre 2012 11:13:28 UTC+2, parul mathuria a écrit :


Dear friends,

I am writing a program in GAMS, in which I need to change a parameter to a certain range, and for each value of this parameter i am evaluating results.
For this sensitivity analysis is it possible to use solve statement in a loop, so that for each input I can get results.
--
With Regards,

Parul Mathuria
Research Scholar



--
To view this discussion on the web visit https://groups.google.com/d/msg/gamswor ... 53XwosttMJ.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.




--
With Regards,

Parul Mathuria
Research Scholar


--
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.
kathely
User
User
Posts: 1
Joined: 4 years ago

Re: SOLVE statement in a loop

Post by kathely »

Dear all,

I need to do exactly the same (to check how the solution of a system changes with changes in a parameter), I did exactly what Dax suggested, but it turns out that, though my code runs without problems, the reported results for all the iterations are the corresponding to the system evaluated just with the first value (in the index) assigned to my parameter. I don´t really find out what the problem is. Does any of you have an idea about what could be going wrong with my code??

In advance, thank you all very much for your help.


Regards,
Kathia
achristensen
User
User
Posts: 18
Joined: 4 years ago
Location: Fairfax, VA

Re: SOLVE statement in a loop

Post by achristensen »

I suspect that you might not be redefining your original parameter within the loop

something like:

PARAMETER sample(iter);
*create some fake parameter to sample from
sample(iter) = uniform(0,1);

loop(iter,
my_original_parameter = sample(iter);
SOLVE my model....
);

does that help?
best,
adam
Post Reply