1

I am using GAMS to solve a network distribution problem and this is my first time using GAMS. I have the following constraint (see Image) which I want to write in gams but keep getting errors. Trying to figure it out using IF statement or any other way to solve it. The variable z is a binary variable, which has been declared already.

Thanks!

Image

Manal Jain
  • 25
  • 3

2 Answers2

1

You do not need an if statement, but can handle this with dollar conditions. You can do it with dollar conditions in the equation (as done here), or you could write three separate equations with dollar conditions to define the domain of each equation.

E_z(u,v,i).. sum(j, z(u,v,j,i)) - sum(j, z(u,v,i,j)) 
=E= 
0 + 1$(sameas(i,u)) - 1$(sameas(i,v));

The sameas operator is documented here. If your sets have numerical values, it might be cleaner to do a value comparison, e.g. $(i.val = u.val).

Martin Bonde
  • 536
  • 3
  • 11
  • The part "0 +" directly after the "=E=" could even be left out since "1$(sameas(i,u))" will evaluate to 0 if "i" and "u" are not the same, but that's just cosmetics and probably a question of personal taste. – Lutz Jun 14 '17 at 15:33
  • Yes. I thought making it explicit was clearer. Personally I would prefer to have three separate equations. – Martin Bonde Jun 16 '17 at 12:27
0

You can read more about conditional expressions in GAMS in the following link:

https://www.gams.com/latest/docs/userguides/userguide/_u_g__cond_expr.html

Salva
  • 109
  • 1
  • 9