Defining equation with logical condition on index

Hi everyone,

I’m new to GAMS and since last few days I’m trying code an equation but finding it difficult to do so. In the equation j is an element which belong to intersection of 2 multidimensional sets i.e. JP(jp) and JS(js). Below I’m attaching an image of the equation.
forum_doubt_1.JPG
Also, the code that I have developed for the above equation is as follows:

Constraints8(s,p)..       sum(j,Y(s,j,p)) =e= 1;

Please help if you know how to code this thing. It would be really helpful. Thanks.

You can create multidimensional sets jp(j, p) and js(j, s). Find more information on multidimensional sets here: https://www.gams.com/latest/docs/UG_SetDefinition.html#UG_SetDefinition_Multi-dimensionalSets

set
jp /#j.#p/
js /#j.#s/
;

You can then write your constraint with if condition

constraints8(s, p).. sum(j $(jp(j, p) and js(j, s)), Y(s, j, p)) =e= 1;

Not sure if it is relevant, but I also note that your equation is defined over p^in _p. If this is by any chance a subset of set P, you can define it as
set
p_in(p);

and then assign relevant elements to it.
Hope this helps!

  • Atharv

Hi Athrav,

Thanks a lot for your suggestions, it worked. Also, I forgot to mention that P^in(P) is a subset of P but you have already assumed it correctly. Thank you for helping me out. :slight_smile: