-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please add support for EDGE_WEIGHT_TYPE : GEOM #13
Comments
Hey, thank you - glad you find it useful :) The |
Also, I think the error message here doesn't really help point you to the problem very well, so I'll improve that for the next version 👍 |
Changing |
Excellent - glad it's working for you. While I want to agree, that's a pretty slippery slope. What about |
In this case you can check |
Okay, so I visited the site and read about the World TSP challenge at http://www.math.uwaterloo.ca/tsp/world/. It says:
That lists some C code for calculating #undef M_PI
#define M_PI 3.14159265358979323846264
int geom_edgelen (int i, int j, CCdatagroup *dat)
{
double lati, latj, longi, longj;
double q1, q2, q3, q4, q5;
lati = M_PI * dat->x[i] / 180.0;
latj = M_PI * dat->x[j] / 180.0;
longi = M_PI * dat->y[i] / 180.0;
longj = M_PI * dat->y[j] / 180.0;
q1 = cos (latj) * sin(longi - longj);
q3 = sin((longi - longj)/2.0);
q4 = cos((longi - longj)/2.0);
q2 = sin(lati + latj) * q3 * q3 - sin(lati - latj) * q4 * q4;
q5 = cos(lati - latj) * q4 * q4 - cos(lati + latj) * q3 * q3;
return (int) (6378388.0 * atan2(sqrt(q1*q1 + q2*q2), q5) + 1.0);
} So this is actually a Obviously, the first thing you'll want to do is translate that C code into a Python function. Next, you need to add it to the map of All together, it should look something like this: import math
import tsplib95
def geom_edgelen(a, b):
lat_i = math.PI * a / 180.0
...
return int(6378388 * math.atan2(math.sqrt(q1 * q1 + q2 * q2), q5) + 1)
# make sure we do this before we try to load the problem
tsplib95.distances.TYPES['GEOM'] = geom_edgelen
problem = tsplib95.load('path/to/world.tsp') |
Hello! Thanks for your library, I'm using
tsplib95-0.7.1
. Could you please add support forEDGE_WEIGHT_TYPE : GEOM
in tsp files, like in world.tsp. Right nowtsplib95
throws an error when I try to load such file:The text was updated successfully, but these errors were encountered: