define subset in GAMS

953 Views Asked by At

I have a problem about partitioning . with 3 set $i,j,k$ , $i=1,..,32 $ Represents the number of classes, $j=1,..,512 $ Represents the number of student, $k=1,..,40 $ Represents the type of student.

set $j=\{ 1,...,512\}$ , and subsets $t_k$ of $j$ ,Which indicates student $j$th belongs to which type. for example , if we consider type $k=1$, then all student with type $'1'$ are $t_1= \{ 2,10,78,69,114,500\}$.

These subsets are known. for example $t_1= \{ 2,10,78,69,114,500\}$ and $t_2=\{8,42,50\}$ ,...

I want to code in gams this sum in GAMS , $ \sum_{i,j} a_{i,j} x_{i,j} \ \ \ \ \forall i , \ \ j\in t_k$

I know when we want to use subset we can write

set j / 1*512/,
    t(j) 

but in this case, The subset has already been specified .

i use this way

set
     j/1*512/
     t(j)/2,10,78,69,114,500/
     ;

its right for one case "$t_1$ "

I don't know how can I define this type of subset such that Work for all sub set, and how can I define this summation?

1

There are 1 best solutions below

4
On BEST ANSWER

In the first few iterations of this question the math was just wrong. It is no surprise that in that case the translation into GAMS is very difficult.

Now we have:

sets
    i 'classes' /class1*class32/
    j 'students' /student1*student512/
    k 'student type' /type1*type40/
; 

Of course for a real model the set elements would have proper meaning, like:

set i 'classes' /English,Biology,Math/;

Now, we can do:

set t(k,j) 'mapping between type and student' /
   type1.(student2,student10,student78,student69,student114,student500)
   type2.(student8,student42,student50)
/;     

We can use this in expressions as

equation 
   e(k).. v(k) =e= sum((i,j)$t(k,j), a(i,j)*x(i,j));

This would correspond to:

$$v_k = \sum_{i,j|t(k,j)} a_{i,j} x_{i,j}$$

I.e. $ is a 'such-that' operator, just like | in math.