## Unique key use for a closed form constraint Topic is solved

Problems with syntax of GAMS
mrv_ce
User Posts: 19
Joined: 1 year ago

### Unique key use for a closed form constraint

Hello everybody,

I'm conducting a research and I need to write a constraint for my model in GAMS. Can you help me?

L(A(i),C(m)) +e =l= L(A(i),C(k))-r

In this constraint L is distance function it calculates the distance between A(i) and C(m). i is alternative set. m is class set. The constraint compares their distance values. The constraint will work for every i and m not equal to k set. (m and k is the same set) However for each i, I have a defined m value. So LHS of the constaint for each i is defined. I need to write RHS of the equation m not equal to k. (for any i, m is specified and k can not be equal to the m)

This is the point that I cannot write. I thought new defined parameter for unique i and m combination can be used but I can ot add it to the existing equation. Up to now I write their open form but for each data set I need to write the model again.

Thanks a lot.

Note: e is error decision variable. r is very small constant value to get rid of equality of L functions.

Renger
Posts: 447
Joined: 3 years ago

### Re: Unique key use for a closed form constraint

Hi
If I understand your question correctly, this could be solved by a mapping between i and m for every combination that is valid, e.g.

Code: Select all

``````set i /i1, i2, i3/, set m /m1, m2, m3, m4/;
alias(m,k);

set mapI_M(i,m)  Allowed combinations of i and m
/ i1.m2, i2.m4, i3.m1/;

equations
myconstraint(i, m,k);

mycontrainst(i,m,k)\$(map(i,m) and not sameas(m,k))..
L(A(i),C(m)) +e =l= L(A(i),C(k))-r ;
``````
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

mrv_ce
User Posts: 19
Joined: 1 year ago

### Re: Unique key use for a closed form constraint

Thanks a lot. It is very useful for me.