diff options
author | bremner <bremner@09fa754a-f411-0410-976a-da6bfa213b30> | 2006-06-01 18:56:34 +0000 |
---|---|---|
committer | bremner <bremner@09fa754a-f411-0410-976a-da6bfa213b30> | 2006-06-01 18:56:34 +0000 |
commit | 7a583e3a287eb468e82e6509b467b6701e50dade (patch) | |
tree | 5c8ef119ec7f7653fb10f6957e2c1b622e95aa53 | |
parent | 98fb9daefbb8afd80c20525782cdefa86d13e92c (diff) |
git-svn-id: file:///export/data/bremner/svn/trunk/inetools@5359 09fa754a-f411-0410-976a-da6bfa213b30
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | README | 22 | ||||
-rw-r--r-- | countrows.c | 114 | ||||
-rw-r--r-- | countrows.doc | 4 | ||||
-rw-r--r-- | countrows.ds | 8 | ||||
-rw-r--r-- | rat2canon.c | 5 | ||||
-rw-r--r-- | rat2canon.ds | 14 |
7 files changed, 165 insertions, 10 deletions
@@ -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 @@ -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 <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <float.h> +#include <errno.h> +#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<m;i++) + fputs(lines[i],stdout); + + fputs("end\n",stdout); +} + + + + + + diff --git a/countrows.doc b/countrows.doc new file mode 100644 index 0000000..48e9e9e --- /dev/null +++ b/countrows.doc @@ -0,0 +1,4 @@ + + + Reads a polyhedron file on stdin, counts the rows, and outputs + an equivalent file with a corrected row count. diff --git a/countrows.ds b/countrows.ds new file mode 100644 index 0000000..1d2aa66 --- /dev/null +++ b/countrows.ds @@ -0,0 +1,8 @@ +#define DOCSTRING "\n\ +\n\ + Reads a polyhedron file on stdin, counts the rows, and outputs \n\ + an equivalent file with a corrected row count.\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(); 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(); |