## Defining equation with logical condition on index

Vivek
User Posts: 2
Joined: 2 months ago

### 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(j*p) and JS(j*s). Below I'm attaching an image of the equation. forum_doubt_1.JPG (10.7 KiB) Viewed 249 times
Also, the code that I have developed for the above equation is as follows:

Code: Select all

``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.

abhosekar
Moderator Posts: 176
Joined: 8 months ago

### Re: Defining equation with logical condition on index

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_Set ... sionalSets

Code: Select all

``````set
jp /#j.#p/
js /#j.#s/
;
``````
You can then write your constraint with if condition

Code: Select all

``````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

Vivek
User Posts: 2
Joined: 2 months ago

### Re: Defining equation with logical condition on index

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. 