[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.2

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:
1.2     ! noro       71: FILE *infile, *outfile;
1.1       maekawa    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;
1.2     ! noro      102:
        !           103:   /* added by noro */
        !           104:   infile = stdin;
        !           105:   outfile = stdout;
1.1       maekawa   106:
                    107:   /* parse command line */
                    108:   while (--argc > 0 && (*++argv)[0] == '-'){
                    109:     acnt=0;
                    110:     for (c = argv[0]+1; *c != '\0'; c++){
                    111:       switch (*c) {
                    112:       case 'h': usage(prog);  break;
                    113:       case 'R': root_only=TRUE; break;    /* Root Flag On */
                    114:       case 'r': root_only=FALSE; break;   /* Root Flag Off */
                    115:       case 'C': rsearch_cache=TRUE; break;/* Turn partial caching on*/
                    116:       case 'c': rsearch_cache=FALSE;break;/* Turn partical caching off*/
                    117:       case 'T': print_tree=TRUE;  break;  /* Turn tree printing on */
                    118:       case 't': print_tree=FALSE; break;  /* Turn tree printing off*/
                    119:       case 'L': print_init=TRUE;  break;  /* Turn initial ideal printing on */
                    120:       case 'l': print_init=FALSE; break;  /* Turn initial ideal printing off */
                    121:       case 'f': lptest=3; break;          /*check facets with linalg and */
                    122:                                          /*flipability tests */
                    123:       case 'F': lptest=1; break;          /*check facets only with linalg */
                    124:       case 'A': lptest=2; use_exsearch=TRUE;break;          /*check facets only for flipability*/
                    125:       case 'E': use_exsearch=FALSE;break; /*use reverse search to enumerate */
                    126:       case 'e': use_exsearch=TRUE; break; /*use exhaustive search */
                    127:       case 'i': case 'I':
                    128:          argc--;
                    129:         ifname=strdup(argv[++acnt]); /* scan infile name */
                    130:           fprintf(stderr,"using filename %s for input\n",ifname);
                    131:        break;
                    132:       case 'o': case 'O':argc--;
                    133:          ofname=strdup(argv[++acnt]); /* scan infile name */
                    134:           fprintf(stderr,"using filename %s for output\n",ofname);
                    135:        break;  /* scan outfile name */
                    136:         break;
                    137:         default:
                    138:            fprintf(stderr,"%s: illegal option %c\n",prog,*c);
                    139:       }
                    140:     }
                    141:     argv+=acnt;
                    142:   }
                    143:   if (argc != 0) usage(prog);
                    144:
                    145:   /* open infile and outfile (if nesc) */
                    146:   if (ifname!=0 && (infile=fopen(ifname,"r"))==0){
                    147:       fprintf(stderr," %s: couldn't open %s for input\n",prog,ifname);
                    148:       exit(1);
                    149:   }
                    150:   if (ofname!=0 && (outfile=fopen(ofname,"w"))==0){
                    151:       fprintf(stderr," %s: couldn't open %s for output\n",prog,ofname);
                    152:       exit(1);
                    153:   }
                    154:
                    155:   /* scan input from infile and outfile */
                    156:
                    157:   eatwhite(infile);
                    158:   cc=getc(infile);
                    159:   if (cc=='R'){
                    160:     while((cc=getc(infile))!=':');
                    161:     if (ring_read(infile)==FALSE){
                    162:      fprintf(stderr,"%s: ring_read() failed\n",prog);
                    163:      exit(1);
                    164:     }
                    165:     eatwhite(infile);
                    166:     cc=getc(infile);
                    167:   }
                    168:   if (cc=='G'){
                    169:     while((cc=getc(infile))!=':');
                    170:     if (ring_N<0) {
                    171:        fprintf(stderr,"%s: ring not set\n",prog);
                    172:        exit(1);
                    173:     }
                    174:     G1=gset_new();
                    175:     if (gset_read(infile,G1)==FALSE){
                    176:      fprintf(stderr,"%s: gset_read() failed\n",prog);
                    177:      exit(1);
                    178:     }
                    179:     stat=GSETFOUND;
                    180:   }
                    181:   else if (cc=='M'){
                    182:     while((cc=getc(infile))!=':');
                    183:     if ((M=imatrix_read(infile,&Mm,&Mn))==0){
                    184:      fprintf(stderr,"%s: imatrix_read() failed\n",prog);
                    185:      exit(1);
                    186:     }
                    187:     if (ring_N==0) ring_set(Mn);
                    188:     else if (ring_N!=Mn) {
                    189:      fprintf(stderr,"%s: Matrix collum and ring dimensions must agree\n",prog);
                    190:      exit(1);
                    191:     }
                    192:     stat=MATFOUND;
                    193:   }
                    194:   else {
                    195:    fprintf(stderr,"%s,: Input files contains neither a generating set\n",prog);
                    196:    fprintf(stderr,"     nor a matrix description of a toric ideal\n");
                    197:    exit(1);
                    198: }
                    199:
                    200:   /* ensure we have root */
                    201:   if (stat==MATFOUND){
                    202:    G1=gset_toric_ideal(M,Mm,Mn);
                    203:   }
                    204:   else {
                    205:    if (compGB==TRUE){gset_rgb(G1,monomial_lexcomp);}
                    206:    else {
                    207:      /* could put checks to make sure input is toric rgb */
                    208:      /* then use grobner walk to get to first rgb */
                    209:    }
                    210:   }
                    211:
                    212:   /* output first GB if desired */
                    213:   fprintf(outfile,"%% starting GB:\n");
                    214:   fprintf(outfile,"R: %d\n",ring_N);
                    215:   fprintf(outfile,"G: ");
                    216:   gset_print(outfile,G1);
                    217:   fprintf(outfile,"\n");
                    218:
                    219:   /* perform reverse search if desired*/
                    220:   if (root_only==FALSE){
                    221:     if (use_exsearch==FALSE){
                    222:       /* should double check we are at root */
                    223:      fprintf(outfile,"\n Enumerating Groebner bases\n");
                    224:      fprintf(outfile,"   using reverse search\n");
                    225:      if (ifname!=0) fprintf(outfile,"   taking input from %s\n",ifname);
                    226:      if (rsearch_cache==FALSE) fprintf(outfile,"   without partial caching\n");
                    227:      else fprintf(outfile,"   with partial caching\n");
                    228:      switch(lptest){
                    229:      case 1:
                    230:         fprintf(outfile,"   using only linear programing to test facets\n");
                    231:         break;
                    232:      case 3:
                    233:         fprintf(outfile,"   using wall ideal pretest for facet checking\n");
                    234:         break;
                    235:      case 2:
                    236:        fprintf(stderr,"Error: can not use -A option with reverse search\n");
                    237:        break;
                    238:      }
                    239:      tt=clock();
                    240:      counter=rsearch(G1);
                    241:      tt=(clock()-tt)/CLOCKS_PER_SEC;
                    242:      fprintf(outfile,"\n");
                    243:      fprintf(outfile,"Number of Groebner bases found %d\n",counter);
                    244:      fprintf(outfile,"Number of edges of state polytope %d\n",stats_ecounter);
                    245:      fprintf(outfile,"max caching depth      %d\n",stats_tdepth);
                    246:      fprintf(outfile,"max facet binomials    %d\n",stats_maxfacets);
                    247:      fprintf(outfile,"min facet binomials    %d\n",stats_minfacets);
                    248:      fprintf(outfile,"max elts               %d\n",stats_maxelts);
                    249:      fprintf(outfile,"min elts               %d\n",stats_minelts);
                    250:      fprintf(outfile,"max degree             %d\n",stats_maxdeg);
                    251:      fprintf(outfile,"min degree             %d\n",stats_mindeg);
                    252:      if (ifname!=0) fprintf(outfile,"%s: ",ifname);
                    253:      fprintf(outfile,"Reverse Search, ");
                    254:      switch(rsearch_cache){
                    255:      case TRUE:
                    256:         fprintf(outfile,"  Caching,");
                    257:         break;
                    258:      case FALSE:
                    259:         fprintf(outfile,"  NO Caching,");
                    260:         break;
                    261:       }
                    262:      switch(lptest){
                    263:      case 1:
                    264:         fprintf(outfile,"  LP only.\n");
                    265:         break;
                    266:      case 3:
                    267:         fprintf(outfile,"  A-pretest,\n");
                    268:         break;
                    269:      }
                    270:      fprintf(outfile,"time used (in seconds) %4.2lf\n",tt);
                    271:      return 0;
                    272:     }
                    273:     else {
                    274:       fprintf(outfile,"\nEnumerating Groebner bases\n");
                    275:       fprintf(outfile,"using exhaustive searching");
                    276:       if (ifname!=0) fprintf(outfile,"taking input from %s\n",ifname);
                    277:       else fprintf(outfile,"\n");
                    278:      switch(lptest){
                    279:      case 1:
                    280:         fprintf(outfile,"   using only linear programing to test facets\n");
                    281:         break;
                    282:      case 3:
                    283:         fprintf(outfile,"   using wall ideal pretest for facet checking\n");
                    284:         break;
                    285:      case 2:
                    286:        fprintf(outfile,"Using wall ideal pretest instead of facet checking\n");
                    287:        fprintf(outfile," FINDING ALL A-GRADED INITIALS CONNECTED TO ROOT\n");
                    288:        break;
                    289:      }
                    290:      tt=clock();
                    291:      counter=exsearch(G1);
                    292:      tt=(clock()-tt)/CLOCKS_PER_SEC;
                    293:      fprintf(outfile,"\n");
                    294:      fprintf(outfile,"Number of Groebner bases found %d\n",counter);
                    295:      fprintf(outfile,"Number of edges of state polytope %d\n",stats_ecounter);
                    296:      fprintf(outfile,"max facet binomials    %d\n",stats_maxfacets);
                    297:      fprintf(outfile,"min facet binomials    %d\n",stats_minfacets);
                    298:      fprintf(outfile,"max elts               %d\n",stats_maxelts);
                    299:      fprintf(outfile,"min elts               %d\n",stats_minelts);
                    300:      fprintf(outfile,"max degree             %d\n",stats_maxdeg);
                    301:      fprintf(outfile,"min degree             %d\n",stats_mindeg);
                    302:      if (ifname!=0) fprintf(outfile,"%s: ",ifname);
                    303:      fprintf(outfile,"Exhaustive search, ");
                    304:      switch(lptest){
                    305:      case 1:
                    306:         fprintf(outfile,"  LP only\n");
                    307:         break;
                    308:      case 3:
                    309:         fprintf(outfile,"  A-pretest\n");
                    310:         break;
                    311:      case 2:
                    312:        fprintf(outfile," A-only\n");
                    313:        break;
                    314:      default:
                    315:         fprintf(outfile,"\n");
                    316:      }
                    317:      fprintf(outfile,"time used (in seconds) %4.2lf\n",tt);
                    318:     return 0;
                    319:     }
                    320:   }
                    321:   /* clean up */
                    322:   LP_free_space();
                    323:   if (G1!=0) gset_free(G1);
                    324: }
                    325:
                    326:
                    327:
                    328:
                    329:
                    330:
                    331:
                    332:

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