'How to identify if an element of a set N belongs to a subset of such a set N
Good evening, I want to do the following modeling in GAMS language:
PART 1 : Let N={n1,n2,n3,n4} be a set. I'm going to partitioning the set N in two subsets: B1={n1} and B2={n2,n3,n4}.
PART 2 : Then I want to form a set B whose elements are the sets B1 and B2, i.e, B={B1,B2}. That is, B will have 2 elements, which is the number of subsets that were created in part 1.
PART 3 : I want to know if an element of N is in any element of B, for example, i want to know if n1 is in B1 or not.
All these three steps is because I want to obtain equations of the form: Ec(n1,B1), Ec(n2,B2),Ec(n3,B2), Ec(n4,B2) using only one equation something like that : Ec(N,B)$[CONDITION]. The condition is precisely the PART 3.
My attempt is the following:
PART 1
SETS
N /n1*n4/
B1(N) /n1/
B2(N) /n2*n4/
;
PART 2 , I don't know if this is correct, that is, if a set whose elements are previously defined sets is written like this
SETS
B /B1,B2/
PART 3
PARAMETER test(N);
test(B1)=1;
test(B2)=2;
But this doesn't help me at all because if my partition had 1000 subsets, i.e. B1 ... B1000 then I would need to write it as some kind of recursion using PART 2.
Please I need your help. Thank you very much.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
