New reply based on the comments:
You need to makes sure, the you get the order of and
and not
right. So, what you want is $(not (sameAs(i,"d") and sameAs(j, "k")))
(which is equivalent to $(not sameAs(i,"d") or not sameAs(j, "k")))
instead of $(not sameAs(i,"d") and not sameAs(j, "k"))
. So, here is a dummy model using that:
Sets i index / a, b, c, d /
j / h, k /;
Variables X(i,j), dummy;
Equations EQX(i,j);
EQX(i,j)$(not (sameAs(i,"d") and sameAs(j, "k"))).. X(i,j) =e= dummy;
Model m /EQX/;
Solve m min dummy use lp;
And looking at the equation listing, this is the result:
---- EQX =E=
EQX(a,h).. X(a,h) - dummy =E= 0 ; (LHS = 0)
EQX(a,k).. X(a,k) - dummy =E= 0 ; (LHS = 0)
EQX(b,h).. X(b,h) - dummy =E= 0 ; (LHS = 0)
EQX(b,k).. X(b,k) - dummy =E= 0 ; (LHS = 0)
EQX(c,h).. X(c,h) - dummy =E= 0 ; (LHS = 0)
EQX(c,k).. X(c,k) - dummy =E= 0 ; (LHS = 0)
EQX(d,h).. X(d,h) - dummy =E= 0 ; (LHS = 0)
EDIT: Some details based on a question in the comments
The syntax is a bit tricky!! Is there a reason why the order is important here?
Think of it like this:
You are concerned about exactly one element of the couple (i,j)
and that it 'd'.'k'
. You get this element by writing sameAs(i,"d") and sameAs(j, "k")
. And since this element should be excluded from the list of all possible elements in (i,j)
, you need to negate this operation using not
. For this, you need to keep in mind the order of operations (or operator precedence), which is higher for not
than it is for and
, so that you have to use quotes and write not (sameAs(i,"d") and sameAs(j, "k"))
.
Note that the order of operations is not specific to GAMS, but a general concept in math and programming languages, see for example here.