/* * 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.h" 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 *ok[]={ "integer", "rational" }; char *type; char buf[BUFSIZ]; process_args(argc,argv,DOCSTRING); lrs_mp_init (MP_DIGITS,stdin,stdout); scan_for_begin(&m,&n,&type); check_type(type, ok, 2); An=calloc(m,sizeof(lrs_mp*)); Ad=calloc(m,sizeof(lrs_mp*)); rows=calloc(m,sizeof(int)); for (i=0; i