Power, rPower, Sum Functions

Hey everyone,

I am trying to code the following inequality in GAMS for an assignment:
image.png
Where the D^p is the minkowski distance between two points.
image.png
Hence, I tried to code this equation in gams as follows:

constraint1(k,n,t)$(ord(n)<>ord(t))..rPower(sum(j,w(j)*power(((a(k,j))-y(n,j)),p)),(1/p))-e(k)=l=rPower(sum(j,w(j)*power(((a(k,j))-m(t,j)),p)),(1/p))-r;

But the code is not correct somehow. When I check the gams output in the equation listings, I always get values way off even for the very small (a_kj-y_nj) values.
image.png
In this example, there are 4 w values, p=2, and largest a_kj-y_nj=2.75. However the output is like this. I also attach the gams code in a txt file.

Would appreciate if someone could help me out.

Best wishes
code.txt (1.14 KB)
image.png
image.png

Sorry to post again, but it’s extremely important to me and time is running up for me. If someone has an idea, could you please share? Thanks :slight_smile:

Hi, i don’t have too much information but you can try this

sets k 1 to 18?? /1*18/
     j 1 to 3??  /1*3/
     n 1 to 18?? /1*18/
;
alias(n,t)
;

constraint1(k,n)..                           D_p(k,n) =e= rPower(sum(j,w(j)*power(((a(k,j))-y(n,j)),p)),(1/p));
constraint2(k,n,t)$(ord(t) ne ord(n)).. D_p(k,n)-e(k) =l= D_p(k,t)-r;

please check the sets and alias

best

Hey, thank you so much for your response! I have managed to overcome the problem of taking different values in a set. But I believe there is something wrong with the expression inside the constraint:

rPower(sum(j,w(j)*power(((a(k,j))-y(n,j)),p)),(1/p))-e(k)=l=rPower(sum(j,w(j)*power(((a(k,j))-m(t,j)),p)),(1/p))-r

I get way off values when I check them from the Gams output(I edited and added a screenshot to the main post.). Do you think there is something wrong with this expression?

Hi, when I can I will observe what you shared. But, remember that it is an NLP problem so the equations shown by the lst file are a linear approximation of them.
Best!

Sure, I’ll be waiting for your response :slight_smile:

I don’t exactly know what the issue is. You are concerned with the equation listing which is the linearized model instance at the input point. Since you don’t pay attention setting the input point, the equation listing is of little concern I think. Look at what solution the solver generates in the solution report. At least MINOS find an (locally) optimal solution for your model.

-Michael

Hi, i think there are no problems in the equation “constraint1”. I can’t tell you if the model is ok or not because I don’t know the problem.
best!