Summing over specific range Topic is solved

Problems with syntax of GAMS
Post Reply
scouser_s
User
User
Posts: 8
Joined: 4 years ago

Summing over specific range

Post by scouser_s »

I want to define three equations for three-time steps.

For the first hour, I can write the following:

p(s,h) $(ord(h) eq 1)..

The last hour will be the following:

p(s,h) $(ord(h) eq card(h))..

I am trying to write equations for the hours in between something like this but can't get the syntax right.

p(s,h) $(ord(h) gt 1 & ord(h) lt card(h))..

I would appreciate any help on this.
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Summing over specific range

Post by Renger »

Hi
Yould define a parameter as follows:

Code: Select all

alias(h,ah);

parameter hnr(h)  Hour ord;

hnr(h) = ord(h);

p(s,h,ah)$(ord(h) eq hnr(h))..
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
kontrail
User
User
Posts: 1
Joined: 3 years ago

Re: Summing over specific range

Post by kontrail »

Suppose that you are hired as a decision maker for a charity organization called "Help!". This year the
organisation is planning to distribute support packages including basic needs (bottles of water, bread, canned
food etc.) to people in need in their neighbourhood. Some volunteers collected data from around and found
that there are 24 houses which are suitable for this support and gave you the coordinates for those houses.

Houses 1 2 3 4 5 6 7 8 9 10 11 12
x 6 14 14 4 3 10 20 7 12 5 16 6
y 19 7 4 6 13 12 8 17 12 11 19 6
Houses 13 14 15 16 17 18 19 20 21 22 23 24
x 11 14 18 20 11 3 3 6 17 6 17 5
y 16 16 8 12 2 2 11 16 19 3 12 10
Table 1: Coordinates of the houses.
According to the given information try to make decisions for the following problems

Could you help me please :) have a healtyh days
scouser_s
User
User
Posts: 8
Joined: 4 years ago

Re: Summing over specific range

Post by scouser_s »

Renger wrote: 3 years ago Hi
Yould define a parameter as follows:

Code: Select all

alias(h,ah);

parameter hnr(h)  Hour ord;

hnr(h) = ord(h);

p(s,h,ah)$(ord(h) eq hnr(h))..
Cheers
Renger
I tried the proposed way but I think I didn't quite understand the way you proposed to solve this. Let's say,

Code: Select all

set h /1*10/;

p(s,h) $(ord(h) eq 1)..
p(s,h) $(ord(h) eq card(h))..
How do I write the code using the method you suggested for hours 2 to 9. I really appreciate your help on this.
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Summing over specific range

Post by Renger »

Hi

Sorry, my mistake. Here a solution: you split the equation in three parts and use the conditions on those parts

Code: Select all

p(s,h)..  A(s,h) =E= 
	12$(ord(h) = 1 )$(ord(h) eq 1) + 
	10$(ord(h) >  1 and ord(h) < card(h));
	8$(ord(h) = card(h);
	
THis will result in A(s,h) begin 12 in the first hour, 10 in the in-between hours, and 8 in the last hour.
I hope this helps
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply