Sorting numbers in descending order

Dear All,
I am new in GAMS programming, I’ve just come across a difficulty in sorting two dimension numbers and display it. I’ve read the user guide for one-dimension sorting and also tried some other ways for two days, but still confused. So I am writing to ask if someone could help. The problem can be described as follows:

Num(i,j) is an output generated from a calculation, this may include numbers like
/1 .2 0.695,
1 .3 0.770
2 .4 2.753
2 .5 0.721
2 .6 3.712
4 .6 0.647
4 .7 1.286/
Now it is required to keep and rank the numbers greater than 1 in descending order and neglect numbers less than 1. The result should be displayed in the .lst file and seen as
/2.6 3.712
2.4 2.753
4.7 1.286/

Thanks in advance for your advice.
Warmly,
Linstro


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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

\

Linstro,

Keeping the values greater than 1 is easy: just create a copy of num(i,j) and use the dollar to assign to it:

parameter a(i,j);
a(i,j)$[num(i,j) > 1] = num(i,j);

To sort the values in a, perhaps you can look at the GDXRANK example in the GAMS Data Utilities Models library for some inspiration.

-Steve


On Fri, Mar 22, 2013 at 10:04 AM, Linstro Forren wrote:

Dear All,
I am new in GAMS programming, I’ve just come across a difficulty in sorting two dimension numbers and display it. I’ve read the user guide for one-dimension sorting and also tried some other ways for two days, but still confused. So I am writing to ask if someone could help. The problem can be described as follows:

Num(i,j) is an output generated from a calculation, this may include numbers like
/1 .2 0.695,
1 .3 0.770
2 .4 2.753
2 .5 0.721
2 .6 3.712
4 .6 0.647
4 .7 1.286/
Now it is required to keep and rank the numbers greater than 1 in descending order and neglect numbers less than 1. The result should be displayed in the .lst file and seen as
/2.6 3.712
2.4 2.753
4.7 1.286/

Thanks in advance for your advice.
Warmly,
Linstro


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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





\

Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdirkse@gams.com
http://www.gams.com