From 0adbe5a920fe6106109f14d6bdb28dee49cb8774 Mon Sep 17 00:00:00 2001 From: bremner Date: Thu, 1 Jun 2006 15:21:54 +0000 Subject: first version of rat2canon git-svn-id: file:///export/data/bremner/svn/trunk/inetools@5354 09fa754a-f411-0410-976a-da6bfa213b30 --- Makefile | 9 ++- rat2canon.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rat2canon.doc | 10 ++++ 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 rat2canon.c create mode 100644 rat2canon.doc diff --git a/Makefile b/Makefile index 631a4cf..5c00003 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ .SUFFIXES: .doc .ds -BIN= rat2float float2rat +BIN= rat2float float2rat rat2canon MPOBJ= CC=gcc @@ -39,6 +39,13 @@ rat2float: rat2float.c rat2float.ds $(MPOBJ) $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $(MPOBJ) $(LDFLAGS) $< +rat2canon.ds: rat2canon.doc + +rat2canon: rat2canon.c rat2canon.ds $(MPOBJ) + $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $(MPOBJ) $(LDFLAGS) $< + + + float2rat.ds: float2rat.doc float2rat: float2rat.c float2rat.ds diff --git a/rat2canon.c b/rat2canon.c new file mode 100644 index 0000000..88b72b3 --- /dev/null +++ b/rat2canon.c @@ -0,0 +1,178 @@ +/* + * 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 "rat2float.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); + if (strncmp(buf,"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