Distance Matrix

13 views
Skip to first unread message

Prabhupad Bharadwaj

unread,
Nov 13, 2017, 12:29:11 PM11/13/17
to AMPL Modeling Language
Hello Experts
I want to generate distance matrix between points when the points x coordinate and y coordinate of points are known.I need to calculate the euclidean distance between points and generate distance matrix for a Model
Please help me in coding
Data are like X Y
Depot 0 0
P1 7.976 -9
P2 -2.61 0.039
P3 4.487 7.142
P4 8.938 -4.388
P5 -4.172 -9.096
D1 4.404 -1.952
D2 0.673 6.283
D3 7.032 2.808
D4 -0.694 -7.098
D5 3.763 -7.269
Depot 0 0

Robert Fourer

unread,
Nov 14, 2017, 2:10:56 PM11/14/17
to am...@googlegroups.com
Your model could specify the data as

set POINTS;
param X {POINTS};
param Y {POINTS};

Then you could define a distance table by

param distance {i in POINTS, j in POINTS} = sqrt((X[i]-X[j])^2 + (Y[i]-Y[j])^2);

Bob Fourer
am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages