/* Example of using dynamic program subroutines for the TSPLIB instances with norm EUC_2D */ #include #include #define MAXSIZE 20000 double xloc[MAXSIZE], yloc[MAXSIZE]; /* coordinates of cities */ long int tour1[MAXSIZE],tour2[MAXSIZE]; /* space for input/output */ #define round(n) ((int)((n)+0.5)) #define theNorm(a,b) round(sqrt(((xloc[a])-(xloc[b]))*((xloc[a])-(xloc[b]))+((yloc[a])-(yloc[b]))*((yloc[a])-(yloc[b])))) #include "solver.h" int ReadData(char *fname) { FILE *inpf; int c,d,n; char iStr[50],tStr[20]; if ((inpf = fopen(fname, "r")) == NULL) { fprintf(stderr,"error with input file %s\n",fname); exit(1); } fgets(iStr,50,inpf); while (iStr[0]!='D') {fgets(iStr,50,inpf);} sscanf (iStr+11,"%d",&n); while (iStr[0]!='E') {fgets(iStr,50,inpf);} sscanf(iStr+18,"%s",tStr); if (strcmp("EUC_2D",tStr)!=0) { fprintf(stderr,"code designed for norms of type EUC_2D\n"); exit(1); } while (iStr[0]!='N') {fgets(iStr,50,inpf);} for (c=0; cMAXSIZE) { fprintf(stderr,"problem size too big.\n"); exit(1); } GetAuxgraph(k,n,h,1); printf("Constructing Nearest Neighbor Tour...\n"); NearestNeighbor(tour1,tour2,n); for (c=0;c