help-glpk
[Top][All Lists]

## Re: [Help-glpk] how to make matrix multiply with mathprog

 From: Yaron Kretchmer Subject: Re: [Help-glpk] how to make matrix multiply with mathprog Date: Tue, 24 Feb 2009 12:49:54 -0800

Xypron-
Any thoughts on how to how to model sparse matrix multiplication? this is usually with linked lists, but I'm sure that there's a smart way to use sets to do the modeling

Thanks
kretch

On Tue, Feb 24, 2009 at 10:29 AM, xypron wrote:

Hello!

hhb83 wrote:
>
> I still could not work it out. Here, the Up,i is var, so should I take the
> Xp,i as param or var? If param, it always said "_expression_ following :=
> has invalid type". And if I define it as var, and take the formulation as
> constraint like this:
> s.t. position{i in I, j in J, m in K}: X[i,j,m] = if i==1 then X0[j,m]
> else sum{k in K} A[m,k]*X[i-1,j,k] + B[m,k]*U[i-1,j,k];
>
>

you can find a working example below.

Best regards

Xypron

# hhb83: how to make matrix multiply with mathprog
set I := {1..9};
set J := {1..3};
set K := {1..3};
set M := {1..3};
param A{j in J, k in K};
param B{j in J, k in K};
param X0{j in J, k in K};
param U{i in I, j in J, k in K};
param X{i in I, j in J, m in M} :=
if i==1 then X0[j,m] else sum{k in K} ( A[m,k]*X[i-1,j,k] +
B[m,k]*U[i-1,j,k] );
display X;
data;
param A: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9;
param B: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9;
param X0: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9;
param U:=
[1,*,*]: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9
[2,*,*]: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9
[3,*,*]: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9
[4,*,*]: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9
[5,*,*]: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9
[6,*,*]: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9
[7,*,*]: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9
[8,*,*]: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9
[9,*,*]: 1 2 3 :=
1 1 2 3
2 4 5 6
3 7 8 9;
end;

--
View this message in context: http://www.nabble.com/how-to-make-matrix-multiply-with-mathprog-tp22077225p22187619.html
Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com.

_______________________________________________
Help-glpk mailing list