Newsgroups: comp.ai.genetic
Path: cantaloupe.srv.cs.cmu.edu!europa.chnt.gtegsc.com!gatech!swrinde!elroy.jpl.nasa.gov!usc!math.ohio-state.edu!uwm.edu!caen!hearst.acc.Virginia.EDU!murdoch!uvacs.cs.Virginia.EDU!rcc6p
From: rcc6p@uvacs.cs.Virginia.EDU (Robert C. Craighurst)
Subject: Softlib distance function question.
X-Nntp-Posting-Host: mamba-fo.cs.virginia.edu
Message-ID: <DAu91p.1GD@murdoch.acc.Virginia.EDU>
Originator: rcc6p@mamba.cs.Virginia.EDU
Sender: usenet@murdoch.acc.Virginia.EDU
Organization: University of Virginia Computer Science Department
Date: Tue, 27 Jun 1995 15:44:13 GMT
Lines: 79

  I'm having trouble with one of the distance functions for the TSP from
Softlib (ftp softlib.rice.edu in /pub/tsplib/source.)  Gerhard Reinelt
is the archivist for this collection but I've not been able to contact
him.  (reinelt@augsopt.uni-augsburg.de doesn't work.)  If anyone can
give me his current address or help me with the problem I would
greatly appreciate it.

  The distance function for the geographical TSP, as given by Softlib,
has some errors in it.  (I give the details of these errors later for
anyone interested.)  When I correct the errors and try plausible
variants I still do not get the distances that Softlib and Reinelt
publish for certain tours [Reinelt, 1991.]  Below is a comparison
between my distances Reinelt's.

  problem/tour:  GR666/canonical   GR666/optimum    GR96/optimum
  Reinelt:         423,710            294,358          55,209
       Me:         422,156            293,285          54,645

  Has anyone else had this problem?  Can anyone tell me the distance
function that will produce Reinelt's distances?

  Thanks for your help.

---------------------------------------------------------------------
  For those interested, here are Softlib's/Reinelt's equations.  They
are for the geographical TSP.  (The geographical TSP is one where
distances between points are measured along a spherical Earth.)

The longitude and latitude for each city are given as decimals in the
format DDD.MM.  DDD represents the degrees, MM the minutes.  Softlib
gives the following equations to convert degrees/minutes to radians.

1.  PI = 3.141592

2.  deg = aint( x[i] );  /* x[i] is the latitude of city i */
3.  min = x[i] - deg;
4.  latitude[i] = PI * (deg + 5.0 * min) / 3.0) / 180.0;

With similar equations for longitude.  The equations to calculate the
distance between cities i and j from their longitude and latitude in
radians are given as:

5.  RADIUS_OF_EARTH = 6378.388   /* kilometers */

6.  q1 = cos( longitude[i] - longitude[j] );
7.  q2 = cos( latitude[i] - latitude[j] );
8.  q3 = cos( latitude[i] + latitude[j] );
9.  distance = 
     trunc((RADIUS_OF_EARTH * acos( 0.5*((1.0+q1)*q2 - (1.0-q1)*q3))+1.0); 

where "trunc" truncates and "acos" is the inverse cosine function.

Equations 4 and 9 have unmatched parentheses.  Removing the first left
parenthesis from equation 9 turns it into a plausible equation.  I'm
not sure why the "+1.0" was added at the end.  Perhaps to guarantee
that the distance between two cities is never 0.  However, equation 4
needs more work.  Instead of 
   4.  latitude[i] = PI * (deg + 5.0 * min) / 3.0) / 180.0;
I believe they meant to say,
   4'. latitude[i] = PI * (deg + 5.0 * min / 3.0) / 180.0;

Recall that "min" is a decimal value, ranging from .0 to .59.  Then
"5.0 * min / 3.0" converts min to a proportioned decimal ranging from .0
to .9833....

  However, even with these changes, I still do not get Reinelt's
published values.  Tinkering with the values of PI and RADIUS_OF_EARTH
hasn't helped either.  (Even if it had, I would be reluctant to assume
I had the correct distance function.)

  How does Reinelt get his values?

-------------------------------------
Reinelt, Gerhard.  "TSPLIB--A Traveling Saleman Problem Library."  ORSA
Journal of Computing.  Vol 3, No. 4, pp 376-384. Fall 1991.
-- 
---- Rob Craighurst   --   rcc6p@virginia.edu    --   CS Dept, UVa ------
----  And just where is the U.S. Cavalry when I need 'em?  They must ----
----  be around here somewhere...maybe under this pile of papers.... ----
