void valid_ints( int eqdimpar, RAT *eqarpar, int neqpar,int eqrlpar, int iedimpar, RAT *iearpar, int niepar, int ierlpar, char *fname ) { RAT *eqsum = (RAT *)0; RAT *iesum = (RAT *)0; fprintf (prt,"computing all valid integral points "); fflush(prt); /* 17.01.1994: include logging on file porta.log */ porta_log( "computing all valid integral points "); fflush(logfile); if (!lowbds || !upbds) msg( "\nno bounds are given", "", 0 ); for (eqdim = 0 ; eqdim < eqdimpar; eqdim++) if (lowbds[eqdim] > upbds[eqdim]) msg("lower bound greater than upper bound", "", 0); neq = neqpar; eqdim = eqdimpar; eqar = eqarpar; eqrl = eqrlpar; ubea = eqar+neq*eqrl; nie = niepar; iedim = iedimpar; iear = iearpar; ierl = ierlpar; ubia = iear+nie*ierl; fname[strlen(fname)-4] = '\0'; strcat(fname,".poi"); fp = wfopen(fname); fprintf(fp,"DIM =%3d\n\nCONV_SECTION\n",dim); integ = (int *) allo(integ,0,eqdim*sizeof(int)); reknum = intnum = 0; eqsum = (RAT *) RATallo(eqsum,0,(1+neq)*(eqdim+1)); iesum = (RAT *) RATallo(iesum,0,(1+nie)*(iedim+1)); integ_rekurs(eqsum,iesum,0); #if defined WIN32 || defined __CYGWIN32__ || defined __APPLE__ free(integ); #else // WIN32 cfree(integ); #endif // WIN32 fprintf(fp,"\nEND\n"); fclose(fp); fprintf(prt,"\n\nnumber of valid integral points : %i\n\n",intnum); fprintf(prt,"integral points written to file %s\n",fname); /* 17.01.1994: include logging on file porta.log */ porta_log( "\n\nnumber of valid integral points : %i\n\n",intnum); porta_log( "integral points written to file %s\n",fname); }
void writesys( FILE *fp, int frow, int lrow, int rowl, int format, int *indx, char eqie, int *start ) { int i,j; if (!MP_realised) { max = (RAT *) RATallo(CP 0,0,U rowl); for (j = 0; j < rowl; j++) max[j].num = max[j].den.i = 0; for (i = frow; i < lrow; i++) max_vals( max, porta_list[i]->sys, rowl ); width_line(max,rowl,format); } for (i = frow; i < lrow; i++) { /* fprintf(fp,"(%3d) ",i-frow+1); */ fprintf(fp,"(%3d) ",*start); (*start)++; (* writeline)(fp,rowl,porta_list[i]->sys,format,max,eqie,indx); if (option & Statistic_of_coefficients) writestatline(fp,(int *)porta_list[i]->ptr); fprintf(fp,"\n"); } /* for i */ /* fprintf(fp,"\n"); */ if (!MP_realised) RATallo(max,rowl,0); }
void read_eqie( RAT **ar, int dim, int *equa, int *ineq, int *maxrows, int *line, char *fname, char in_line[], char *scanned_inline ) /*****************************************************************/ /* * Read the INEQUALITY_SECTION into the table "ar". * For each (in)equality, the corresponding line of "ar" contains, in this order: * the "dim" coefficients of the variables x1--xn, * the right-hand side, * 0 if it was an equation, 1 if it was an inequality. * All inequalities are stored as "<=" inequalities. * Lines as * "x1 - 1 <= 3 + x2" * are interpreted as * "x1 -x2 <= 4" */ { char *p,*in; int i,rs=0,index=0,j,sysrow, numberread,nonempty; RAT val; sysrow = dim+2; /* row length of array "ar" */ do { nonempty = get_line(fp,fname,in_line,line); } while (!nonempty); for (i = 0; scan_line(&val,3,dim,*line, fname,in_line,scanned_inline); i++) { /* * scan_line() reads an inequality into string "scanned_inline", * with a little formatting. * "val" is not used. */ p = in = scanned_inline; rs = 0; /* rs records the type of inequality, * rs = 0 means: type not yet known. */ /* scan string "scanned_inline" up to '\0' or '#' */ while (*p != '\0' && *p != '#' ) { val.den.i = 1; val.num = 1; if (*p == '-') val.num = -1; /* * If: {+,-} has been read, * or {<,=,>} followed by {x,0,1,..,9} has been read, * or it is the beginning of the line. then ... */ if ( *p == '-' || *p == '+' || (p == scanned_inline || (p != scanned_inline && (*(p-1)=='<' || *(p-1)=='=' || *(p-1)=='>')) && ((*p < 58 && *p > 47) || *p =='x') ) ) { numberread = 0; if ( *p == '-' || *p == '+') p++; in = p; while (*p > 47 && *p < 58) p++; if (in != p) { /* in points to a number, p to the next non-number */ numberread = 1; val.num *= atoi(in); if (*p == '/') { p++; in = p; while (*p > 47 && *p < 58) p++; if (p == in) msg("%s, line %i : invalid denominator", fname,*line); if ((val.den.i = atoi(in)) <= 0) msg("%s, line %i : invalid denominator", fname,*line); } } /* if (in != p) */ if (*p == 'x') { p++; in = p; while (*p > 47 && *p < 58) p++; if (p == in) msg("%s, line %i : invalid format",fname,*line); index = atoi(in)-1; if (index > dim-1 || index < 0) msg("%s, line %i : only variable names x1,...,xdim allowed", fname,*line); } /* * Change by M.S. 1.6.92: * The following four lines of code are changed. * * In the case (*p in {+,-}), * something like "10 +", but not "x10 +" has been encountered. * In the case (rs==0 && *p in {<,>,>} ), * something like "10 <", but not "x10 <" has been encountered. * In both cases, the number "10" is interpreted as part of * the right-hand side. * But it should be tested, * whether a number has actually been read. * Otherwise * "x1++x2 <= 20\n" is interpreted as * "x1+1+x2 <= 20\n". */ else if (numberread && (*p == '+' || *p == '-' || ((rs == 0) && (*p =='<'||*p == '>'||*p == '=')))) { index = dim; } /* The following four lines mean: * If "<=" or ">=" or "==" has already been read (i.e. rs > 0), * and if p points to the end of the line, * then interpret the number in val as the right hand side. * to be stored in the dim-th position of the current row * of table "ar". */ else if (numberread && rs && (*(p) == '\0' || *(p) == '#')) { index = dim; } else msg("%s, line %i : invalid format",fname,*line); } /* if ......... */ else if ((p != scanned_inline) && (*p == '<' || *p == '>' || *p == '=')) { /* * Record the type of inequality: * rs = 1 if it is an equation ("=" or "==") * rs = 2 if it is a "<=" inequality (may also be written "=<") * rs = 3 if it is a ">=" inequality (may also be written "=>") */ if (++rs > 1) msg("%s, line %i : invalid format",fname,*line); if ((*p == '=') && (*(p+1) == '=')) p++; else if ((*p == '=') && (*(p+1) != '>') && (*(p+1) != '<')); else if ((*p == '=' && *(p+1) == '>') || (*p == '>' && *(p+1) == '=')) { rs++;rs++; p++; } else if ((*p == '=' && *(p+1) == '<') || (*p == '<' && *(p+1) == '=')) { rs++; p++; } else msg("%s, line %i : invalid format",fname,*line); p++; index = -1; } /* else if < = > */ else msg("%s, line %i : invalid format",fname,*line); if (index > -1) { /* not "< > =" */ if (index == dim) val.num *= -1; if (rs ) I_RAT_sub(*(*ar+i*sysrow+index),val,*ar+i*sysrow+index); else I_RAT_add(*(*ar+i*sysrow+index),val,*ar+i*sysrow+index); } } /* while */ /* transform ">=" into "<=" by multiplying the inequality with -1 */ if (rs == 3 ) { /* >= */ for (j = 0; j <= dim; j++) (*ar+i*sysrow+j)->num = -(*ar+i*sysrow+j)->num; rs -= 1; } (*ar+(i+1)*sysrow-1)->num = --rs; /* * Now rs = 0 if the line was an equation, * and rs = 1 if the line was an inequality. * The last line stored rs into the "dim+1"th position of ar[i]. */ (rs == 1) ? (*ineq)++ : (*equa)++; if ((*ineq)+(*equa)+2 > *maxrows) { *ar = (RAT *) RATallo(*ar,(*maxrows)*(dim+2),(*maxrows+INCR_INSYS_ROW)*(dim+2)); *maxrows += INCR_INSYS_ROW; } do { nonempty = get_line(fp,fname,in_line,line); } while (!nonempty); } /* for i */ }
int read_input_file( char *fname, FILE *outfp, int *dim, RAT **ar, int *nel_ar, char *intkey1, int **intli1, char *intkey2, int **intli2, char *RATkey1, RAT **RATli1 ) /*****************************************************************/ /* * Read the dimension "dim", * a table "ar" of points (in case of a .poi file), * or of inequalities (in case of a .ieq file), * a line "intli1" of integers occurring after keyword "intkey1", * a line "intli2" of integers occurring after keyword "intkey2", * a line "RATli1" of rationals occurring after keyword "RATkey1". * "ar6" is a point that is output in the VALID section in the .ieq file. * * Change by M.S. 5.6.92: * If "outfp" exists (e.g. if is_set(Sort)), * copy the input file into outfp, * except for the INEQUALITIES_SECTION, the CONV_SECTION, and the CONE_SECTION, * and END. */ { int i,j,ieqs,nonempty,arrows=0,arrowl=0,cone = 0,conv = 0,line; int *hip; char *in,*end = "END", equalities[22], convstr[13],conestr[13],key_eli[18],key_val[6],key_low[13],key_upp[13], *comm = "COMMENT" ; char scanned_inline[MAXLINE]; char in_line[MAXLINE]; RAT val; line = 0; strcpy (equalities,"INEQUALITIES_SECTION"); strcpy (convstr,"CONV_SECTION"); strcpy (conestr,"CONE_SECTION"); strcpy (key_eli,"ELIMINATION_ORDER"); strcpy (key_val,"VALID"); strcpy (key_upp,"UPPER_BOUNDS"); strcpy (key_low,"LOWER_BOUNDS"); fp = fopen(fname,"r"); if (fp == 0) msg( "%s : no such file", fname, 0 ); /* * Read the first line into string "in_line". Leading blanks are skipped. * In_Line should start with "DIM=". */ do { nonempty = get_line(fp,fname,in_line,&line ); } while (!nonempty); scan_line(&val,3,0,line,fname,in_line,scanned_inline); if (strncmp(scanned_inline,"DIM=",4) == 0) { in = scanned_inline+4; *dim = atoi(in); if (*dim == 0) msg("%s, line %i : dimension error",fname,line); if (outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } ieqs = (strcmp(fname+strlen(fname)-4,".ieq") == 0); if( ieqs ) { equa = ineq = 0; convstr[0] = conestr[0] = '\n'; arrowl = *dim+2; if (!strcmp(intkey1,"ELIMINATION_ORDER") || !strcmp(intkey2,"ELIMINATION_ORDER")) key_eli[0] = '\n'; if (!strcmp(intkey1,"LOWER_BOUNDS") || !strcmp(intkey2,"LOWER_BOUNDS")) key_low[0] = '\n'; if (!strcmp(intkey1,"UPPER_BOUNDS") || !strcmp(intkey2,"UPPER_BOUNDS")) key_upp[0] = '\n'; if (!strcmp(RATkey1,"VALID")) key_val[0] = '\n'; } else { /* * key_eli, key_low, key_upp, and key_val are set to 0, * if they already appear as input parameters to this subroutine. * In this way, if e.g. the keyword "VALID" is encountered twice in the * input file, an error message is produced. * "convstr" and "conestr" are set to "\n", * so that the keywords "CONV_SECTION" and "CONE_SECTION" * result in an error message, if they appear in the .ieq file. */ cone = conv = 0; key_val[0] = key_upp[0] = key_low[0] = key_eli[0] = equalities[0] = '\n'; arrowl = *dim+1; } /* * ar6 is initialized to 0. * It is overwritten by a point in the CONV_SECTION, * or by a point in the VALID section. */ ar6 = (RAT *) RATallo(ar6,0,*dim); for (j = 0; j < *dim; j++) { ar6[j].num = 0; ar6[j].den.i = 1; } /* Read the next line into string "in_line" and scan it */ nonempty = get_line(fp,fname,in_line,&line ); scan_line(&val,3,0,line,fname,in_line,scanned_inline); do { if (!nonempty) { if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); } else if (strncmp(scanned_inline,comm,7) == 0) { /* * Overread keyword COMMENT and all following lines, * until the next keyword (i.e. one of the arguments of nstrcmp() ) * is encountered. */ do { if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); } while (nstrcmp(scanned_inline,conestr,equalities,end, intkey1,intkey2,RATkey1,convstr) || !nonempty); } else if (strcmp(scanned_inline,RATkey1) == 0) { /* * If the keyword RATkey1 is encountered, * read the next line of "dim" rationals into array RATli1. * RATkey1 is "VALID" for "traf *.ieq" applications. */ if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } /* When calling read_input_file, RATkey1 is always assigned to a const argument (string). Therefore it isn't allowed to assign new values to this argument. By the way, this statement causes a bus error on some architectures like the HP! 18.01.1994, Andreas Loebel RATkey1[0] = '\n'; *RATli1 = (RAT *) RATallo(*RATkey1,0,*dim); */ *RATli1 = (RAT *) RATallo(CP 0,0,*dim); do { nonempty = get_line(fp,fname,in_line,&line); if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } while (!nonempty); scan_line(*RATli1,1,*dim,line,fname,in_line,scanned_inline); nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); } else if (strcmp(scanned_inline,key_val) == 0) { /* * keyval[0] == "VALID", iff * Ratkey1 was not "VALID" at the start of function read_input_file() * Otherwise keyval[0] = '\n' * --> "VALID" is accepted as a keyword at most once. */ if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } key_val[0] = '\n'; /* * Change by M.S.: "ar6" was already allocated earlier, * and it is never freed in this loop. ar6 = (RAT *) RATallo(ar6,0,*dim); */ do { nonempty = get_line(fp,fname,in_line,&line); if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } while (!nonempty); scan_line(ar6,1,*dim,line,fname,in_line,scanned_inline); nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); /* change by M.S. 31.5.92: * "ar6" is also used when reading the CONV_SECTION, so don't free it. ar6 = (RAT *) RATallo(ar6,*dim,0); */ } else if (strcmp(scanned_inline,intkey1) == 0) { if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } intkey1[0] = '\n'; *intli1 = (int *) allo(*intli1,0,*dim*sizeof(int)); do { nonempty = get_line(fp,fname,in_line,&line); if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } while (!nonempty); scan_line((RAT *)*intli1,2,*dim,line,fname,in_line,scanned_inline); nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); } else if (strcmp(scanned_inline,intkey2) == 0) { if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } intkey2[0] = '\n'; *intli2 = (int *) allo(*intli2,0,*dim*sizeof(int)); do { nonempty = get_line(fp,fname,in_line,&line); if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } while (!nonempty); scan_line((RAT *)*intli2,2,*dim,line,fname,in_line,scanned_inline); nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); } else if (!strcmp(scanned_inline,key_eli) || !strcmp(scanned_inline,key_low) || !strcmp(scanned_inline,key_upp) ) { /* * array "hip" is just a temporary array. */ if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } if (!strcmp(scanned_inline,key_eli)) key_eli[0] = '\n'; if (!strcmp(scanned_inline,key_low)) key_low[0] = '\n'; if (!strcmp(scanned_inline,key_upp)) key_upp[0] = '\n'; hip = (int *) allo(CP 0,0,*dim*sizeof(int)); do { nonempty = get_line(fp,fname,in_line,&line); if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } while (!nonempty); scan_line((RAT *)hip,2,*dim,line,fname,in_line,scanned_inline); nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); hip = (int *) allo(hip,*dim*sizeof(int),0); } else if (strcmp(scanned_inline, convstr) == 0) { /* * Read the CONV_SECTION into array "ar". * For all points j=1,...,conv in the CONV_SECTION, * ar[j-1][dim] is set to 1. * "arrowl" was set to dim+1 earlier. */ convstr[0] = '\n'; *ar = (RAT *) RATallo(*ar,arrows*arrowl, (arrows+INCR_INSYS_ROW)*arrowl); arrows += INCR_INSYS_ROW; do { nonempty = get_line(fp,fname,in_line,&line); } while (!nonempty); while (scan_line(*ar+(conv+cone)*arrowl,0,*dim,line,fname, in_line,scanned_inline)) { (*ar+(conv+cone)*arrowl+*dim)->num = 1; if (conv+cone+2 > arrows) { *ar = (RAT *) RATallo(*ar,arrows*arrowl, (arrows+INCR_INSYS_ROW)*arrowl); arrows += INCR_INSYS_ROW; } do { nonempty = get_line(fp,fname,in_line,&line); } while (!nonempty); conv++; } /* repeat the last point in array "ar6" */ for (j = 0; j < *dim; j++) ar6[j] = (*ar+(conv+cone-1)*arrowl)[j]; } else if ((strcmp(scanned_inline, conestr) == 0)) { /* * Read the CONE_SECTION * ar[j-1][dim] is initialized by RATallo to 0. */ conestr[0] = '\n'; *ar = (RAT *) RATallo(*ar,arrows*arrowl, (arrows+INCR_INSYS_ROW)*arrowl); arrows += INCR_INSYS_ROW; do { nonempty = get_line(fp,fname,in_line,&line); } while (!nonempty); while (scan_line(*ar+(conv+cone)*arrowl,0,*dim,line,fname, in_line,scanned_inline)) { if (conv+cone+2 > arrows) { *ar = (RAT *) RATallo(*ar,arrows*arrowl, (arrows+INCR_INSYS_ROW)*arrowl); arrows += INCR_INSYS_ROW; } do { nonempty = get_line(fp,fname,in_line,&line); } while (!nonempty); cone++; } } else if ( (strcmp(scanned_inline, equalities) == 0)) { /* * Read the INEQUALITIES_SECTION * "arrowl" was set to dim+2 earlier. */ equalities[0] = '\n'; *ar = (RAT *) RATallo(*ar,arrows*arrowl, (arrows+INCR_INSYS_ROW)*arrowl); arrows += INCR_INSYS_ROW; read_eqie(ar,*dim,&equa,&ineq,&arrows,&line, fname,in_line,scanned_inline); nonempty = 1; } else if (strcmp(scanned_inline,end) == 0) { i = (ieqs) ? equa+ineq : conv+cone; *nel_ar = (i+1)*arrowl; *ar = (RAT *) RATallo(*ar,arrows*arrowl,*nel_ar); fclose(fp); fprintf(prt,"input file %s o.k.\n",fname); fprintf(prt, "dimension : %4i \n",*dim); /* 17.01.1994: include logging on file porta.log */ porta_log( "input file %s o.k.\n",fname); porta_log( "dimension : %4i \n",*dim); if (ieqs) { fprintf(prt,"number of equations : %4i \n",equa); fprintf(prt,"number of inequalities : %4i \n\n",ineq); /* 17.01.1994: include logging on file porta.log */ porta_log( "number of equations : %4i \n",equa); porta_log( "number of inequalities : %4i \n\n",ineq); } else { fprintf(prt,"number of cone-points : %4i \n",cone); fprintf(prt,"number of conv-points : %4i \n\n",conv); /* 17.01.1994: include logging on file porta.log */ porta_log( "number of cone-points : %4i \n",cone); porta_log( "number of conv-points : %4i \n\n",conv); } return (i); } else msg("%s, line %i : invalid format",fname,line); } while (1); }