Reputation: 310
I have multiple parameters named in the same convention, e.g.
parameter
par_1_1 /1/
par_1_2 /2/
par_2_1 /3/
par_2_2 /4/
;
I want to define a macro, which will be replaced (based on the input) by the identifier, e.g.
$macro f(x) (x_1_1)
and use it in my program, e.g.
variable x;
x.lo = -1000;
x.up = 1000;
$macro f(x) (x_1_1)
parameter
par_1_1 /1/
par_1_2 /2/
par_2_1 /3/
par_2_2 /4/
;
variable obj; equation eqobj; eqobj.. obj =e= x;
equation eqcon; eqcon.. x =l= f3(par);
model mod /all/;
solve mod minimizing obj using minlp;
Unfortunaly, this is not working because gams will consider x_1_1
as an (undefined) symbol.
Is there any way to accomplish this?
Upvotes: 0
Views: 30
Reputation: 2292
Not sure, if I got it exactly right, what you want to do, but does this work?
variable x;
x.lo = -1000;
x.up = 1000;
$macro f(x,y) par_&x&_&y
parameter
par_1_1 /1/
par_1_2 /2/
par_2_1 /3/
par_2_2 /4/
;
variable obj; equation eqobj; eqobj.. obj =e= x;
equation eqcon; eqcon.. x =l= f(1,2);
model mod /all/;
solve mod minimizing obj using minlp;
Upvotes: 1