Summation Imdexing

Hi all,

I am a new user of GAMS and still trying to get all the tricks. I have
the following (hopefully easy) problem.

I have a set set(k), where k is / 0*299 /
I try to define in a simple and fast way 600 sums as following.

Pseudo-code:
For n = 0 to 299
define sumA(n) = sum (i (from 0 to n), set(i))
define sumB(n) = sum (i (from n to 299), set(i))
next n

Is there an easy way to do it without defining 600 subsets?

Thanks in advance.

\

hi
can you explain more, maybe i can help you.

you want to sum on elements of your set?


On Thu, Mar 10, 2011 at 1:13 AM, Greg K wrote:

Hi all,

I am a new user of GAMS and still trying to get all the tricks. I have
the following (hopefully easy) problem.

I have a set set(k), where k is / 0*299 /
I try to define in a simple and fast way 600 sums as following.

Pseudo-code:
For n = 0 to 299
define sumA(n) = sum (i (from 0 to n), set(i))
define sumB(n) = sum (i (from n to 299), set(i))
next n

Is there an easy way to do it without defining 600 subsets?

Thanks in advance.


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.



\

Babak Saleck Pay
M.Sc
Socio-Economic System Engineering
Group of Industrial Engineering
University of Tehran
Tehran,Iran


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.

Greg,

Here’s a way that I think is pretty easy.

-Steve

sets
K / 0 * 19 /
s(K)
;
alias (K,J);

s(K) = [uniform(0,1) = ord(K)], 1$s(J)};


On Wed, Mar 9, 2011 at 3:43 PM, Greg K wrote:

Hi all,

I am a new user of GAMS and still trying to get all the tricks. I have
the following (hopefully easy) problem.

I have a set set(k), where k is / 0*299 /
I try to define in a simple and fast way 600 sums as following.

Pseudo-code:
For n = 0 to 299
define sumA(n) = sum (i (from 0 to n), set(i))
define sumB(n) = sum (i (from n to 299), set(i))
next n

Is there an easy way to do it without defining 600 subsets?

Thanks in advance.


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.




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

The simple example.
Table a(k) where k = {1 … 5}
For every k I want to define the following sums
sumA(k) = a(1) + a(2) + … + a(k)
sumB(k) = a(k) + a(k+1) + … + a(5)

So, for k = 2
sumA(2) = a(1) + a(2)
and
sumB(2) = a(2) + a(3) + a(4) + a(5)

With the help of this group I had found some answers and I hope they
are correct. Can anyone confirm/correct?

set k /0*299/
alias (k,j)
table a(k)

sumA(k) =e= sum(j$(ord(j) wrote:

hi
can you explain more, maybe i can help you.

you want to sum on elements of your set?

On Thu, Mar 10, 2011 at 1:13 AM, Greg K wrote:

Hi all,

I am a new user of GAMS and still trying to get all the tricks. I have
the following (hopefully easy) problem.

I have a set set(k), where k is / 0*299 /
I try to define in a simple and fast way 600 sums as following.

Pseudo-code:
For n = 0 to 299
define sumA(n) = sum (i (from 0 to n), set(i))
define sumB(n) = sum (i (from n to 299), set(i))
next n

Is there an easy way to do it without defining 600 subsets?

Thanks in advance.


“gamsworld” group.
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.


Babak Saleck Pay
M.Sc
Socio-Economic System Engineering
Group of Industrial Engineering
University of Tehran
Tehran,Iran

\

Hi Greg

If I understand correctly, you want to make a summation on the value of the set “i”. If that is correct, the problem with that is that the sets are by definition a string. One way to do it is by creating an auxiliary parameter like the code below. There may be an easier way to do it, but this is the one I know.



parameter Ini(i) ;

Ini(‘1’)=1;

loop(i, ini(i+1)=ini(i)+1 );

SumA(i)=sum(i,ini(i));



Regards

Jose



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of babak saleckpay
Sent: jueves, 10 de marzo de 2011 01:53 a.m.
To: gamsworld@googlegroups.com
Subject: Re: Summation Imdexing



hi
can you explain more, maybe i can help you.

you want to sum on elements of your set?

On Thu, Mar 10, 2011 at 1:13 AM, Greg K wrote:

Hi all,

I am a new user of GAMS and still trying to get all the tricks. I have
the following (hopefully easy) problem.

I have a set set(k), where k is / 0*299 /
I try to define in a simple and fast way 600 sums as following.

Pseudo-code:
For n = 0 to 299
define sumA(n) = sum (i (from 0 to n), set(i))
define sumB(n) = sum (i (from n to 299), set(i))
next n

Is there an easy way to do it without defining 600 subsets?

Thanks in advance.


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.



\

Babak Saleck Pay
M.Sc
Socio-Economic System Engineering
Group of Industrial Engineering
University of Tehran
Tehran,Iran


\

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.


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.

sums(K,‘up’) = sum{J$[ord(J) >= ord(K)], 1$s(J)};

Duh, apparently I forgot about the existence of “>=” sign. :slight_smile:
See my solution below

On Mar 10, 9:08 am, Steven Dirkse wrote:

Greg,

Here’s a way that I think is pretty easy.

-Steve

sets
K / 0 * 19 /
s(K)
;
alias (K,J);

s(K) = [uniform(0,1) > scalar cs;
cs = card(s);

parameter sums(K,*);

sums(K,‘down’) = sum{J$[ord(J) > sums(K,‘up’) = sum{J$[ord(J) >= ord(K)], 1$s(J)};

On Wed, Mar 9, 2011 at 3:43 PM, Greg K wrote:

Hi all,

I am a new user of GAMS and still trying to get all the tricks. I have
the following (hopefully easy) problem.

I have a set set(k), where k is / 0*299 /
I try to define in a simple and fast way 600 sums as following.

Pseudo-code:
For n = 0 to 299
define sumA(n) = sum (i (from 0 to n), set(i))
define sumB(n) = sum (i (from n to 299), set(i))
next n

Is there an easy way to do it without defining 600 subsets?

Thanks in advance.


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 athttp://groups.google.com/group/gamsworld?hl=en.


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

\