## Loop for objective function

Problems with syntax of GAMS
Luqman Hakeem
User
Posts: 21
Joined: 2 months ago

### Re: Loop for objective function

Renger wrote:
1 month ago
Same procedure:
replace the parameter or variable with one without the index t, remove the sum and, if it is a parameter, initialize it in the loop with the value for period t
Cheers
Renger
It is basically a constraint over a binary variable 'h' as;
retro(i) .. sum(tc, h(i,tc)) =l= 1;
It should run only once (means 'sum of h < 1'). Summation is working but this summation appears in every loop for "t" which is not required.

Luqman Hakeem
User
Posts: 21
Joined: 2 months ago

### Re: Loop for objective function

Renger wrote:
1 month ago
Same procedure:
replace the parameter or variable with one without the index t, remove the sum and, if it is a parameter, initialize it in the loop with the value for period t
Cheers
Renger
Hi Renger!

In the attached file "HGDPwFS", 'h(i,tc)' is a binary variable for fuel switching retrofitting. Retrofitting should only be done only once in the time horizon. But it appears for every loop on "t".
HGDPwFS.gms
input2.xlsx

Renger
Posts: 550
Joined: 3 years ago

### Re: Loop for objective function

Hi

I think you could do without t in H(i,t). Then, if in year x, H(i) becomes 1, you fix it to that level and it will stay like this in all t afterwards.

Code: Select all

``if(h(i) = 1; h.FX(i)  = 1;);``
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

Luqman Hakeem
User
Posts: 21
Joined: 2 months ago

### Re: Loop for objective function

Renger wrote:
1 month ago
Hi

I think you could do without t in H(i,t). Then, if in year x, H(i) becomes 1, you fix it to that level and it will stay like this in all t afterwards.

Code: Select all

``if(h(i) = 1; h.FX(i)  = 1;);``
Cheers
Renger
Hi Renger,
Your idea is good as always. But it is showing following errors.
input2.xlsx
141 Symbol declared but no values have been assigned. Check for missing
via a solve statement.
A wild shot: You may have spurious commas in the explanatory
text of a declaration. Check symbol reference list.
143 A suffix is missing
149 Uncontrolled set entered as constant
257 Solve statement not checked because of previous errors
HGDPwFSPangy.gms

Renger
Posts: 550
Joined: 3 years ago

### Re: Loop for objective function

Hi Hakeem
I am not sure if this is what you are looking for
HGDPwFSPangy.gms