[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-glpk] Multidimesional Arrays in GLPK/L
From: |
Andrew Makhorin |
Subject: |
Re: [Help-glpk] Multidimesional Arrays in GLPK/L |
Date: |
Wed, 27 Nov 2002 19:34:28 +0300 |
>How to work with cost matrices that have more than two dimwnsions?
In glpk/l there are three ways to initialize a parameter with more than
two dimensions.
Let, for example, there be a three-dimensional parameter declared as
follows:
sets A = (a1, a2, a3),
B = (b1, b2, b3, b4, b5),
C = (c1, c2, c3, c4);
parameter
p[A, B, C];
The first way is to assign a value to each (non-zero) parameter member
separately, for example:
p[#a1,#b1,#c1] := 1;
p[#a1,#b2,#c1] := 2;
p[#a3,#b4,#c2] := 6;
/* etc. */
The second way is to use the data clause, for example:
p[i,j,k] := data
( i in A, j in B, k in C:
a1 b1 c1 1
a1 b2 c1 2
a3 b4 c2 6
/* etc. */
);
And the third way is to use the table clause, for example:
p[#a1,j,k] := table(k in C, j in B:
b1 b2 b3 b4 b5:
c1 1 2 3 . 4
c2 . . 5 6 .
c3 7 . . . 8
c4 . . 9 . 10 );
p[#a2,j,k] := table(k in C, j in B:
b1 b2 b3 b4 b5:
c1 10 9 8 . 7
c2 6 5 . . .
c3 . . 4 . 3
c4 2 . . 1 . );
p[#a3,j,k] := table(k in C, j in B:
b1 b2 b3 b4 b5:
c1 . . 5 . 8
c2 1 . . 6 9
c3 2 4 . . .
c4 3 . . 7 10 );
In any case you can use the display statement, for example:
display p;
to see what you get.
Being initialized a multidimensional parameter can be used in model
expressions, in particular, to define an objective function row, for
example:
obj := sum((i,j,k), p[i,j,k] * x[i,j,k]);
where x is a three-dimensional model variable.