AnsweredAssumed Answered

Set of tuples

Question asked by Guenther Fuellerer on Jan 15, 2013
Latest reply on Aug 6, 2014 by Susanne.Heip

In GLPK (which uses GNU MathProg) it is common to create set of tuples.

Example below:

set V:=1..3;

set E_implicit, within V cross V;
param c{(i,j) in E_implicit};

set E_explicit:={(1,2),(1,3),(2,1),(2,3),(3,1),(3,2)};

display E_implicit;
display E_explicit;

printf{(i,j) in E_implicit: c[i,j]} "      %3d       %3d   %8d\n",i, j, c[i,j];

solve;


data;


param : E_implicit : c :=
    1  2   1
    1  3   2
    2  1   3
    2  3   4
    3  1   5
    3  2   6;

end;

OUTPUT:

Display statement at line 9
E_implicit:
   (1,2)
   (1,3)
   (2,1)
   (2,3)
   (3,1)
   (3,2)
Display statement at line 10
E_explicit:
   (1,2)
   (1,3)
   (2,1)
   (2,3)
   (3,1)
   (3,2)
        1         2          1
        1         3          2
        2         1          3
        2         3          4
        3         1          5
        3         2          6

 

Can this also be done with Mosel? E_implicit (which is euqal to E_explicit) is a set of (i,j) tuples and it is easys to go through it. You can also use this concept for modelling sparse data.

 

The advantagE is that you do alsways have to put something like exists(c(i,j)) if you want to iterate through the array c which is V cross V.

 

Outcomes