/* Example of using dynamic program subroutines for the geographic instances on the largest US cities, designed by Neil Simonetti */ #include #include #define MAXSIZE 2000 long int lon[MAXSIZE], lat[MAXSIZE]; /* coordinates of cities in millionths of a degree */ long int tourA[MAXSIZE],tourB[MAXSIZE]; /* space for input/output */ long int *tour1=tourA, *tour2=tourB, /* pointers to space */ *tourswap; /* swap space for space */ #define swapTour {tourswap=tour1;tour1=tour2;tour2=tourswap;} #define _shrink 1 #define cs(x) cos(x*0.00000001745329251994) #define sn(x) sin(x*0.00000001745329251994) #define theNorm(a,b) (acos(cs(lon[a])*cs(lat[a])*cs(lon[b])*cs(lat[b])+sn(lon[a])*cs(lat[a])*sn(lon[b])*cs(lat[b])+sn(lat[a])*sn(lat[b]))*63781.5) #include "solver.h" int ReadData(char *fname) { FILE *inpf; int c,d,n; char iStr[50]; if ((inpf = fopen(fname, "r")) == NULL) { fprintf(stderr,"error with input file %s\n",fname); exit(1); } for (c=0;fname[c]!='.';c++); fname[c]=0; sscanf (fname+4,"%d",&n); for (c=0; cMAXSIZE) { fprintf(stderr,"problem size too big.\n"); exit(1); } GetAuxgraph(k,n,h,2); printf("Constructing Nearest Neighbor Tour...\n"); LastCost = (CurrentCost = NearestNeighbor(tour1,tour2,n))+1; while(CurrentCost < LastCost && i(d=random()%(n-k)))?d:c; CurrentCost = DynOpt(k,n,h,13,targ,tour1,tour2,0L); if (tour2[0]==n) {i=iLim;} } printf("Final Cost: %d\n",CurrentCost); printf("Sequence:\n"); if (tour2[0]