Page 1 of 1

problem in if statement

Posted: Fri Jun 30, 2017 1:11 pm
by garvisgarg
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.

Re: problem in if statement

Posted: Sat Jul 01, 2017 4:23 pm
by Renger
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