00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #include "VRPH.h"
00014
00015 #define RANDOM 0
00016 #define REGRET 1
00017
00018 int main(int argc, char *argv[])
00019 {
00024
00025 VRPH_version();
00026
00027 int i,n;
00028 char infile[200];
00029
00030 if(argc < 5 || (strncmp(argv[1],"-help",5)==0 || strcmp(argv[1],"-h")==0 || strcmp(argv[1],"--h")==0))
00031 {
00032 fprintf(stderr,"Usage: %s -f vrp_file -m method [-c]\n",argv[0]);
00033 fprintf(stderr,
00034 "\t method should be 0 for CW, 1 for Sweep\n"
00035 "\t If -c option is given, then all routes are cleaned up at the end\n"
00036 "\t\t by running intra-route improvements\n");
00037 exit(-1);
00038 }
00039
00040 bool has_filename=false, clean_up=false;
00041 for(i=1;i<argc;i++)
00042 {
00043 if(strcmp(argv[i],"-f")==0)
00044 {
00045 strcpy(infile,argv[i+1]);
00046 has_filename=true;
00047 }
00048 }
00049
00050 if(has_filename==false)
00051 report_error("No input file given\n");
00052
00053 n=VRPGetDimension(infile);
00054
00055 VRP V(n);
00056
00057
00058 int method=-1;
00059 for(i=1;i<argc;i++)
00060 {
00061 if(strcmp(argv[i],"-m")==0)
00062 method=atoi(argv[i+1]);
00063 if(strcmp(argv[i],"-c")==0)
00064 clean_up=true;
00065 }
00066 if(method<0)
00067 report_error("method must be 0 or 1\n");
00068
00069
00070 V.read_TSPLIB_file(infile);
00071
00072 Sweep sweep;
00073 ClarkeWright CW(n);
00074
00075 if(method==0)
00076 {
00077
00078 printf("Finding initial solution using Clarke-Wright algorithm\n");
00079 CW.Construct(&V, 1.0, false);
00080
00081 }
00082 else
00083 {
00084 printf("Finding initial solution using Sweep algorithm\n");
00085 sweep.Construct(&V);
00086 }
00087
00088 if(clean_up)
00089 {
00090 printf("Total route length before clean up: %f\n",V.get_total_route_length()-V.get_total_service_time());
00091 V.normalize_route_numbers();
00092 for(i=1;i<=V.get_total_number_of_routes();i++)
00093 V.clean_route(i,ONE_POINT_MOVE+TWO_POINT_MOVE+TWO_OPT);
00094 }
00095
00096
00097 V.summary();
00098 return 0;
00099
00100 }
00101