/* * Reads a polyhedron file on stdin with rationals and outputs * a canonical form with normalized rhs and sorted constraints. * * David Bremner. bremner@cs.mcgill.ca * */ static char rcsid[]="$Id: rat2float.c 2343 2006-04-04 12:34:35Z bremner $"; #ifndef LRSMP #error This file only compiles with LRSMP #endif #include #include #include #include #include #include "lrsmp.h" typedef lrs_mp integer_t; #define MP_DIGITS 1000L #include "rat2canon.ds" static int *rows=NULL; static long int m,n; static lrs_mp **An; static lrs_mp **Ad; int cmprow(const void *i_p,const void *j_p){ int i=*(int *)i_p; int j=*(int *)j_p; int cval; int k=0; /* the trick here is that the denominators are always positive */ while( k< n && ( cval=comprod(An[i][k],Ad[j][k],An[j][k],Ad[i][k])) == 0){ k++; } return cval; } int main(argc,argv) int argc; char **argv; { int i,j; char format[BUFSIZ]; char buf[BUFSIZ]; char *cursor; CHECK_HELP; lrs_mp_init (MP_DIGITS,stdin,stdout); while ( fgets(buf,BUFSIZ,stdin) !=NULL ) { fputs(buf,stdout); for (cursor=buf; isblank(*cursor); cursor++); if (strncmp(cursor,"begin",5)==0) break; } if (fgets(buf,BUFSIZ,stdin)==NULL) { fprintf(stderr,"No parameter line"); exit(1); } m=strtol(buf,&cursor,10); if (errno==ERANGE || m==0){ fprintf(stderr,"Missing or absurd row count"); exit(1); } An=calloc(m,sizeof(lrs_mp*)); Ad=calloc(m,sizeof(lrs_mp*)); rows=calloc(m,sizeof(int)); n=strtol(cursor,&cursor,10); if (errno==ERANGE || m==0){ fprintf(stderr,"Missing or absurd column count"); exit(1); } for (i=0; i