如何定义并集,交集,对称差? [英] How can define Union, intersection, symmetric difference?

查看:129
本文介绍了如何定义并集,交集,对称差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从i和j设置了i,j和子集k.我要有并集,交集和对称差.

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

我的电视机很大.但是为了澄清这个问题,让我为I = 1 * 3,j = 6 * 12.

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

我想在k(i,j)上具有并集,交集和对称差.

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

例如,对于k(1,j)和k(2,j).交叉点为'11',对称差为'6,7,9',联合点为'6,7,9,11'

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'

我必须计算k(i,j)中所有可能组合的交集,并集和对称差,如何在GAMS中做到这一点?我该如何编码?

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和j上的Union,我可以写

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

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

但是在这种情况下,k(i,j)是具有二维的子集,我不知道如何获得Union?如何获得交集或对称差?

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?

谢谢

推荐答案

尝试一下:

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

这篇关于如何定义并集,交集,对称差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆