problem in if statement Topic is solved

Problems with syntax of GAMS
Post Reply
garvisgarg
User
User
Posts: 5
Joined: 2 years ago

problem in if statement

Post by garvisgarg » 2 years ago

hello, I am new to GAMS and I have started coding in GAMS with some small problems. Currently, in one problem I am using 'if' statement as follow:
if (a(t) <=b(t),
p(i,t)=a(t);
else
p(i,t)=b(t);
);
in this code error_119(related to primary number) is occurred.
Thanks in advance for help in future.

User avatar
Renger
Posts: 360
Joined: 2 years ago

Re: problem in if statement

Post by Renger » 2 years ago

Hi

You have to loop over t as Gams doesn't allow this kind of direct assignment in an if-statement:

Code: Select all

loop(t,
	if (a(t) <=b(t),
		p(i,t)=a(t);
	else
		p(i,t)=b(t);
	);
);
You could do this, however using the dollar sign

Code: Select all

p(i,t)$(a(t) < b(t)) = a(t);
p(i,t)$(a(t) > b(t)) = b(t);
p(i,t)$... is pronounced as p(i,t) such that my condition is equal to

Cheers
Renger
____________________________________
Enjoy modeling even more: The lazy economist

Post Reply