2

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

Richard
  • 177
  • 1
  • 9

1 Answers1

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);
Lutz
  • 2,197
  • 1
  • 10
  • 12
  • OK that's work,thanks. i searched and i write this union(i,ia,j)=k(i,j) + k(ia,j), in two loop . that's work too – Richard Jul 23 '18 at 08:29