Question: Using this code for Java in eclipse, Create a program that will take in 5 user-input geocodes and use the haversine formula to compute the

Using this code for Java in eclipse, Create a program that will take in 5 user-input geocodes and use the haversine formula to compute the distance between each geocode and create a graph from this. Then another program that uses "traveling salesman problem" to find the sequence of visits that will show the shortest amount of travel between each geocode

Haversine Code:

#include

#include

#include

#define M_PI 3.14

double CalculateDistance(double,double,double,double);

void main(void){

printf("Distance: %f ",CalculateDistance(40.458896, -73.985130, 41.825226, -71.418884));

}

double CalculateDistance( double nLat1, double nLon1, double nLat2, double nLon2 )

{

int nRadius = 3959; // Earth's radius in Kilometers

double nDLat = (nLat2 - nLat1) * (M_PI/180);

double nDLon = (nLon2 - nLon1) * (M_PI/180);

double nA = pow ( sin(nDLat/2), 2 ) + cos(nLat1) * cos(nLat2) * pow ( sin(nDLon/2), 2 );

double nC = 2 * atan2( sqrt(nA), sqrt( 1 - nA ));

double nD = nRadius * nC;

return nD; // Return our calculated distance

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!