Single Element of a Set of a Parameter in a For Statement

Problems with syntax of GAMS
Post Reply
Going
User
User
Posts: 1
Joined: 6 years ago

Single Element of a Set of a Parameter in a For Statement

Post by Going »

Hello,

I have the following problem:
One of my defined parameters is as follows:
F(i) /a=1, b=2/
Later I would like to run my model for different values of F("a").
So far I have modelled that in the following way which leads to errors:

file output /output.dat/;
for(F("a") = 1 to 10 by 1,
put output;
solve Model1 using mcp;
put "F" F("a"):10:3/;
);

If I try that with a scalar instead of a parameter, it works.

I tried to model that in another way which works neither:

parameter
FIX
file output /output.dat/;
for(FIX = 1 to 10 by 1,
put output;
solve Model1 using mcp;
FIX = F("a");
put "F" FIX:10:3/;
);

Thanks for your help!

Kind regards,
Going
User avatar
dirkse
Moderator
Moderator
Posts: 214
Joined: 7 years ago
Location: Fairfax, VA

Re: Single Element of a Set of a Parameter in a For Statement

Post by dirkse »

A common way to implement what you ask about - solves for different scenarios or data values - is to set up a loop over the scenarios you want to consider. In the loop, assign scenario values to the parameters used in the model, solve, and extract results to a parameter indexed by the scenario set. There are many examples for this in the model library: senstran is one that might be helpful to you.

A little code might also help:

set s 'scenarios' / s1 * s3 /;
parameter inputPar(s) / s1 1, s2, 3.5, s3 10 /;
parameters out1(s), out2(s,j) 'assuming j is used in the model';
loop {s,
F('a') = inputPar(s);
solve model1 using mcp;
out1(s) = xxx('a');
out2(s,j) = www(j);
};

HTH,

-Steve
Post Reply