Cumulative sums

Problems with syntax of GAMS
Post Reply
hermann.westerholt
User
User
Posts: 13
Joined: 4 months ago

Cumulative sums

Post by hermann.westerholt » 3 months ago

Hi all,

I am trying to use a cumulative sum in one of my equations. This is what I am trying to achieve:
cumsum.png


This is the relevant section of my current code:

Code: Select all

set
i=/1*3/;

alias(i,j);

Parameters
CPRL(i)       Production cost for given week and given partition [EUR] /1 456939.268307277
                                                                                 		   2 459320.004138218
                                                                                                   3 462078.056546382/;
                                                                                                    
PRL(i)        PRL in given partition [MW]                                           /1 8
                                                                                                  2 1
                                                                                                  3 1/;
                                                                                                   
Variables
p(i)
askPrice(i);
                                                                                                   
Cost        ..        C =e= sum(i,(p(i)*(CPRL(i) + sum(j$(ord(j) le ord(i)),PRL(i)*askPrice(i)))));


Sadly, the lst file output has very little in common with what I was hoping to see:

Code: Select all

Cost..  - (765265.268307277)*p(1) - (536401.504138218)*p(2)
     
      - (577700.306546382)*p(3) + (0)*askPrice(1) + (0)*askPrice(2)
     
      + (0)*askPrice(3) + C =E= 0 ; (LHS = 0)

All suggestions how to fix this are highly appreciated, thank you in advance!

Best regards,
Hermann

User avatar
Renger
Posts: 125
Joined: 1 year ago

Re: Cumulative sums

Post by Renger » 3 months ago

Hi Hermann

Gams collects all the information on the equation, linearizes it (if non-linear), and moves all variables and constants to the left.
If you have an equation like "a*P1 + b*P2 =E= c*P1" this will appear as:
(a-c)*P1 + b*P2 =E= 0;

If you are not sure, if your code is right, you should use "simple" numbers and check the values accordingly. Here is some of your code

Code: Select all

set
i /1*3/;

alias(i,j);

Parameters
CPRL(i)       Production cost for given week and given partition [EUR] /1 1
                                                                        2 1
                                                                        3 1/,
                                                                                                    

PRL(i)        PRL in given partition [MW]                /1 1
                                                                         2 1
                                                                         3 1/;
                                                                                                   
Variables
p(i)
C
askPrice(i);

equations cost;

Cost..        C =e= sum(i, ( p(i) * (CPRL(i) + sum(j$(ord(j) le ord(i)), PRL(i) * askPrice(i))));

model test /all/;

P.L(i) = 1; askprice.L(i) = 1;
test.iterlim = 0;
solve test minimizing C using NLP;
This gives:

---- cost =E=

cost.. - (2)*p(1) - (3)*p(2) - (4)*p(3) + C - (1)*askPrice(1) - (2)*askPrice(2)

- (3)*askPrice(3) =E= 0 ; (LHS = -9, INFES = 9 ****)

Hope this helps
Renger

hermann.westerholt
User
User
Posts: 13
Joined: 4 months ago

Re: Cumulative sums

Post by hermann.westerholt » 3 months ago

Dear Renger,

thank you very much for your response. I am afraid that my problem description was not accurate enough: the LHS/RHS notation GAMS uses is not the issue (I hope), but I am struggling to transform the equation I have jotted down on paper into correct GAMS code. For your example with simple values, the "paper version" can be found in the attached .png file.
cumsum2.png
This is what I would expect to see in GAMS:

Cost .. c =e= - (1)*p(1) - (1)*p(2) - (1)*p(3) + C - p(2)*(1)*askPrice(1) - p(2)*(1)*askPrice(2) - p(3)*(1)*askPrice(1) - p(3)*(1)*askPrice(2) - p(3)*(1)*askPrice(3)

I think that something must be wrong with my $ statement, but I don't know how to fix this.

Best,
Hermann

User avatar
Renger
Posts: 125
Joined: 1 year ago

Re: Cumulative sums

Post by Renger » 3 months ago

looks correct, as you will have 2 * P(1) as written out it P(1) * CPRL (=1) + P(1) * PRL(=1) * aksPrice(=1) = 2*P(1), etc.

hermann.westerholt
User
User
Posts: 13
Joined: 4 months ago

Re: Cumulative sums

Post by hermann.westerholt » 3 months ago

Oh boy ... I just realised that GAMS does not display multiplications of variables - instead, subsequent variables are replaced by their initial values! It all makes sense now.

Thank you very much, Renger, this has been a valuable lesson.

User avatar
dirkse
Moderator
Moderator
Posts: 21
Joined: 1 year ago
Location: Fairfax, VA

Re: Cumulative sums

Post by dirkse » 3 months ago

Hermann,

To be precise, GAMS displays the linearization of the expression. Since you have multiplication, that linearization will involve the level values for some variables, but that's only because of the product rule for derivatives.

If you have exp(2*x) + exp(3*y) =L= 10; you will not see anything that looks like a level value in the equation listing.

-Steve

Post Reply