[BACK]Return to call.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / TiGERS_0.9

Annotation of OpenXM_contrib/TiGERS_0.9/call.c, Revision 1.1.1.1

1.1       maekawa     1: /*
                      2: ** call.c                                 Birk Huber, 2/99
                      3: **   -- main calling file for tigers code
                      4: **
                      5: **
                      6: ** TiGERS,  Toric Groebner Basis Enumeration by Reverse Search
                      7: ** copyright (c) 1999  Birk Huber
                      8: **
                      9: */
                     10: #include<stdio.h>
                     11: #include<stdlib.h>
                     12: #include<string.h>
                     13: #include<time.h>
                     14: #include "utils.h"
                     15: #include "gset.h"
                     16: #include "matrices.h"
                     17:
                     18: /*
                     19: ** write a description of program usage to stderr
                     20: */
                     21: usage(prog)
                     22: char *prog;
                     23: {
                     24:   static char *helpmsg[] = {
                     25:   "Function: Enumerate all Groebner bases of a toric ideal I_A.",
                     26:   "          \n",
                     27:   "Input: \n ",
                     28:   "  A) A ring description (for now just a number of variables)\n",
                     29:   "     followed by a reduced Groebner basis for I_A.\n",
                     30:   "     example:\n",
                     31:   "     R: 5\n",
                     32:   "     G: {a^2*c-b^2*e, a^2*d-b*e^2, b*d-c*e}\n",
                     33:   "  or \n",
                     34:   "  B) An integer matrix A (defining I_A).\n",
                     35:   "     example:\n",
                     36:   "     M: { 3 5 : 2 1 1 1 1 1 \n",
                     37:   "                3 0 1 2 1 0 \n",
                     38:   "                4 0 0 1 2 1}\n",
                     39:   " Note: Lines beginning with a % are comments and are ignored.\n",
                     40:   "       Comment lines should only occur at the beginning of the file.\n",
                     41:   "     : When binomials are printed out (and read in) they can be \n",
                     42:   "       preceeded by the characters !, or # \n",
                     43:   "       ! means the binomial is known not to be a facet.\n",
                     44:   "       # means the binomial is known to be a facet.\n",
                     45:   " \n",
                     46:   "Options:\n",
                     47:   "    -h            print this message\n"
                     48:   "    -i (filename) set file name for input  [default: stdin]\n",
                     49:   "    -o (filename) set file name for output [default: stdout]\n",
                     50:   "    -R            only compute root of tree \n",
                     51:   "    -r            compute all grobner bases [done by default]\n",
                     52:   "    -C            turn partial caching on   [done by default]\n",
                     53:   "    -c            turn partial caching off \n",
                     54:   "    -T            print edges of search tree \n",
                     55:   "    -t            do not print edges of search tree [assumed by default]\n",  "    -L            print vertices by giving initial ideals\n",
                     56:   "                     and printing facet biomials.\n",
                     57:   "    -l            print vertices as grobner bases   [done by default]\n",
                     58:   "    -F            Use only linear algebra when testing facets [default]\n",
                     59:   "    -f            use FLIPPABILITY test first when determining facets\n",
                     60:   "    -e            use exhaustive search instead of reverse search\n",
                     61:   "    -E            use reverse search                   [default]\n",
                     62:   NULL
                     63:   };
                     64:   char **p=helpmsg;
                     65:
                     66:   fprintf(stderr,"Usage: %s {Options} \n",prog);
                     67:   while(*p)(void) fputs(*p++,stderr);
                     68:   exit(-1);
                     69: }
                     70:
                     71: FILE *infile=stdin, *outfile=stdout;
                     72: extern int rsearch_cache;
                     73: extern int print_tree;
                     74: extern int  print_init;
                     75: extern int stats_minfacets;
                     76: extern int stats_minelts;
                     77: extern int stats_mindeg;
                     78: extern int stats_maxfacets;
                     79: extern int stats_maxelts;
                     80: extern int stats_maxdeg;
                     81: extern int stats_ecounter;
                     82: extern int stats_tdepth;
                     83: extern int lptest;
                     84: int root_only=FALSE;
                     85: int compGB=FALSE;
                     86: int use_exsearch=FALSE;
                     87:
                     88: #define MATFOUND 1
                     89: #define GSETFOUND 2
                     90: main(int argc, char **argv ){
                     91:  char *c,cc, *prog=argv[0], *ifname=0, *ofname=0;
                     92:  int tmp,acnt,stat=0,counter;
                     93:  gset G1=0,gset_toric_ideal();
                     94:  int **M=0,Mn,Mm;
                     95:  double tt;
                     96:
                     97:   /* initialize parameters */
                     98:   root_only=FALSE;
                     99:   rsearch_cache=TRUE;
                    100:   print_tree=FALSE;
                    101:   print_init=FALSE;
                    102:
                    103:   /* parse command line */
                    104:   while (--argc > 0 && (*++argv)[0] == '-'){
                    105:     acnt=0;
                    106:     for (c = argv[0]+1; *c != '\0'; c++){
                    107:       switch (*c) {
                    108:       case 'h': usage(prog);  break;
                    109:       case 'R': root_only=TRUE; break;    /* Root Flag On */
                    110:       case 'r': root_only=FALSE; break;   /* Root Flag Off */
                    111:       case 'C': rsearch_cache=TRUE; break;/* Turn partial caching on*/
                    112:       case 'c': rsearch_cache=FALSE;break;/* Turn partical caching off*/
                    113:       case 'T': print_tree=TRUE;  break;  /* Turn tree printing on */
                    114:       case 't': print_tree=FALSE; break;  /* Turn tree printing off*/
                    115:       case 'L': print_init=TRUE;  break;  /* Turn initial ideal printing on */
                    116:       case 'l': print_init=FALSE; break;  /* Turn initial ideal printing off */
                    117:       case 'f': lptest=3; break;          /*check facets with linalg and */
                    118:                                          /*flipability tests */
                    119:       case 'F': lptest=1; break;          /*check facets only with linalg */
                    120:       case 'A': lptest=2; use_exsearch=TRUE;break;          /*check facets only for flipability*/
                    121:       case 'E': use_exsearch=FALSE;break; /*use reverse search to enumerate */
                    122:       case 'e': use_exsearch=TRUE; break; /*use exhaustive search */
                    123:       case 'i': case 'I':
                    124:          argc--;
                    125:         ifname=strdup(argv[++acnt]); /* scan infile name */
                    126:           fprintf(stderr,"using filename %s for input\n",ifname);
                    127:        break;
                    128:       case 'o': case 'O':argc--;
                    129:          ofname=strdup(argv[++acnt]); /* scan infile name */
                    130:           fprintf(stderr,"using filename %s for output\n",ofname);
                    131:        break;  /* scan outfile name */
                    132:         break;
                    133:         default:
                    134:            fprintf(stderr,"%s: illegal option %c\n",prog,*c);
                    135:       }
                    136:     }
                    137:     argv+=acnt;
                    138:   }
                    139:   if (argc != 0) usage(prog);
                    140:
                    141:   /* open infile and outfile (if nesc) */
                    142:   if (ifname!=0 && (infile=fopen(ifname,"r"))==0){
                    143:       fprintf(stderr," %s: couldn't open %s for input\n",prog,ifname);
                    144:       exit(1);
                    145:   }
                    146:   if (ofname!=0 && (outfile=fopen(ofname,"w"))==0){
                    147:       fprintf(stderr," %s: couldn't open %s for output\n",prog,ofname);
                    148:       exit(1);
                    149:   }
                    150:
                    151:   /* scan input from infile and outfile */
                    152:
                    153:   eatwhite(infile);
                    154:   cc=getc(infile);
                    155:   if (cc=='R'){
                    156:     while((cc=getc(infile))!=':');
                    157:     if (ring_read(infile)==FALSE){
                    158:      fprintf(stderr,"%s: ring_read() failed\n",prog);
                    159:      exit(1);
                    160:     }
                    161:     eatwhite(infile);
                    162:     cc=getc(infile);
                    163:   }
                    164:   if (cc=='G'){
                    165:     while((cc=getc(infile))!=':');
                    166:     if (ring_N<0) {
                    167:        fprintf(stderr,"%s: ring not set\n",prog);
                    168:        exit(1);
                    169:     }
                    170:     G1=gset_new();
                    171:     if (gset_read(infile,G1)==FALSE){
                    172:      fprintf(stderr,"%s: gset_read() failed\n",prog);
                    173:      exit(1);
                    174:     }
                    175:     stat=GSETFOUND;
                    176:   }
                    177:   else if (cc=='M'){
                    178:     while((cc=getc(infile))!=':');
                    179:     if ((M=imatrix_read(infile,&Mm,&Mn))==0){
                    180:      fprintf(stderr,"%s: imatrix_read() failed\n",prog);
                    181:      exit(1);
                    182:     }
                    183:     if (ring_N==0) ring_set(Mn);
                    184:     else if (ring_N!=Mn) {
                    185:      fprintf(stderr,"%s: Matrix collum and ring dimensions must agree\n",prog);
                    186:      exit(1);
                    187:     }
                    188:     stat=MATFOUND;
                    189:   }
                    190:   else {
                    191:    fprintf(stderr,"%s,: Input files contains neither a generating set\n",prog);
                    192:    fprintf(stderr,"     nor a matrix description of a toric ideal\n");
                    193:    exit(1);
                    194: }
                    195:
                    196:   /* ensure we have root */
                    197:   if (stat==MATFOUND){
                    198:    G1=gset_toric_ideal(M,Mm,Mn);
                    199:   }
                    200:   else {
                    201:    if (compGB==TRUE){gset_rgb(G1,monomial_lexcomp);}
                    202:    else {
                    203:      /* could put checks to make sure input is toric rgb */
                    204:      /* then use grobner walk to get to first rgb */
                    205:    }
                    206:   }
                    207:
                    208:   /* output first GB if desired */
                    209:   fprintf(outfile,"%% starting GB:\n");
                    210:   fprintf(outfile,"R: %d\n",ring_N);
                    211:   fprintf(outfile,"G: ");
                    212:   gset_print(outfile,G1);
                    213:   fprintf(outfile,"\n");
                    214:
                    215:   /* perform reverse search if desired*/
                    216:   if (root_only==FALSE){
                    217:     if (use_exsearch==FALSE){
                    218:       /* should double check we are at root */
                    219:      fprintf(outfile,"\n Enumerating Groebner bases\n");
                    220:      fprintf(outfile,"   using reverse search\n");
                    221:      if (ifname!=0) fprintf(outfile,"   taking input from %s\n",ifname);
                    222:      if (rsearch_cache==FALSE) fprintf(outfile,"   without partial caching\n");
                    223:      else fprintf(outfile,"   with partial caching\n");
                    224:      switch(lptest){
                    225:      case 1:
                    226:         fprintf(outfile,"   using only linear programing to test facets\n");
                    227:         break;
                    228:      case 3:
                    229:         fprintf(outfile,"   using wall ideal pretest for facet checking\n");
                    230:         break;
                    231:      case 2:
                    232:        fprintf(stderr,"Error: can not use -A option with reverse search\n");
                    233:        break;
                    234:      }
                    235:      tt=clock();
                    236:      counter=rsearch(G1);
                    237:      tt=(clock()-tt)/CLOCKS_PER_SEC;
                    238:      fprintf(outfile,"\n");
                    239:      fprintf(outfile,"Number of Groebner bases found %d\n",counter);
                    240:      fprintf(outfile,"Number of edges of state polytope %d\n",stats_ecounter);
                    241:      fprintf(outfile,"max caching depth      %d\n",stats_tdepth);
                    242:      fprintf(outfile,"max facet binomials    %d\n",stats_maxfacets);
                    243:      fprintf(outfile,"min facet binomials    %d\n",stats_minfacets);
                    244:      fprintf(outfile,"max elts               %d\n",stats_maxelts);
                    245:      fprintf(outfile,"min elts               %d\n",stats_minelts);
                    246:      fprintf(outfile,"max degree             %d\n",stats_maxdeg);
                    247:      fprintf(outfile,"min degree             %d\n",stats_mindeg);
                    248:      if (ifname!=0) fprintf(outfile,"%s: ",ifname);
                    249:      fprintf(outfile,"Reverse Search, ");
                    250:      switch(rsearch_cache){
                    251:      case TRUE:
                    252:         fprintf(outfile,"  Caching,");
                    253:         break;
                    254:      case FALSE:
                    255:         fprintf(outfile,"  NO Caching,");
                    256:         break;
                    257:       }
                    258:      switch(lptest){
                    259:      case 1:
                    260:         fprintf(outfile,"  LP only.\n");
                    261:         break;
                    262:      case 3:
                    263:         fprintf(outfile,"  A-pretest,\n");
                    264:         break;
                    265:      }
                    266:      fprintf(outfile,"time used (in seconds) %4.2lf\n",tt);
                    267:      return 0;
                    268:     }
                    269:     else {
                    270:       fprintf(outfile,"\nEnumerating Groebner bases\n");
                    271:       fprintf(outfile,"using exhaustive searching");
                    272:       if (ifname!=0) fprintf(outfile,"taking input from %s\n",ifname);
                    273:       else fprintf(outfile,"\n");
                    274:      switch(lptest){
                    275:      case 1:
                    276:         fprintf(outfile,"   using only linear programing to test facets\n");
                    277:         break;
                    278:      case 3:
                    279:         fprintf(outfile,"   using wall ideal pretest for facet checking\n");
                    280:         break;
                    281:      case 2:
                    282:        fprintf(outfile,"Using wall ideal pretest instead of facet checking\n");
                    283:        fprintf(outfile," FINDING ALL A-GRADED INITIALS CONNECTED TO ROOT\n");
                    284:        break;
                    285:      }
                    286:      tt=clock();
                    287:      counter=exsearch(G1);
                    288:      tt=(clock()-tt)/CLOCKS_PER_SEC;
                    289:      fprintf(outfile,"\n");
                    290:      fprintf(outfile,"Number of Groebner bases found %d\n",counter);
                    291:      fprintf(outfile,"Number of edges of state polytope %d\n",stats_ecounter);
                    292:      fprintf(outfile,"max facet binomials    %d\n",stats_maxfacets);
                    293:      fprintf(outfile,"min facet binomials    %d\n",stats_minfacets);
                    294:      fprintf(outfile,"max elts               %d\n",stats_maxelts);
                    295:      fprintf(outfile,"min elts               %d\n",stats_minelts);
                    296:      fprintf(outfile,"max degree             %d\n",stats_maxdeg);
                    297:      fprintf(outfile,"min degree             %d\n",stats_mindeg);
                    298:      if (ifname!=0) fprintf(outfile,"%s: ",ifname);
                    299:      fprintf(outfile,"Exhaustive search, ");
                    300:      switch(lptest){
                    301:      case 1:
                    302:         fprintf(outfile,"  LP only\n");
                    303:         break;
                    304:      case 3:
                    305:         fprintf(outfile,"  A-pretest\n");
                    306:         break;
                    307:      case 2:
                    308:        fprintf(outfile," A-only\n");
                    309:        break;
                    310:      default:
                    311:         fprintf(outfile,"\n");
                    312:      }
                    313:      fprintf(outfile,"time used (in seconds) %4.2lf\n",tt);
                    314:     return 0;
                    315:     }
                    316:   }
                    317:   /* clean up */
                    318:   LP_free_space();
                    319:   if (G1!=0) gset_free(G1);
                    320: }
                    321:
                    322:
                    323:
                    324:
                    325:
                    326:
                    327:
                    328:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>