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
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