在gams中迭代多维集

Iterating multidimensional sets in gams

我想在gams中使用一组张量。我的想法是将它们表示如下(因为gams中没有1对1的张量集):

假设我有一个张量集,如下所示:{ [[1,2],[3,4]], [[5,6],[7,8]] }(即包含每个维度为 2:2 的张量的集合)。

我的想法是使用 gams 提供的多维集合,其中第一个索引是集合中张量的索引,后面的索引是张量中条目的索引。对于上面的设置,我的游戏设置如下所示

Set S /1.1.1 =1,1.1.2 =2,1.2.1 =3,1.2.2 =4, 2.1.1 =5,2.1.2 =6,2.2.1 =7,2.2.2 =8/;

这看起来有点臃肿,但我没有想出更好的解决方案。

现在有什么方法可以迭代这个集合(在索引方程中),但只是张量,而不是每个条目?

equation eq; eq(S).. x =g= (??);

应该可以将我们正在迭代的条目用作值或索引。

我会用伪代码展示一个例子。

Variable x in [0, 10]; # variable value to be optimized, between 0 and 10
Set S := { ((1,2),(3,4)), ((5,6),(7,8)) }; # set containing two Tensors of the dimension 2:2 each
Tensor T := (1,2,3,4,5,6); # tensor / vector containing 6 entries

forall i in S: # iterating over every tensor in S
    i[1,1] <= x; # x has to be larger than the entry of index 1,1 of every tensor in S (in this instance 1 and 5)

forall j in S: # iterating over every tensor in S
   T[ j[1,2] ] <= x; # x has to be larger than the entry of T with the index that equals the entry of index 1,2 of every tensor in S (the indices of T in this instance are 2 and 6, the values of the picked entries of T are therefore 2 and 6).

这对你有用吗(这实际上是不可行的,但希望能展示一个想法来模拟这样的东西)?

Alias (*,a,b,c,T);
Set ST(a,b,c,T) /1.(1.(1.1,
                       2.2),
                    2.(1.3,
                       2.4)),
                 2.(1.(1.5,
                       2.6),
                    2.(1.7,
                       2.8))/
     S(a,b,c);
* Project ST into S
option S<ST;

Parameter K (a) /1=1,2=2/;
Parameter Te(T) /1=1,2=2,3=3,4=4,5=5,6=6/; 

Variable x; x.up = 10;

equation eq1(a);
eq1(a)$S[a,'1','1'].. x =g= K(a);

equation eq2(a);
eq2(a).. x =g= sum(ST(a,b,c,T)$(sameas(b,'1') and sameas(c,'2')),Te(T));

Model dummy /all/;
solve dummy min x use lp;