How can a three-way equality constraint be defined in GAMS? Topic is solved

Problems with modeling
Post Reply
teo21r
User
User
Posts: 10
Joined: 3 years ago

How can a three-way equality constraint be defined in GAMS?

Post by teo21r »

Hey there,

I have a model that includes (among other constraints) constraints v1-v3 below:

Code: Select all

v1(i,inp)$p1(i)..         x(inp,i)=G=sum(p1,lambda1(i,p1)*x(inp,p1));
v2(i,inp)$p1(i)..         x(inp,i))=G=sum(p1,lambda2(i,p1)*x(inp,p1));
v3(i,inp)$p1(i)..         x(inp,i)=G=sum(p1,lambda3(i,p1)*x(inp,p1));
I'd like to include in the model an interdependence constraint that is essentially a three-way equality of the right-hand side terms of constraints v1-v3 as follows:

Code: Select all

inter(i,inp)$p1(i)..          sum(p1,lambda1(i,p1)*x(inp,p1))=E=sum(p1,lambda2(i,p1)*x(inp,p1))=E=sum(p1,lambda3(i,p1)*x(inp,p1));
When I include such a constraint in the model I get the following error (related to the newly added constraint):
Error 409. Unrecognizable item - skip to find a new statement
looking for a ';' or a key word to get started again.

Is there a way to define such a three-way equality constraint in GAMS? If not, then will the solution be to use the transitivity rule and break down the above three-way equality constraint into two separate equalities as below?

Code: Select all

sum(p1,lambda1(i,p1)*x(inp,p1))=E=sum(p1,lambda2(i,p1)*x(inp,p1));
sum(p1,lambda2(i,p1)*x(inp,p1))=E=sum(p1,lambda3(i,p1)*x(inp,p1));
Thank you in advance for your help.

Teo
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: How can a three-way equality constraint be defined in GAMS?

Post by abhosekar »

Looking at first three equations v1, v2, v3. If the left hand side is the same, it automatically implies that all right hand sides are equal. So I don't see the need to add any extra constraint.

You cannot define a three way equality in GAMS syntax so if it all you have to do this, you can use transitivity as you showed in the last two equations.

HTH
-Atharv
User avatar
dirkse
Moderator
Moderator
Posts: 214
Joined: 7 years ago
Location: Fairfax, VA

Re: How can a three-way equality constraint be defined in GAMS?

Post by dirkse »

Teo,

Your primary question was about how to write A == B == C. You are correct in supposing that the way to write this is to use two equations:

Code: Select all

f1..  A =E= B;
f2..  B =E= C;
I have some additional comments about how you might use auxiliary variables. Your formulations included several sums that you use repeatedly. It such a case it can make the model more sparse and essentially smaller to use auxiliary vars for these sums. Even though you add rows and columns, the number of nonzeros goes down. This can be helpful overall, but there is no guarantee. You just try it both ways.

So to be specific, introduce a variable s1(i,inp) and an equation defs1(i,inp) like this:

Code: Select all

defs1(i,inp)$p1(i)..         s1(i,inp) =E= sum(p1,lambda1(i,p1)*x(inp,p1));
and use s1 instead of the sum in both your equations v1-v3 and in the equality constraints. Ditto for the sums involving lambda2 and lambda3. This can result in a substantial reduction in nonzero count if your sums are used many times.

HTH,

-Steve
teo21r
User
User
Posts: 10
Joined: 3 years ago

Re: How can a three-way equality constraint be defined in GAMS?

Post by teo21r »

Atharv and Steve,

Thank you for your quick reply. Your answers were very helpful!

Best,
Teo
Post Reply