Reputation: 215
Sets
i / 1, 2 /;
Parameters
j(i) / 2, 1 /;
Variables
x(i);
So, here I have an index i, a parameter that depends on i which gives the same values as i, and a variable that depends on x.
If I want to get x(2), I could of course write x(2), but what if I wanted to write x(j(1)). Since j(1) = 2, this ought to be the same, but GAMS doesn't like it, and says it expected a set.
How can I do this?
Upvotes: 0
Views: 560
Reputation: 371
You could use a mapping: see example below which maps x(1) to P(2) and x(2) to P(1), using the mapping j which maps 1 to 2 and 2 to 1.
Set i / 1, 2 /;
alias(k,i);
set j(i,k) /
1.2
2.1
/;
parameter P(i);
P("1") = 10;
P("2") = 20;
Variables
x(i);
loop(j(i,k), x.l(k) =P(i));
execute_unload "test.gdx";
Upvotes: 1
Reputation: 86
Not sure if I understand the question correctly, but maybe you just mean x(i) = j(i) ? Then for all set elements of i x will take the same value of j. If you only want the first set element: x("1") = j("1"). j("1") = 2, so x("1") will equal 2 too.
Upvotes: 0