Aydin
Aydin

Reputation: 187

Error in defining sets and indexes as alias

I'm trying to calculate the euclidean distance between some points. The coordinates of the points are denoted by x(i) and y(i), and the indices i and j are alias. For this I use the following code:

i "Customers";
Alias(i,j);

Parameters
x(i<)/
1        100
2        500
3        200/
y(i<)/
1        150
2        560
3        300/
;

Positive variables
d(i,j)
;

Equations
Eq1
;

Eq1..
d(i,j) =e= power(power(x(i)-x(j),2)+power(y(i)-y(j),2),1/2);

But an error occurs as:

Uncontrolled set entered as constant

which is about the line:

d(i,j) =e= power(power(x(i)-x(j),2)+power(y(i)-y(j),2),1/2);

What could be the reason for this?

Upvotes: 0

Views: 20

Answers (1)

Erwin Kalvelagen
Erwin Kalvelagen

Reputation: 16724

For an indexed equation, you need to use, well, indices. So:

Equations
   Eq1(i,j)
;

Eq1(i,j)..
   d(i,j) =e= sqrt( sqr(x(i)-x(j))+sqr(y(i)-y(j)) );

See any GAMS model that has an equation. I also cleaned up the expression for the length (that was not correct either).

Upvotes: 1

Related Questions