VRPH
1.0
|
00001 00002 // // 00003 // This file is part of the VRPH software package for // 00004 // generating solutions to vehicle routing problems. // 00005 // VRPH was developed by Chris Groer (cgroer@gmail.com). // 00006 // // 00007 // (c) Copyright 2010 Chris Groer. // 00008 // All Rights Reserved. VRPH is licensed under the // 00009 // Common Public License. See LICENSE file for details. // 00010 // // 00012 00013 #include "VRPH.h" 00014 00015 00016 int main(int argc, char *argv[]) 00017 { 00022 00023 VRPH_version(); 00024 00025 char in[VRPH_STRING_SIZE], plotfile[VRPH_STRING_SIZE],pdffile[VRPH_STRING_SIZE], 00026 solfile[VRPH_STRING_SIZE]; 00027 00028 int i,n; 00029 int orientation=1; 00030 bool do_pdf=false; 00031 00032 // Usage: vrp_plotter -f <vrp_file> -s <sol_file> -p <plot_file> 00033 if(argc<7 ) 00034 { 00035 fprintf(stderr,"Usage: %s -f <vrp_file> -s <sol_file> -p <plot_file> [-e -w -r]\n",argv[0]); 00036 fprintf(stderr,"\t <plot_file> must be .ps format\n"); 00037 fprintf(stderr,"\t .pdf format requires the epstopdf executable\n"); 00038 fprintf(stderr,"\t -pdf <pdf_file> will also create a .pdf image of the solution\n"); 00039 fprintf(stderr,"\t -e will not show the depot edges\n"); 00040 fprintf(stderr,"\t -w will weight the size of the non-depot nodes by their demand\n"); 00041 fprintf(stderr,"\t -o will rotate 90 degrees\n"); 00042 exit(-1); 00043 } 00044 00045 00046 int options=VRPH_DEFAULT_PLOT; 00047 00048 bool has_filename=false; 00049 for(i=1;i<argc;i++) 00050 { 00051 if(strcmp(argv[i],"-f")==0) 00052 { 00053 // Get the input file name 00054 has_filename=true; 00055 strcpy(in,argv[i+1]); 00056 } 00057 00058 if(strcmp(argv[i],"-s")==0) 00059 { 00060 // Get the solution file name 00061 strcpy(solfile,argv[i+1]); 00062 } 00063 00064 if(strcmp(argv[i],"-p")==0) 00065 { 00066 // Get the plot file name 00067 strcpy(plotfile,argv[i+1]); 00068 00069 } 00070 00071 if(strcmp(argv[i],"-pdf")==0) 00072 { 00073 do_pdf=true; 00074 strncpy(pdffile,argv[i+1],strlen(argv[i+1])); 00075 pdffile[strlen(argv[i+1])]='\0'; 00076 } 00077 00078 if(strcmp(argv[i],"-e")==0) 00079 options+=VRPH_NO_DEPOT_EDGES; 00080 00081 if(strcmp(argv[i],"-w")==0) 00082 options+=VRPH_WEIGHTED; 00083 00084 if(strcmp(argv[i],"-r")==0) 00085 { 00086 // Get the plot file name 00087 orientation=0; 00088 00089 } 00090 00091 } 00092 00093 if(!has_filename) 00094 report_error("No file name given!\n"); 00095 00096 n=VRPGetDimension(in); 00097 VRP V(n); 00098 00099 // Load the problem data 00100 V.read_TSPLIB_file(in); 00101 00102 printf("Imported instance\n"); 00103 00104 V.read_solution_file(solfile); 00105 int *sol; 00106 sol=new int[V.get_num_nodes()+2]; 00107 V.export_canonical_solution_buff(sol); 00108 V.import_solution_buff(sol); 00109 printf("Imported solution\n"); 00110 00111 // Show the solution to stdout 00112 V.summary(); 00113 00114 printf("Plotfile is %s\n",plotfile); 00115 V.plot(plotfile,options,orientation); 00116 00117 if(do_pdf) 00118 { 00119 // Create a .pdf file 00120 char command[VRPH_STRING_SIZE]; 00121 sprintf(command,"%s %s --outfile=%s\n",VRPH_EPS_EXE,plotfile,pdffile); 00122 system(command); 00123 } 00124 00125 delete [] sol; 00126 00127 return 0; 00128 00129 } 00130 00131