How can define Union, intersection, symmetric difference?

自作多情 提交于 2019-12-08 02:50:18

问题


I have set i ,j and sub set k from i and j . I want to have union , intersection and symmetric difference .

The size of my set is large. But to clarify the question , let's I=1*3, j=6*12 .

 Set i /1*3/
        j/6*12/
        K(i ,j) 
         1.(6,9,11)
         2.(7,11)
         3.(8,9,10,12) ;

I want to have Union, intersection, and symmetric difference on k(i ,j).

For example for k(1,j) and k(2,j). Intersection is '11' and symmetric difference is '6,7,9' and Union is '6,7,9,11'

I have to calculate intersection, Union , and symmetric difference for all possible combination in k( i ,j) , how can I do this in GAMS ? How can i code it?

I know for Union on set I and j , I can write

  Set  i-u-j /#i,#j/;   or /i+j/

But in this case k(i ,j) is subset with two dimension , and I don't know how can I get Union ? How can I get intersection or symmetric difference?

Thanks


回答1:


Try this:

Set i /1*3/
    j/6*12/
    K(i ,j) /
         1.(6,9,11)
         2.(7,11)
         3.(8,9,10,12) / ;

Alias (i,ia);

Set intersect(i,ia,j)
    symDiff(i,ia,j)
    union(i,ia,j);

intersect(i,ia,j)$(ord(i)<ord(ia)) = k(i,j) and k(ia,j);
symDiff(i,ia,j)$(ord(i)<ord(ia)) = k(i,j) xor k(ia,j);
union(i,ia,j)$(ord(i)<ord(ia)) = k(i,j) or k(ia,j);


来源:https://stackoverflow.com/questions/51400240/how-can-define-union-intersection-symmetric-difference

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!