summation with a lower bound and upper bound

1,552 views
Skip to first unread message

helena

unread,
Jan 13, 2012, 7:40:56 PM1/13/12
to gamsworld
Dear all,

I just started to study gams and encountered a problem. It's easy to
understand my problem so plz have a look and give me a help. I
appreciate your help!!

Here is the my gams:
set a
/apple, banana, orange, grape/
b
/1*20/
c
/1*20/ ;


Parameter d(a)
/apple 2
banana 4
orange 6
grape 8/;

variable objective;
equation eq1(a);
eq1(a).. objective=e=sum(c$(ord(c)<=(ord(c)+d(a))),sum(b$
((ord(b)<=19),&(ord(b)>=ord(c))),b*c*100));

************************************************************************************************************************
And my equation is actually as follows:

b=19 c=c+d(a)
objective=∑ ∑ (c*b*100).
b=c c=1

So you can see I want to make a summation over b from b=c to b=19, but
I don't know how to define b in the summation equation with both lower
and upper bounds, I just wrote by my intuition but gams did not
recognize the part of bounding b I wrote.
Could you give me some advice?
I really need your help!

Thank you very much!

Best,
Helena






Renger van Nieuwkoop

unread,
Nov 5, 2012, 3:15:04 AM11/5/12
to gams...@googlegroups.com

Hi Helena

 

Gams helps with looking for the error. If I run your code I first get the following error:

 

  8  ')' expected

 

And Gams tells me it is after 19).

 

So  a closing parenthesis is missing (also repair the first error Gams encounters and don’t worry about the following errors)

After correcting this, I get

 

119  Number (primary) expected

 

Gams doesn’t understand the comma, it expects  a number. Deleting the comma and after that replacing the “&” by “and”

And setting the parenthesis correct I get this

 

((ord(b)<=19) AND (ord(b)>=ord(c)))

 

Then Gams complains about b*c*100. These are sets and not numbers! So you can’t add or multiply  these set elements with each other. Either use the extension .val to use the value of this set element (in this case this works fine, as you defined the set consisting of numbers) or use ord again.  I am used to using ord, so it looks now looks like this:

 

eq1(a)..         objective=e=sum(c$(ord(c)<=(ord(c)+d(a))),sum(b$

((ord(b)<=19) AND (ord(b)>=ord(c))),ord(b)*ord(c)*100));

 

Long story in two sentences:

. Use the errors reported by GAMS to debug your model

. Repeat debugging the first error in the listing and running the model again, until no errors are left..

 

Cheers

 

Renger

 

 

Von: gams...@googlegroups.com [mailto:gams...@googlegroups.com] Im Auftrag von Selina
Gesendet: Montag, 5. November 2012 00:24
An: gams...@googlegroups.com
Betreff: Re: summation with a lower bound and upper bound

 

I have the same question. Have you figure it out?

--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/kVUCiFElshsJ.
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.

Reply all
Reply to author
Forward
0 new messages