Pinpoint the last parameter of a set of parameters

Hi, GAMS world.

I have some difficulties in pinpointing the last parameter of a set of parameters.

For now I use the following method to let N to be equal to the last parameter of M(k):

Set
k / k1*k10 / ;

Parameter
M(k) ;

Scalar
N ;

N = sum(k$(ord(k)=card(k)), M(k)) ;

Since this method looks very clumsy, I am wondering if there is a better way to finish the job.

Thanks.

Dylan


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 https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Dylan,

If you use a singleton set, you can isolate the “ord(k)=card(k)” to the definition of the singleton set, and potentially use the singleton many times. An example is below.

-Steve

Set k / k1*k10 /;
singleton set kLast(k);
kLast(k) = [ord(k)=card(k)];

Parameter M(k);
M(k) = ord(k);

Scalars N, S;

N = sum(k$(ord(k)=card(k)), M(k));

  • since kLast is declared to be a singleton, the statement below is OK
    S = M(kLast);

On Tue, Feb 16, 2016 at 8:57 PM, Dylan Lan wrote:

Hi, GAMS world.

I have some difficulties in pinpointing the last parameter of a set of parameters.

For now I use the following method to let N to be equal to the last parameter of M(k):

Set
k / k1*k10 / ;

Parameter
M(k) ;

Scalar
N ;

N = sum(k$(ord(k)=card(k)), M(k)) ;

Since this method looks very clumsy, I am wondering if there is a better way to finish the job.

Thanks.

Dylan


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 https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.



\

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