main_2p.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 
00004 #ifdef LINUX
00005 #include <getopt.h>
00006 #endif
00007 
00008 #include "eg_util.h"
00009 #include "eg_macros.h"
00010 #include "eg_kpseparator.h"
00011 #include "eg_2ptighten.h"
00012 
00013 void usage (char *program)
00014 {
00015   fprintf (stdout, "Usage: %s [options]\n", program);
00016   fprintf (stdout, "Options:\n");
00017   fprintf (stdout, "     -x d   x file name.\n");
00018   fprintf (stdout, "     -b     use binary file format.\n");
00019 }
00020 
00021 int parseargs (int argc,
00022                char **argv,
00023                int *binary_file,
00024                char **boss_host,
00025                char **file_name)
00026 {
00027 
00028   int c;
00029   char noyes[2][4] = {[0] = "no",[1] = "yes" };
00030 
00031   *file_name = 0;
00032   *binary_file = 0;
00033   *boss_host = 0;
00034 
00035   while ((c = getopt (argc, argv, "x:bh:")) != EOF)
00036   {
00037     switch (c)
00038     {
00039     case 'h':
00040       *boss_host = optarg;
00041       break;
00042     case 'b':
00043       *binary_file = 1;
00044       break;
00045     case 'x':
00046       *file_name = optarg;
00047       break;
00048     default:
00049       usage (argv[0]);
00050       return 1;
00051     }
00052   }
00053 
00054   if (!*file_name)
00055   {
00056     usage (argv[0]);
00057     return 1;
00058   }
00059 
00060   /* reporting the options */
00061   fprintf (stdout, "\n");
00062   fprintf (stdout, "Parsed Options:\n");
00063   fprintf (stdout, "input         : %s\n", *file_name);
00064   fprintf (stdout, "binary files  : %s\n", noyes[*binary_file]);
00065   fprintf (stdout, "\n");
00066   fflush (stdout);
00067 
00068   return 0;
00069 
00070 }
00071 
00072 int main (int argc,
00073           char **argv)
00074 {
00075   int rval,
00076     i,
00077     d,
00078     binary_file;
00079   char *file_name = 0,
00080    *boss_host;
00081 
00082   int nnodes,
00083     norig_edges,
00084    *orig_edges,
00085     nIneq,
00086    *n2dominoes,
00087   **naset,
00088   **nbset,
00089   **nmset,
00090    *nahandle,
00091    *nbhandle,
00092   ***aset,
00093   ***bset,
00094   ***mset,
00095   **ahandle,
00096   **bhandle;
00097   double *orig_weight;
00098 
00099   /**** PARSING INPUT ********************************************************/
00100 
00101   rval = parseargs (argc, argv, &binary_file, &boss_host, &file_name);
00102   CHECKRVAL (rval);
00103 
00104   /**** LOADING X FILE *******************************************************/
00105 
00106   if (binary_file)
00107   {
00108     rval =
00109       loadBGraph (file_name, &nnodes, &norig_edges, &orig_edges, &orig_weight);
00110     CHECKRVAL (rval);
00111   }
00112   else
00113   {
00114     rval =
00115       loadGraph (file_name, &nnodes, &norig_edges, &orig_edges, &orig_weight);
00116     CHECKRVAL (rval);
00117   }
00118 
00119   /**** CALLING DPSEPARATOR ***************************************************/
00120 
00121   nIneq = 0;
00122   rval = DP2separator (nnodes, norig_edges, orig_edges, orig_weight, &nIneq,
00123                        &n2dominoes, &naset, &nbset, &nmset, &nahandle,
00124                        &nbhandle, &aset, &bset, &mset, &ahandle, &bhandle,
00125                        boss_host, 1.0, 10.0, 5.0, 20.0);
00126   CHECKRVAL (rval);
00127 
00128   /* here we call the tightening.... just to check */
00129   if (nIneq)
00130   {
00131     int ln,
00132       nd;
00133     int *new_naset,
00134      *new_nbset,
00135      *new_ntset,
00136       new_nahandle,
00137       new_nbhandle,
00138     **new_aset,
00139     **new_bset,
00140     **new_tset,
00141      *new_ahandle,
00142      *new_bhandle;
00143     double violation;
00144     for (ln = 0; ln < nIneq; ln++)
00145     {
00146       rval = KPtighten (nnodes, norig_edges, orig_edges, orig_weight,
00147                         n2dominoes[ln], naset[ln], nbset[ln], nmset[ln],
00148                         nahandle[ln], nbhandle[ln], aset[ln], bset[ln],
00149                         mset[ln], ahandle[ln], bhandle[ln], &new_naset,
00150                         &new_nbset, &new_ntset, &new_nahandle, &new_nbhandle,
00151                         &new_aset, &new_bset, &new_tset, &new_ahandle,
00152                         &new_bhandle, &violation);
00153       if (new_naset)
00154       {
00155         EGfree (new_ahandle);
00156         EGfree (new_bhandle);
00157         for (nd = n2dominoes[ln]; nd--;)
00158         {
00159           if (new_naset[nd])
00160             EGfree (new_aset[nd]);
00161           if (new_nbset[nd])
00162             EGfree (new_bset[nd]);
00163           EGfree (new_tset[nd]);
00164         }
00165         EGfree (new_naset);
00166         EGfree (new_nbset);
00167         EGfree (new_ntset);
00168         EGfree (new_aset);
00169         EGfree (new_bset);
00170         EGfree (new_tset);
00171       }
00172     }
00173   }
00174 
00175 
00176   if (nIneq)
00177   {
00178     PTRTEST (aset, 1);
00179     PTRTEST (bset, 1);
00180     PTRTEST (mset, 1);
00181     PTRTEST (nbset, 1);
00182     PTRTEST (naset, 1);
00183     PTRTEST (nmset, 1);
00184     PTRTEST (ahandle, 1);
00185     PTRTEST (bhandle, 1);
00186     PTRTEST (n2dominoes, 1);
00187     PTRTEST (nahandle, 1);
00188     PTRTEST (nbhandle, 1);
00189     for (i = 0; i < nIneq; i++)
00190     {
00191       PTRTEST (aset[i], 1);
00192       PTRTEST (bset[i], 1);
00193       PTRTEST (mset[i], 1);
00194       PTRTEST (nbset[i], 1);
00195       PTRTEST (naset[i], 1);
00196       PTRTEST (nmset[i], 1);
00197       PTRTEST (ahandle[i], 1);
00198       PTRTEST (bhandle[i], 1);
00199       for (d = 0; d < n2dominoes[i]; d++)
00200       {
00201         PTRTEST (aset[i][d], 1);
00202         PTRTEST (bset[i][d], 1);
00203         PTRTEST (mset[i][d], 1);
00204         if (aset[i][d])
00205           EGfree (aset[i][d]);
00206         if (bset[i][d])
00207           EGfree (bset[i][d]);
00208         EGfree (mset[i][d]);
00209       }
00210       EGfree (naset[i]);
00211       EGfree (nbset[i]);
00212       EGfree (nmset[i]);
00213       EGfree (ahandle[i]);
00214       EGfree (bhandle[i]);
00215       EGfree (aset[i]);
00216       EGfree (bset[i]);
00217       EGfree (mset[i]);
00218     }
00219     EGfree (n2dominoes);
00220     EGfree (naset);
00221     EGfree (nbset);
00222     EGfree (nmset);
00223     EGfree (aset);
00224     EGfree (bset);
00225     EGfree (mset);
00226     EGfree (ahandle);
00227     EGfree (bhandle);
00228     EGfree (nahandle);
00229     EGfree (nbhandle);
00230 
00231   }
00232 
00233   PTRTEST (orig_edges, 1);
00234   PTRTEST (orig_weight, 1);
00235   EGfree (orig_edges);
00236   EGfree (orig_weight);
00237 
00238   return 0;
00239 
00240 }

Generated on Thu Oct 20 14:58:42 2005 for DominoParitySeparator by  doxygen 1.4.5