Read part of a table

Problems with syntax of GAMS
Post Reply
Stan
User
User
Posts: 1
Joined: 6 years ago

Read part of a table

Post by Stan »

Hello,

I'm Beginning with GAMS. I would like to know if it's possible to do loop with "sub-set"? For example considering a table with the months of the year /M1*M120/, is it possible to create sub-set as /M1*M12/, /M13*M24/, /M25*M36/ etc.. and do a loop on a statement in order to have the results for each year?
Or do I have to do several tables?

Thank you for your help,

Stan
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Read part of a table

Post by Renger »

Hi Stan

You can build subsets like this

Code: Select all

set
	year '		'Full set of years' /M1*M120/;
	year1(year) 	'First half of all years' /M1*M12/,
	year2(year)	'Second half of all years' /M25*M36/;
loop(year1, 
....
);
or loop over all years but constrain the loop to the first half

Code: Select all

loop(year$year1(year),
..
);
If you have a table over all years, eg.

Code: Select all

info(year, techn)  Table with info on each technology for each year;
You could for example values to a parameter with only values of the first half of years:

Code: Select all

parameter firstech(year1, techn);
firsttech(year1, techn) = info(year1, techn);
Hope this helps
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply