Iterating twice through the same set

I am new to GAMS, previously I was using CPLEX, In CPLEX we had iterative variables and sets as separate.
But in GAMS there doesn’t seems to be an iterative variable.

Here is my problem.

Sets
i products / Product1, Product2, Product3, Product4,Product5 /
k customers / Customer1, Customer2,Customer3,Customer4,Customer5, Customer6,Customer7,Customer8,Customer9,Customer10/ ;

Parameters:
r(k,i) ;

Variable
x(k,i) ;

constraint (k,i,j)$(i<>j)… r(k,i)) * x(k,i) =g= r(k,j) )*x(k,i) ;

I wish to add this constraint, i,j both belong to set i , if I duplicate set i and create one more set j, GAMS give me error.
I want to add constraint for i,j both belonging to the Product set when i!=j.

Let me know if the question is unclear.

You are missing “alias” https://www.gams.com/latest/docs/UG_SetDefinition.html#UG_SetDefinition_TheAliasStatementMultipleNamesForASet

All you need to do is create an alias for set i. (say ii)

alias(i, ii);

now you can define your constraint

constraint(k, i, ii) (ord(i) <> ord(ii))..

Hope this helps.

  • Atharv

The alias part is working fine.

But I want to run the constraint for i!=ii.
The code you provided gives the following error.

constraint(k, i, ii) (ord(i) <> ord(ii))…

Error:

‘=’ or ‘…’ or ‘:=’ or ‘$=’ operator expected
rest of statement ignored

Thank You for your reply.

I only provided the part that needs to be corrected. Of course you need the full equation

constraint(k,i,ii)$(ord(i)<>ord(ii)).. r(k,i)) * x(k,i) =g= r(k,ii) )*x(k,i) ;

I don’t know what you are trying to solve, but this constraint itself does not make sense to me. there is x(k, i) on both sides of the equation and r is a parameter. Looks incorrect. I will leave that for you to decide.

  • Atharv