0

I am using GAMS, and have defined two sets in the following way:

Sets
      i        index
     /a    
      b   
      C    
      d    /

j 
/h 
k
/

I now wish to declare a variable of dimension (i,j) as X(i,j):

Variables

X(i,j);

However, I do not wish that the equation list include the specific i value of d and j value of k. Essentially, I would like it to de-select EQX("d,"k") only, while keeping all the other equations for each combination of i and j.

I would normally type:

Equations
EQX(i,j) ;

EQX(i,j)$ (not sameAs(i,"d") and not sameAs(j, "k"))..

However, in stead of de-selecting that EQ, the script de-selects all equations. Is there something off with my syntax?

ChinG
  • 125
  • 7
  • What you posted should generate an error, since j is not controlled for EQX(i). How do you want to exclude a specific j, if nothing is generated for j? – Lutz Feb 23 '23 at 07:02
  • @Lutz Thanks for that- oversight on my part. Thanks. – ChinG Feb 23 '23 at 12:54
  • OK, that looks better now. But what do you actually mean by "However, this does not seem to be doing what I want it to do"? It would be helpful, if you could provide details about what it does compared to your expectations. – Lutz Feb 23 '23 at 13:57
  • @Lutz Thank yo u so much. I have made the question more detailed since. – ChinG Feb 24 '23 at 14:02

1 Answers1

1

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.

Lutz
  • 2,197
  • 1
  • 10
  • 12
  • This is precisely what is the issue. The only equation I want dropped is EQ(d,k). For instance, I would want EQ(d,h), equation EQ(c,k), EQ(a,k) and so on. The "and" operator here seems to function as an "or" operator. – ChinG Feb 24 '23 at 15:14
  • 1
    Now I got it! What you want is `not (d and k)` instead of (`not d and not k`). I'll adjust my reply. – Lutz Feb 24 '23 at 20:43
  • Thank you so much as usual:) Very helpful. The syntax is a bit tricky!! Is there a reason why the order is important here? – ChinG Feb 24 '23 at 23:51
  • I added some explanation to the end of my reply. Hope that helps – Lutz Feb 26 '23 at 06:07