From 7a583e3a287eb468e82e6509b467b6701e50dade Mon Sep 17 00:00:00 2001 From: bremner Date: Thu, 1 Jun 2006 18:56:34 +0000 Subject: git-svn-id: file:///export/data/bremner/svn/trunk/inetools@5359 09fa754a-f411-0410-976a-da6bfa213b30 --- Makefile | 8 ++++- README | 22 ++++++++---- countrows.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ countrows.doc | 4 +++ countrows.ds | 8 +++++ rat2canon.c | 5 +-- rat2canon.ds | 14 ++++++++ 7 files changed, 165 insertions(+), 10 deletions(-) create mode 100644 countrows.c create mode 100644 countrows.doc create mode 100644 countrows.ds create mode 100644 rat2canon.ds diff --git a/Makefile b/Makefile index b04285a..9d0dfcc 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ .SUFFIXES: .doc .ds -BIN= rat2float float2rat rat2canon +BIN= rat2float float2rat rat2canon countrows MPOBJ= CC=gcc @@ -46,6 +46,12 @@ rat2canon: rat2canon.c rat2canon.ds $(MPOBJ) $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $(MPOBJ) $(LDFLAGS) $< +countrows.ds: countrows.doc + +countrows: countrows.c countrows.ds $(MPOBJ) + $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $(MPOBJ) $(LDFLAGS) $< + + float2rat.ds: float2rat.doc diff --git a/README b/README index 2e57145..c7c0888 100644 --- a/README +++ b/README @@ -1,18 +1,16 @@ $Id$ -Release 0.4 +Release 0.5 This directory contains some tools for manipulating lrs/cdd ine files. -At the moment there is only +At the moment there is - rat2float convert to floating point. Note that this - necessarily loses precision. Also, - It assumes the numerator and denominator are both - long integers, unless compiled with - multiprecision support. + + countrows replace the ****** in lrs output with the number + of rows float2rat convert floating point to rationals. Here the conversion is exact, but not very clever, so @@ -20,9 +18,19 @@ At the moment there is only Current version of lrs can handle it, at least the gmp version. + rat2canon put the inequalities/vectors in a canonical form This one only compiles with multiprecision support + + rat2float convert to floating point. Note that this + necessarily loses precision. Also, + It assumes the numerator and denominator are both + long integers, unless compiled with + multiprecision support. + + + I have more code around for, e.g. centering points around the origin and other simple tasks that I would be willing to shake the dust off of if there is interest. diff --git a/countrows.c b/countrows.c new file mode 100644 index 0000000..9120827 --- /dev/null +++ b/countrows.c @@ -0,0 +1,114 @@ +/* + * Reads a polyhedron file on stdin, counts the rows, and outputs + * an equivalent file with a corrected row count. + * + * David Bremner. bremner@cs.unb.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 "countrows.ds" + + +int main(argc,argv) + int argc; + char **argv; +{ + int i,j; + long int m,n; + + char **lines; + int line_count; + char buf[BUFSIZ]; + + char *type; + 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); + } + + cursor=buf; + + while(isspace(*cursor)) + cursor++; + + while (!isspace(*cursor)) + cursor++; + + n=strtol(cursor,&cursor,10); + if (errno==ERANGE || n==0){ + fprintf(stderr,"Missing or absurd column count"); + exit(1); + } + + line_count=2*n; + lines=calloc(line_count,sizeof(char *)); + + while (isblank(*cursor)){ + cursor++; + } + + type=strdup(cursor); + + m=0; + do { + if (fgets(buf,BUFSIZ,stdin)==NULL) { + fprintf(stderr,"missing end"); + exit(1); + } + if (strncmp(buf,"end",3)!=0){ + if (m>=line_count){ + line_count *=2; + lines=realloc(lines,line_count*sizeof(char *)); + } + + lines[m++]=strdup(buf); + } + + } while (strncmp(buf,"end",3)!=0); + + + + printf("%ld %ld %s",m,n,type); + + for (i=0;i 1 && argv[1][0]=='-' && argv[1][1]=='h') usage(); diff --git a/rat2canon.c b/rat2canon.c index 872a286..2a1e0f8 100644 --- a/rat2canon.c +++ b/rat2canon.c @@ -25,7 +25,7 @@ typedef lrs_mp integer_t; #define MP_DIGITS 1000L -#include "rat2float.ds" +#include "rat2canon.ds" static int *rows=NULL; static long int m,n; @@ -65,7 +65,8 @@ int main(argc,argv) while ( fgets(buf,BUFSIZ,stdin) !=NULL ) { fputs(buf,stdout); - if (strncmp(buf,"begin",5)==0) break; + for (cursor=buf; isblank(*cursor); cursor++); + if (strncmp(cursor,"begin",5)==0) break; } if (fgets(buf,BUFSIZ,stdin)==NULL) { diff --git a/rat2canon.ds b/rat2canon.ds new file mode 100644 index 0000000..2447acb --- /dev/null +++ b/rat2canon.ds @@ -0,0 +1,14 @@ +#define DOCSTRING "\n\ +$Id: rat2float.doc 2343 2006-04-04 12:34:35Z bremner $ \n\ +\n\ +rat2canon takes a polytope file with rational or integer coefficents, \n\ +and outputs an equivelent one with normalized right hand side.\n\ +\n\ +\n\ +\n\ +\n\ +\n\ +" + +int usage(){ fprintf(stderr,"\n%s\n",rcsid);fprintf(stderr,DOCSTRING); exit(1); } +#define CHECK_HELP if (argc > 1 && argv[1][0]=='-' && argv[1][1]=='h') usage(); -- cgit v1.2.3