Hi, Renger
Lan is my family name, Dylan is my first name. It would be very nice if you could call me Dylan.
Thank you very much for your help, I think I have asked for too much. I am a novice in programming, just started to learn GAMS two weeks ago and I have no idea how to learn programming at all. Right now I am working on a mathematical model and try to use GAMS to realize its function, but it seems too hard for me to do it by reading the user guide only, so I seeked help on the internet, and luckly I met you, an advanced programmer who gave a lot of suggestions and support. But it makes me think it is too early for me to program for the model.
Besides, since it is my work, I should not always depend on others for quick answer, though I am sure you are a kind hearted and selfless person helping people without hesitation. So I think I should focus on learning GAMS first instead of working on the model. While I am learning I might ask a lot in the forum about GAMS and I wish you could give me advice and help.
I am really appreciate for your help.
Best regards
Dylan
åœ¨ 2013å¹´1æœˆ23æ—¥æ˜ŸæœŸä¸‰UTC+8ä¸‹åˆ9æ—¶16åˆ†37ç§’ï¼ŒRenger van Nieuwkoopå†™é“ï¼š
Hi Lan (I assume that is your first name and not your family name),
You could this as follows (there might be more elegant ways, but this is one takes 3 minutes):
 Use the put utility to write an include file with all the information on the set m and the parameter AM
 Split your model file in one until you have produced your include file and one with the rest, where you have a statement like $include setm.inc.
 Run gams on the first file with the save option. This is necessary, because you can’t write a file and include it in the same gams run (story with compilation and execution time statements).
 Run gams on the second file with the restart option.
Here is the code for the first part
set p /e1*e10/;
parameter IT(p);
IT(p) = ord(p);
IT(“e5”) = 0;
IT(“e7”) = 0;
 count the number of zeros in IT
parameter count0;
count0 = sum(p$(it(p) ne 0), 1);
display count0;
 Use the put utility to write a file that will be included in the second model file
file setm /setm.inc/;
put setm;
parameter counter;
counter = 1;
 Write the set
put “set m”;
put “/”/;
while(counter le count0,
put “m”;
put @2 counter:0:0/;
counter = counter + 1;
);
put “//;”;
loop(p$(IT(p) ne 0),
put “AM('”,@5 counter:0:0, put “') = “, IT(p),”;”/;
counter = counter + 1;
);
putclose setm;
In your second file you would put at the beginning:
$include setm.inc
Renger
By the way: In order to keep the information on which set element of p belongs to m, you could write with to the same put file a mapping.
This mapping can then be used in later when you have p and m together in an equation or assignment.
The mapping would in this case loop like this
Set mapMP(m,p)
/m1.e1
…
m5.e6
…
m8.e10/
;
From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of Dylan Lan
Sent: Mittwoch, 23. Januar 2013 11:45
To: gams...@googlegroups.com
Subject: Re: Convert data from one set to another
Hi Nieuwkoop,
Thank you very much for your reply. Your reply is helpful, however, if the new set ‘m’ is dynamic, it is unable to use operator like ‘ord’ or lag over AM(m).
Thanks.
åœ¨ 2013å¹´1æœˆ23æ—¥æ˜ŸæœŸä¸‰UTC+8ä¸‹åˆ5æ—¶10åˆ†44ç§’ï¼ŒRenger van Nieuwkoopå†™é“ï¼š
Hi Dylan
Here is some code that does the job:
set p /e1*e10/;
parameter IT(p);

Assign some values that are ordered
IT(p) = ord(p);

Set some of the values to zero
IT(“e5”) = 0;
IT(“e7”) = 0;

Define a new subset of p that will only contain elements if IT(p) is not zero
set m(p) Set with for all ordered nonzero values of IT;

Assign the set elements if IT(p) is not zero
m(p)$(IT(p)) = YES;

Define a parameter for the ordered values of IT without the zeros (note, that you

have to define AM over p, as m is a dynamic set. Defining a parameter over a

dynamic set is not allowed in Gams
parameter AM(p);
 Get the values for AM. I added EPS, a very small value to show that
 the zero values aren’t assigned to AM (zero values are not shown in
 a display statement. If the value is EPS the zero values will show up
 as EPS:
AM(m) = IT(m) +EPS;
display IM;
Cheers
Renger
From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of Dylan Lan
Sent: Mittwoch, 23. Januar 2013 09:42
To: gams...@googlegroups.com
Subject: Convert data from one set to another
Hi gamsworld,
I have a problem in transfering nonzero data from parameters IT(p) into parameters(or variables) AT(m).
All data in IT(p) are in descending order except zero, that is IT(p)$(IT(p) ne 0) > IT(p+1); and I still want to keep this order in AT(m), except that no zero data are tranfered to AT(m). The parameters AT(m) are initially empty.
How can I realize this command?
Thanks.
\
To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld//UUxIF473QkkJ.
To post to this group, send email to gams...@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.
–
To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld//eCTP_3aoPgQJ.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.