Power, rPower, Sum Functions

Problems with modeling
Post Reply
diabolik
User
User
Posts: 14
Joined: 1 year ago

Power, rPower, Sum Functions

Post by diabolik »

Hey everyone,

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

Code: Select all

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 KiB) Downloaded 126 times
Attachments
image.png
image.png
Last edited by diabolik 1 year ago, edited 2 times in total.
diabolik
User
User
Posts: 14
Joined: 1 year ago

Re: Special case for constraints

Post by diabolik »

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 :)
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: Special case for constraints

Post by Manassaldi »

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

Code: Select all

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
diabolik
User
User
Posts: 14
Joined: 1 year ago

Re: Special case for constraints

Post by diabolik »

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:

Code: Select all

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?
Manassaldi wrote: 1 year ago Hi, i don't have too much information but you can try this

Code: Select all

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
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: Power, rPower, Sum Functions

Post by Manassaldi »

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!
diabolik
User
User
Posts: 14
Joined: 1 year ago

Re: Power, rPower, Sum Functions

Post by diabolik »

Sure, I'll be waiting for your response :)
Manassaldi wrote: 1 year ago 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!
User avatar
bussieck
Moderator
Moderator
Posts: 1038
Joined: 7 years ago

Re: Power, rPower, Sum Functions

Post by bussieck »

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
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: Power, rPower, Sum Functions

Post by Manassaldi »

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!
Post Reply