How to define incomplete sets in GAMS?

时间:2018-08-03 11:28:08

标签: gams-math

There is an incomplete graph (e.g. including 5 vertices). The adjacency matrix "a" is available. I want to define the set which includes all edges but exclude any other pair of vertices. That is, the pair of vertices belongs to the set of edges iff the element in matrix "a" is positive. The last line of following code does not work!

sets i "Set of vertices" /1*5/    ;  
alias(i,j);  
set a(i,j)  "Adjacency matrix"    ;  
Table a(i,j)  
      1   2   3   4   5  
1     0   1   0   1   1  
2     1   0   1   0   0  
3     0   1   0   0   0  
4     1   0   0   0   1  
5     1   0   0   1   0;  
Set edges(i,j);  
edges(i,j) = a(i,j)$(a(i,j)>0);

2 个答案:

答案 0 :(得分:1)

如果要具有edge,则必须定义如下的set和参数:

  sets i "Set of vertices" /1*5/    ;  
  alias(i,j);  
  set a(i,j)  "Adjacency matrix"    ;  
 Table a(i,j)  
  1   2   3   4   5  
 1     0   1   0   1   1  
 2     1   0   1   0   0  
 3     0   1   0   0   0  
4     1   0   0   0   1  
5     1   0   0   1   0;  
Set edges(i,j);  
edges(i,j) $ a(i,j) =yes;

答案 1 :(得分:0)

您可以将最后一行简化为

edges(i,j) = a(i,j);

这自动执行,就像您写了$(a <> 0)这样。但是,由于您已经将符号a定义为集合而不是参数,因此我认为您实际上不必执行任何操作。正义就是您要寻找的东西。只需

display a;

,然后在第一个文件中查看结果。