Need help with simple Gams problem

Hi. I have been trying to solve this problem for some days now and I am new to GAMS.

I have declared sets;-

set i / 16 /;
set tm(i) / 4
6 /;

For each value of set tm, I am solving a model to find the optimal cost. The result I get is stored in a parameter cost(i). So the result stored in cost are :

4 -100.00, 5 -500.00, 6 -200.00

Now, I want to first use the value of set tm that has the least cost, and so on in my GAMS code. So, I would like to use 5 first, then 6 and then 4 from set tm.

Can someone please help me with this. Thanks in advance.


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/groups/opt_out.

Hi



You could have a look at the rank utility of Tom Rutherford. It would give you a parameter with the values sorted.

http://www.mpsge.org/gdxrank/index.html



Cheers

Renger


Modelworks

Gewerbestrasse 15

3600 Thun – Switzerland

+41 79 818 53 73

Info@modelworks.ch

blog.modelworks.ch







From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of visvalley9@gmail.com
Sent: Sonntag, 6. Oktober 2013 16:00
To: gamsworld@googlegroups.com
Subject: Need help with simple Gams problem



Hi. I have been trying to solve this problem for some days now and I am new to GAMS.



I have declared sets;-



set i / 1*6 /;

set tm(i) / 4*6 /;



For each value of set tm, I am solving a model to find the optimal cost. The result I get is stored in a parameter cost(i). So the result stored in cost are :



4 -100.00, 5 -500.00, 6 -200.00



Now, I want to first use the value of set tm that has the least cost, and so on in my GAMS code. So, I would like to use 5 first, then 6 and then 4 from set tm.



Can someone please help me with this. Thanks in advance.


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/groups/opt_out.


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/groups/opt_out.

Hi. Thanks for your reply. I have used gdxrank to get the sorted values stored in a parameter but there’s another problem.

Currently I have 2D parameter sorted(i,j).

It has values :-
1.5 -500.00
2.6 -200.00
3.4 -100.00

Now I want to loop through this parameter sorted and use the values 5, 6 and 4 in that order in my GAMs code.

Can you tell me how to do that. Thanks


On Sunday, October 6, 2013 4:00:18 PM UTC+2, visva...@gmail.com wrote:

Hi. I have been trying to solve this problem for some days now and I am new to GAMS.

I have declared sets;-

set i / 16 /;
set tm(i) / 4
6 /;

For each value of set tm, I am solving a model to find the optimal cost. The result I get is stored in a parameter cost(i). So the result stored in cost are :

4 -100.00, 5 -500.00, 6 -200.00

Now, I want to first use the value of set tm that has the least cost, and so on in my GAMS code. So, I would like to use 5 first, then 6 and then 4 from set tm.

Can someone please help me with this. Thanks in advance.


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/groups/opt_out.

How about this? The dollar assignment restricts the loop to the available values of test(I,j).



set i /13/, j /46/;



parameter test(i,j);



test(“1”,“5”) = -500.00;

test(“2”,“6”) = -200.00;

test(“3”,“4”) = -100.00;



parameter distest;

loop(i,loop(j$test(i,j),

distest = test(i,j);

display distest;

););



Cheers



Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of visvalley9@gmail.com
Sent: Montag, 7. Oktober 2013 20:24
To: gamsworld@googlegroups.com
Subject: Re: Need help with simple Gams problem



Hi. Thanks for your reply. I have used gdxrank to get the sorted values stored in a parameter but there’s another problem.



Currently I have 2D parameter sorted(i,j).



It has values :-

1.5 -500.00

2.6 -200.00

3.4 -100.00



Now I want to loop through this parameter sorted and use the values 5, 6 and 4 in that order in my GAMs code.



Can you tell me how to do that. Thanks



On Sunday, October 6, 2013 4:00:18 PM UTC+2, visva...@gmail.com wrote:

Hi. I have been trying to solve this problem for some days now and I am new to GAMS.



I have declared sets;-



set i / 1*6 /;

set tm(i) / 4*6 /;



For each value of set tm, I am solving a model to find the optimal cost. The result I get is stored in a parameter cost(i). So the result stored in cost are :



4 -100.00, 5 -500.00, 6 -200.00



Now, I want to first use the value of set tm that has the least cost, and so on in my GAMS code. So, I would like to use 5 first, then 6 and then 4 from set tm.



Can someone please help me with this. Thanks in advance.


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/groups/opt_out.


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/groups/opt_out.

Thanks for your response. It has been helpful. I have one question though. Instead of displaying the value of distest in your example, is there any way to display the values of set j in the order its been processed in the loop i.e I want it to display
5
6
4
and also assign their values to something that is input to another model.
When I write display j, its displaying the values of set j in the order 4 5 6. Actually in my program, these values represent clients. So, after sorting, I want to use those to solve another model. The cost associated with them are not useful in the program I want to write further. It was only useful to sort the clients.

Thanks in advance.


On Sunday, October 6, 2013 4:00:18 PM UTC+2, visva...@gmail.com wrote:

Hi. I have been trying to solve this problem for some days now and I am new to GAMS.

I have declared sets;-

set i / 16 /;
set tm(i) / 4
6 /;

For each value of set tm, I am solving a model to find the optimal cost. The result I get is stored in a parameter cost(i). So the result stored in cost are :

4 -100.00, 5 -500.00, 6 -200.00

Now, I want to first use the value of set tm that has the least cost, and so on in my GAMS code. So, I would like to use 5 first, then 6 and then 4 from set tm.

Can someone please help me with this. Thanks in advance.


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/groups/opt_out.

I found the answer to the question I asked. It’s as easy as writing:

scalar k;
loop(i,loop(j$test(i,j),

distest = test(i,j);

k = ord(j);

display k;
););

Thanks for your help.

On Sunday, October 6, 2013 4:00:18 PM UTC+2, visva...@gmail.com wrote:

Hi. I have been trying to solve this problem for some days now and I am new to GAMS.

I have declared sets;-

set i / 16 /;
set tm(i) / 4
6 /;

For each value of set tm, I am solving a model to find the optimal cost. The result I get is stored in a parameter cost(i). So the result stored in cost are :

4 -100.00, 5 -500.00, 6 -200.00

Now, I want to first use the value of set tm that has the least cost, and so on in my GAMS code. So, I would like to use 5 first, then 6 and then 4 from set tm.

Can someone please help me with this. Thanks in advance.


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/groups/opt_out.

set i /1*2/;



parameter report;



loop(I,

report = i.val;

display report;

);



Cheers



Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of visvalley9@gmail.com
Sent: Tuesday, October 8, 2013 4:15 PM
To: gamsworld@googlegroups.com
Subject: Re: Need help with simple Gams problem



Thanks for your response. It has been helpful. I have one question though. Instead of displaying the value of distest in your example, is there any way to display the values of set j in the order its been processed in the loop i.e I want it to display

5

6

4

and also assign their values to something that is input to another model.

When I write display j, its displaying the values of set j in the order 4 5 6. Actually in my program, these values represent clients. So, after sorting, I want to use those to solve another model. The cost associated with them are not useful in the program I want to write further. It was only useful to sort the clients.



Thanks in advance.




On Sunday, October 6, 2013 4:00:18 PM UTC+2, visva...@gmail.com wrote:

Hi. I have been trying to solve this problem for some days now and I am new to GAMS.



I have declared sets;-



set i / 1*6 /;

set tm(i) / 4*6 /;



For each value of set tm, I am solving a model to find the optimal cost. The result I get is stored in a parameter cost(i). So the result stored in cost are :



4 -100.00, 5 -500.00, 6 -200.00



Now, I want to first use the value of set tm that has the least cost, and so on in my GAMS code. So, I would like to use 5 first, then 6 and then 4 from set tm.



Can someone please help me with this. Thanks in advance.


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/groups/opt_out.


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/groups/opt_out.