Matrix in GAMS

Hello GAMSworld,

I have the following problem: I have a sort of low triangular matrix (A) which has these values. I want to create new one (D) where if A has a non-zero element the corresponding value would be the value of the row-the value of the column.

For example, for DMU 8 the values of A matrix are: A(DMU9, DMU5)=0.543 and A(DMU9, DMU8)= 0.457, thus the corresponding D would be D(DMU9, DMU5)=9-5=4 and D(DMU9, DMU8)=1.

A
DMU1 DMU3 DMU5 DMU6 DMU7 DMU8

DMU3 1.000
DMU4 1.000
DMU5 1.000
DMU6 1.000
DMU7 1.000
DMU8 1.000
DMU9 0.543 0.457
DMU10 1.000


I have done the following

SETS t DMUs /DMU1DMU10/
kk(t) /DMU3
DMU10/;

Parameter Alpha(kk,t), Delta(kk,t);
*Alpha matrix has already these values as presented above;.

set DD(kk,t);

DD(kk,t)$(Alpha(kk,t) NE 0)=YES;

Delta(kk,t)$DD(kk,t)=ORD(t)$DD(kk,t) - ORD(kk)$DD(kk,t);

But get wrong results. Could you please help me?

Best regards,

Kostas


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Hi Kostas



If you use the ord of kk, it will start for DMU3 at 1, so this won’t work. In fact, you don’t need kk at all, but can define an alias. Furthermore, you don’t need the set DD. Here is the code



SETS

t DMUs /DMU1*DMU10/;

alias(t,tt);



table alpha(tt,t)

DMU1 DMU3 DMU5 DMU6 DMU7 DMU8

DMU3 1.000

DMU4 1.000

DMU5 1.000

DMU6 1.000

DMU7 1.000

DMU8 1.000

DMU9 0.543 0.457

DMU10 1.000

;





Parameter Delta(tt,t);



Delta(tt,t)$(Alpha(tt,t) NE 0) = ORD(tt) - ORD(t);



display delta;



Hope this helps

Cheers

Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of ???sta?t??? ?et??d??
Sent: Montag, 15. Juni 2015 17:29
To: gamsworld@googlegroups.com
Subject: Matrix in GAMS



Hello GAMSworld,



I have the following problem: I have a sort of low triangular matrix (A) which has these values. I want to create new one (D) where if A has a non-zero element the corresponding value would be the value of the row-the value of the column.



For example, for DMU 8 the values of A matrix are: A(DMU9, DMU5)=0.543 and A(DMU9, DMU8)= 0.457, thus the corresponding D would be D(DMU9, DMU5)=9-5=4 and D(DMU9, DMU8)=1.



A

DMU1 DMU3 DMU5 DMU6 DMU7 DMU8



DMU3 1.000

DMU4 1.000

DMU5 1.000

DMU6 1.000

DMU7 1.000

DMU8 1.000

DMU9 0.543 0.457

DMU10 1.000





I have done the following



SETS t DMUs /DMU1*DMU10/

kk(t) /DMU3*DMU10/;



Parameter Alpha(kk,t), Delta(kk,t);

*Alpha matrix has already these values as presented above;.



set DD(kk,t);



DD(kk,t)$(Alpha(kk,t) NE 0)=YES;



Delta(kk,t)$DD(kk,t)=ORD(t)$DD(kk,t) - ORD(kk)$DD(kk,t);



But get wrong results. Could you please help me?



Best regards,



Kostas


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Thank you Renger, indeed that solved the problem!!!

Τη Τρίτη, 16 Ιουνίου 2015 - 3:57:49 μ.μ. UTC+3, ο χρήστης Renger van Nieuwkoop έγραψε:

Hi Kostas



If you use the ord of kk, it will start for DMU3 at 1, so this won’t work. In fact, you don’t need kk at all, but can define an alias. Furthermore, you don’t need the set DD. Here is the code



SETS

t DMUs /DMU1*DMU10/;

alias(t,tt);



table alpha(tt,t)

DMU1 DMU3 DMU5 DMU6 DMU7 DMU8

DMU3 1.000

DMU4 1.000

DMU5 1.000

DMU6 1.000

DMU7 1.000

DMU8 1.000

DMU9 0.543 0.457

DMU10 1.000

;





Parameter Delta(tt,t);



Delta(tt,t)$(Alpha(tt,t) NE 0) = ORD(tt) - ORD(t);



display delta;



Hope this helps

Cheers

Renger



From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of ???sta?t??? ?et??d??
Sent: Montag, 15. Juni 2015 17:29
To: gams...@googlegroups.com
Subject: Matrix in GAMS



Hello GAMSworld,



I have the following problem: I have a sort of low triangular matrix (A) which has these values. I want to create new one (D) where if A has a non-zero element the corresponding value would be the value of the row-the value of the column.



For example, for DMU 8 the values of A matrix are: A(DMU9, DMU5)=0.543 and A(DMU9, DMU8)= 0.457, thus the corresponding D would be D(DMU9, DMU5)=9-5=4 and D(DMU9, DMU8)=1.



A

DMU1 DMU3 DMU5 DMU6 DMU7 DMU8



DMU3 1.000

DMU4 1.000

DMU5 1.000

DMU6 1.000

DMU7 1.000

DMU8 1.000

DMU9 0.543 0.457

DMU10 1.000





I have done the following



SETS t DMUs /DMU1*DMU10/

kk(t) /DMU3*DMU10/;



Parameter Alpha(kk,t), Delta(kk,t);

*Alpha matrix has already these values as presented above;.



set DD(kk,t);



DD(kk,t)$(Alpha(kk,t) NE 0)=YES;



Delta(kk,t)$DD(kk,t)=ORD(t)$DD(kk,t) - ORD(kk)$DD(kk,t);



But get wrong results. Could you please help me?



Best regards,



Kostas


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.