00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <getopt.h>
00025 #include <math.h>
00026 #include "eg_mem.h"
00027 #include "eg_macros.h"
00028 #include "mt_gomory.h"
00029 #include "mt_tableau.h"
00030 #include "eg_io.h"
00031
00032
00033
00034
00035
00036
00037 static int mt_mode=0;
00038 static char tb_file[1024]="tableau.txt";
00039
00040
00041 int static usage(char*prog)
00042 {
00043 fprintf(stderr,"Usage:\n%s [options]",prog);
00044 fprintf(stderr,"Options:\n");
00045 fprintf(stderr," -m n Mode of testing: 0 for tableau reading testing,\n");
00046 fprintf(stderr," Default: %d\n",mt_mode);
00047 fprintf(stderr," -t f File containing a tableau row, Default %s\n",tb_file);
00048 return 0;
00049 }
00050
00051
00052 int static parse_args(int argc,char**argv)
00053 {
00054 int c;
00055 while((c=getopt(argc,argv,"f:m:"))!=EOF)
00056 {
00057 switch(c)
00058 {
00059 case 'f':
00060 snprintf(tb_file,1023,"%s",optarg);
00061 break;
00062 case 'm':
00063 mt_mode = atoi(optarg);
00064 break;
00065 default:
00066 usage(argv[0]);
00067 exit(1);
00068 }
00069 }
00070
00071 if(mt_mode != 0)
00072 {
00073 usage(argv[0]);
00074 exit(1);
00075 }
00076 return 0;
00077 }
00078
00079
00080
00081 int static test_MTgomory_cut(void)
00082 {
00083 int rval = 0;
00084 register int i;
00085 int*rowbeg = 0, *rowind = 0, nrows = 0, ncols = 0;
00086 double* rowval = 0, *f=0, *cutval=0, *work=0, *base = 0;
00087 FILE*input = EGsfopen(tb_file,"r");
00088
00089 rval = MTreadRTableau( input, &nrows, &ncols, &rowval, &rowind,
00090 &rowbeg, &f);
00091 CHECKRVALG(rval,CLEANUP);
00092
00093 cutval = EGsMalloc(double,ncols);
00094 work = EGsMalloc(double,ncols+1);
00095 base = EGsMalloc(double,nrows);
00096 for( i = nrows ; i-- ; ) base[i] = 1.0;
00097 rval = MTgomoryCut( nrows, ncols, rowval, rowind, rowbeg, f, base,
00098 cutval, work);
00099 CHECKRVALG(rval,CLEANUP);
00100
00101 fprintf(stdout, "The cut is:\n");
00102 for( i = 0 ; i < ncols ; i++ )
00103 fprintf(stdout,"%s %.5lf x_%d ", (cutval[i]>=0) ? "+":"-",
00104 fabs(cutval[i]), i);
00105 fprintf(stdout," >= 1\n");
00106 CLEANUP:
00107 EGfree(rowbeg);
00108 EGfree(rowind);
00109 EGfree(rowval);
00110 EGfree(f);
00111 EGfree(cutval);
00112 EGfree(work);
00113 EGfree(base);
00114 fclose(input);
00115 return rval;
00116 }
00117
00118
00119 int main(int argc,char**argv)
00120 {
00121 int rval = 0;
00122 parse_args(argc,argv);
00123 switch(mt_mode)
00124 {
00125 case 0:
00126 rval = test_MTgomory_cut();
00127 CHECKRVALG(rval,CLEANUP);
00128 break;
00129 }
00130 CLEANUP:
00131 return rval;
00132 }
00133
00134
00135
00136