Gams problem: "sum" statement seems to return 0 unexpectedly

Archive of Gamsworld Google Group
Post Reply
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Gams problem: "sum" statement seems to return 0 unexpectedly

Post by Archiver »



Hi

I am having a problem with some code which uses a sum statement, it
appears to be returning zero when I would not expect this to be the
case. The problem is two fold:
1. I dont expect the data to return zero ever
2. The problem seems in consistent, if i repeat the sum statement
after the first statement fails, it appears to work.

I have double checked my sets and parameters etc in the .lst file
below to verify the data is not be zero. Of course this does not seem
to explain (2) above. I have chopped out the relevant pieces of code
below and added comments to show where it is going strange, I dumped a
ton of other stuff so in some cases its going to seem odd/unneccessary
but just bear with it, its only the summing to zero part that I would
like focused on.

I imagine I am doing something dumb :)

The data is pretty simply, t = a nominal block of time, s = seasons,
mapts maps blocks to seasons, duration(t) is the number of hours in
that block. All I am trying to do is count the number of hours in a
particular season. Eg if summer contains blocks 1 2 & 3 then it would
sum up the duration of blocks 1 2 & 3.

scalar temp1;
Set
s Seasons /
Summer
Shoulder
Winter
/;
alias (s,ss);
set
thisRecord_s(s) "Which season(s) are covered by the
record being written"
;

Set
t /
B1
B2
B3
B4
B5
B6
B7
B8
B9
B10
B11
/;

Set Mapts(t,s) Mapping of blocks to seasons /
B1 . Summer
B2 . Summer
B3 . Summer
B4 . Summer
B5 . Summer
B6 . Winter
B7 . Winter
B8 . Winter
B9 . Shoulder
B10 . Shoulder
B11 . Shoulder

---- 19296 PARAMETER Duration Duration of blocks in thousands of
hours

B1 1.224, B2 0.688, B3 0.704, B4 0.352, B5 0.704,
B6 0.720, B7 0.432, B8 1.008, B9 0.976
B10 0.560, B11 1.392


loop (s) do

{Is this entry annual (all seasons) or seasonal?}
if (%gAnnual%) then
thisRecord_s(ss) = yes; {turn all seasons on for reporting}
t_SeasonAdj = 1;
else
{-->THIS IS THE PART WHICH IS EXECUTING IN MY
INSTANCE 0, but.....}
if (NOT temp1) then

{ --> ....this fires in SUMMER (not winter or shoulder)}
{ this should NOT fire ever! }

Display "Got here a";
temp1 = sum(mapts(t,thisRecord_s), duration(t));
if (NOT temp1) then
Display "Got here b"; {<-- this never fires! Its the
same sum code from above!!! why?}
endif;
temp1 = sum((t,thisRecord_s)$mapts(t,thisRecord_s),
duration(t)); {try different code}
if (NOT temp1) then
Display "Got here c"; {<-- this never fires}
endif;
elseif (temp1 = 123456) then
Display "Got here d"; {<-- this never fires}
endif;


endloop; {s}


All help greatly appreciated.

Regards
AndyC
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---


Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: Gams problem: "sum" statement seems to return 0 unexpectedly

Post by Archiver »



I received a response from GAMS, which I will repeat here to assist
anyone else experiencing this problem.

The response was basically that there was an issue which was fixed in
v20 and above. Moving up to the later version is the fix for the
problem



On Oct 13, 2:48 pm, AC wrote:
> > Hi
> >
> > I am having a problem with some code which uses a sum statement, it
> > appears to be returning zero when I would not expect this to be the
> > case. The problem is two fold:
> > 1. I dont expect the data to return zero ever
> > 2. The problem seems in consistent, if i repeat the sum statement
> > after the first statement fails, it appears to work.
> >
> > I have double checked my sets and parameters etc in the .lst file
> > below to verify the data is not be zero. Of course this does not seem
> > to explain (2) above. I have chopped out the relevant pieces of code
> > below and added comments to show where it is going strange, I dumped a
> > ton of other stuff so in some cases its going to seem odd/unneccessary
> > but just bear with it, its only the summing to zero part that I would
> > like focused on.
> >
> > I imagine I am doing something dumb :)
> >
> > The data is pretty simply, t = a nominal block of time, s = seasons,
> > mapts maps blocks to seasons, duration(t) is the number of hours in
> > that block. All I am trying to do is count the number of hours in a
> > particular season. Eg if summer contains blocks 1 2 & 3 then it would
> > sum up the duration of blocks 1 2 & 3.
> >
> > scalar temp1;
> > Set
> > s Seasons /
> > Summer
> > Shoulder
> > Winter
> > /;
> > alias (s,ss);
> > set
> > thisRecord_s(s) "Which season(s) are covered by the
> > record being written"
> > ;
> >
> > Set
> > t /
> > B1
> > B2
> > B3
> > B4
> > B5
> > B6
> > B7
> > B8
> > B9
> > B10
> > B11
> > /;
> >
> > Set Mapts(t,s) Mapping of blocks to seasons /
> > B1 . Summer
> > B2 . Summer
> > B3 . Summer
> > B4 . Summer
> > B5 . Summer
> > B6 . Winter
> > B7 . Winter
> > B8 . Winter
> > B9 . Shoulder
> > B10 . Shoulder
> > B11 . Shoulder
> >
> > ---- 19296 PARAMETER Duration Duration of blocks in thousands of
> > hours
> >
> > B1 1.224, B2 0.688, B3 0.704, B4 0.352, B5 0.704,
> > B6 0.720, B7 0.432, B8 1.008, B9 0.976
> > B10 0.560, B11 1.392
> >
> > loop (s) do
> >
> > {Is this entry annual (all seasons) or seasonal?}
> > if (%gAnnual%) then
> > thisRecord_s(ss) = yes; {turn all seasons on for reporting}
> > t_SeasonAdj = 1;
> > else
> > {-->THIS IS THE PART WHICH IS EXECUTING IN MY
> > INSTANCE > thisRecord_s(ss) = no; {initially turn off all seasons...}
> > thisRecord_s(s) = yes; {...then only report this season}
> > t_SeasonAdj = sum(mapts(t,s), Duration(t)) /
> > sum(mapts(t,ss), Duration(t)); {weight adjustment factor based on how
> > many hours in this season}
> > endif;
> >
> > {DEBUGGING BELOW}
> > temp1 = 123456;
> > temp1 = sum(mapts(t,thisRecord_s), duration(t)); {this
> > should always be > 0, but.....}
> > if (NOT temp1) then
> >
> > { --> ....this fires in SUMMER (not winter or shoulder)}
> > { this should NOT fire ever! }
> >
> > Display "Got here a";
> > temp1 = sum(mapts(t,thisRecord_s), duration(t));
> > if (NOT temp1) then
> > Display "Got here b"; { > same sum code from above!!! why?}
> > endif;
> > temp1 = sum((t,thisRecord_s)$mapts(t,thisRecord_s),
> > duration(t)); {try different code}
> > if (NOT temp1) then
> > Display "Got here c"; { > endif;
> > elseif (temp1 = 123456) then
> > Display "Got here d"; { > endif;
> >
> > endloop; {s}
> >
> > All help greatly appreciated.
> >
> > Regards
> > AndyC
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---


Post Reply