main.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_dpseparator.h"
00011 #include "eg_kpseparator.h"
00012 #include "eg_dptighten.h"
00013 #include "eg_greedykp.h"
00014 
00015 void usage (char *program)
00016 {
00017   fprintf (stdout, "Usage: %s [options]\n", program);
00018   fprintf (stdout, "Options:\n");
00019   fprintf (stdout, "     -x d   x file name.\n");
00020   fprintf (stdout, "     -b     use binary file format.\n");
00021   fprintf (stdout, "     -p lf  percentage of ball around " 
00022                    "s to use for domino generation.\n");
00023   fprintf (stdout, "     -h s   boss host.\n");
00024   fprintf (stdout, "     -k n   use greedy kp heuristic (n handles).\n");
00025 }
00026 
00027 int parseargs (int argc,
00028                char **argv,
00029                int *binary_file,
00030                char **boss_host,
00031                char **file_name,
00032                double *percentage,
00033                int *use_greedy,
00034                int *max_handles)
00035 {
00036 
00037   int c;
00038   char noyes[2][4] = {[0] = "no",[1] = "yes" };
00039 
00040   *file_name = 0;
00041   *binary_file = 0;
00042   *boss_host = 0;
00043   *percentage = 1.0;
00044   *use_greedy = 0;
00045   *max_handles = 2;
00046 
00047   while ((c = getopt (argc, argv, "x:bh:p:k:")) != EOF)
00048   {
00049     switch (c)
00050     {
00051 
00052     case 'p':
00053       *percentage = atof (optarg);
00054       break;
00055     case 'h':
00056       *boss_host = optarg;
00057       break;
00058     case 'k':
00059       *use_greedy=1;
00060       *max_handles = atoi(optarg);
00061       break;
00062     case 'b':
00063       *binary_file = 1;
00064       break;
00065     case 'x':
00066       *file_name = optarg;
00067       break;
00068     default:
00069       usage (argv[0]);
00070       return 1;
00071     }
00072   }
00073 
00074   if (!*file_name)
00075   {
00076     usage (argv[0]);
00077     return 1;
00078   }
00079 
00080   /* reporting the options */
00081   fprintf (stdout, "\n");
00082   fprintf (stdout, "Parsed Options:\n");
00083   fprintf (stdout, "input         : %s\n", *file_name);
00084   fprintf (stdout, "binary files  : %s\n", noyes[*binary_file]);
00085   fprintf (stdout, "percentage    : %lf\n", *percentage);
00086   if (*boss_host)
00087      fprintf (stdout, "boss host     : %s\n", *boss_host);
00088   fprintf (stdout, "greedy kp     : %s\n", noyes[*use_greedy]);
00089   fprintf (stdout, "\n");
00090   fflush (stdout);
00091 
00092   return 0;
00093 
00094 }
00095 
00096 int main (int argc,
00097           char **argv)
00098 {
00099   int rval,
00100     i,
00101     d,
00102     binary_file,
00103     use_greedy;
00104   char *file_name = 0,
00105    *boss_host;
00106 
00107   int nnodes,
00108     norig_edges,
00109     *orig_edges,
00110     max_handles;
00111 
00112   double *orig_weight;
00113   double percentage = 1.0;
00114 
00115 
00116   /**** PARSING INPUT ********************************************************/
00117 
00118   rval =
00119     parseargs (argc, argv, &binary_file, &boss_host, &file_name, &percentage,
00120                &use_greedy, &max_handles);
00121   CHECKRVAL (rval);
00122 
00123   /**** LOADING X FILE *******************************************************/
00124 
00125   if (binary_file)
00126   {
00127     rval =
00128       loadBGraph (file_name, &nnodes, &norig_edges, &orig_edges, &orig_weight);
00129     CHECKRVAL (rval);
00130   }
00131   else
00132   {
00133     rval =
00134       loadGraph (file_name, &nnodes, &norig_edges, &orig_edges, &orig_weight);
00135     CHECKRVAL (rval);
00136   }
00137 
00138   /**** CALLING DPSEPARATOR ***************************************************/
00139 
00140   if (!use_greedy)
00141   {
00142 
00143      int nIneq=0,
00144         *ndominoes,
00145         **naset,
00146         **nbset,
00147         *nhandle,
00148         ***aset,
00149         ***bset,
00150         **handle;
00151 
00152      rval = DPseparator (nnodes, norig_edges, orig_edges, orig_weight, &nIneq,
00153                          &ndominoes, &naset, &nbset, &nhandle, &aset, &bset,
00154                          &handle, boss_host, percentage, 10.0);
00155      CHECKRVAL (rval);
00156 
00157      /* here we call the tightening.... just to check */
00158      if (nIneq)
00159      {
00160        int ln, nd;
00161        int *new_n_aset,
00162         *new_n_bset,
00163          new_n_handle,
00164        **new_aset,
00165        **new_bset,
00166         *new_handle;
00167        double violation;
00168        for (ln = 0; ln < nIneq; ln++)
00169        {
00170          rval = DPtighten (nnodes, norig_edges, orig_edges, orig_weight,
00171                            ndominoes[ln], naset[ln], nbset[ln], nhandle[ln],
00172                            aset[ln], bset[ln], handle[ln], &new_n_aset,
00173                            &new_n_bset, &new_n_handle, &new_aset, &new_bset,
00174                            &new_handle, &violation);
00175          if (new_aset)
00176          {
00177            for (nd = ndominoes[ln]; nd--;)
00178            {
00179              free (new_aset[nd]);
00180              free (new_bset[nd]);
00181            }
00182            free (new_aset);
00183            free (new_bset);
00184            free (new_n_aset);
00185            free (new_n_bset);
00186            free (new_handle);
00187          }
00188        }
00189      }
00190 
00191      if (nIneq)
00192      {
00193        for (i = 0; i < nIneq; i++)
00194        {
00195          for (d = 0; d < ndominoes[i]; d++)
00196          {
00197             EGfree (aset[i][d]);
00198             EGfree (bset[i][d]);
00199          }
00200          EGfree (naset[i]);
00201          EGfree (nbset[i]);
00202          EGfree (handle[i]);
00203          EGfree (aset[i]);
00204          EGfree (bset[i]);
00205        }
00206        EGfree (ndominoes);
00207        EGfree (naset);
00208        EGfree (nbset);
00209        EGfree (aset);
00210        EGfree (bset);
00211        EGfree (handle);
00212        EGfree (nhandle);
00213      }
00214   }
00215 
00216   /**** CALLING KPSEPARATOR ***************************************************/
00217 
00218   if (use_greedy)
00219   {
00220 
00221      int nineq = 0,
00222          *nhandles = 0,
00223          **handle_size = 0,
00224          ***handles = 0,
00225          *nteeth = 0,
00226          **teeth_size = 0,
00227          ***teeth = 0,
00228          **teeth_k = 0,
00229          ***teeth_handle = 0,
00230          ***teeth_nhalf = 0,
00231          ****teeth_halves = 0;
00232 
00233      rval = KPseparator (max_handles,
00234                          nnodes, 
00235                          norig_edges, 
00236                          orig_edges, 
00237                          orig_weight, 
00238                          &nineq,
00239                          &nhandles,
00240                          &handle_size,
00241                          &handles,
00242                          &nteeth, 
00243                          &teeth_size,
00244                          &teeth,
00245                          &teeth_k,
00246                          &teeth_handle,
00247                          &teeth_nhalf,
00248                          &teeth_halves, 
00249                          boss_host, 
00250                          percentage);
00251      CHECKRVAL (rval);
00252 
00253      for(i=0; i < nineq; i++)
00254         EGfreePKPCB(nhandles[i],
00255                     handle_size[i],
00256                     handles[i],
00257                     nteeth[i],
00258                     teeth_size[i],
00259                     teeth[i],
00260                     teeth_k[i],
00261                     teeth_handle[i],
00262                     teeth_nhalf[i],
00263                     teeth_halves[i]);
00264 
00265      free(nhandles);
00266      free(handle_size);
00267      free(handles);
00268      free(nteeth);
00269      free(teeth_size);
00270      free(teeth);
00271      free(teeth_k);
00272      free(teeth_handle);
00273      free(teeth_nhalf);
00274      free(teeth_halves);
00275 
00276   }
00277 
00278   /**** FREE ALLOCATIONS *****************************************************/
00279 
00280 
00281   EGfree (orig_edges);
00282   EGfree (orig_weight);
00283 
00284   return 0;
00285 
00286 }

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