aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbremner <bremner@09fa754a-f411-0410-976a-da6bfa213b30>2006-07-11 11:15:40 +0000
committerbremner <bremner@09fa754a-f411-0410-976a-da6bfa213b30>2006-07-11 11:15:40 +0000
commitfc9b18afa66eca90d15302af3161a09e942c3a37 (patch)
tree88fca046e389959214bc20bf1b81139dcaca4d8d
parentf2f3ec70cd3c86583c1eb03b0da63f74b6aefe05 (diff)
git-svn-id: file:///export/data/bremner/svn/trunk/inetools@5465 09fa754a-f411-0410-976a-da6bfa213b30
-rw-r--r--ine_io.c53
-rw-r--r--rat2int.c139
-rw-r--r--rat2int.doc10
-rw-r--r--rat2int.h11
4 files changed, 213 insertions, 0 deletions
diff --git a/ine_io.c b/ine_io.c
new file mode 100644
index 0000000..46d1716
--- /dev/null
+++ b/ine_io.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <errno.h>
+
+void scan_for_begin(int *m_p, int *n_p, char **type_p){
+ char buf[BUFSIZ];
+ char *cursor;
+ int m,n;
+
+ 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);
+ }
+ *m_p=m;
+
+ n=strtol(cursor,&cursor,10);
+ if (errno==ERANGE || m==0){
+ fprintf(stderr,"Missing or absurd column count");
+ exit(1);
+ }
+
+ *n_p=n;
+
+ while (isblank(*cursor)){
+ cursor++;
+ }
+
+ *type_p=cursor;
+
+}
+
+void check_type( char *type, char *ok[], int count){
+ int i;
+ for (i=0; i< count; i++){
+ if (strncmp(type,ok[i],strlen(ok[i]))==0)
+ return;
+ }
+
+ fprintf(stderr,"Type %s not permitted\n",
+ type);
+ exit(1);
+}
diff --git a/rat2int.c b/rat2int.c
new file mode 100644
index 0000000..24c7ade
--- /dev/null
+++ b/rat2int.c
@@ -0,0 +1,139 @@
+/*
+ * Reads a polyhedron file on stdin with rationals and outputs an equivalent
+ * system with integer coefficents.
+ *
+ * David Bremner. bremner@unb.ca
+ *
+ */
+static char rcsid[]="$Id: rat2int.c 2055 2006-04-03 19:41:14Z bremner $";
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifndef LRSMP
+#error This file only compiles with LRSMP
+#endif
+
+#include "lrsmp.h"
+#include "rat2int.h"
+
+static long int m,n,type;
+#define MP_DIGITS 1000L
+
+static void lcm3(lrs_mp a,lrs_mp b,lrs_mp c);
+
+
+main(int argc, char **argv)
+{
+
+
+ int i,j;
+ lrs_mp l,g,scratch;
+ char *type;
+ lrs_mp *D, *N;
+ char *ok[]={ "integer", "rational"};
+ process_args(argc,argv,DOCSTRING);
+ lrs_mp_init (MP_DIGITS,stdin,stdout);
+ scan_for_begin(&m,&n,&type);
+
+ check_type(type, ok , 2);
+
+ printf("%d %d integer\n",m,n);
+ D=calloc(n,sizeof(lrs_mp));
+ N=calloc(n,sizeof(lrs_mp));
+
+ for (i=0;i<m;i++) {
+
+ for (j=0; j<n; j++){
+ readrat(N[j],D[j]);
+ }
+
+ lcm3(D[0],D[1],l);
+
+ for(j=2;j<n;j++){
+ lcm3(l,D[j],l);
+ }
+
+ mul_row(N,D,l,0);
+
+ /* reinitialize gcd */
+ copy(g,N[0]);
+ copy(scratch,N[1]);
+ gcd(g,scratch);
+
+ for (j=2; j<n ; j++){
+ copy(scratch,N[j]);
+ gcd(g,scratch);
+ }
+
+ if (negative(g))
+ storesign(g,POS);
+
+ div_row(N,D,g,0);
+
+ for (j=0; j< n; j++){
+ pmp("",N[j]);
+ }
+ fputs("\n",stdout);
+ }
+
+ printf("end\n");
+
+}
+
+/* c<- lcm(a,b) */
+
+static void lcm3(lrs_mp a,lrs_mp b,lrs_mp c)
+{
+ lrs_mp gc,ab,scratch;
+
+ copy(gc,a);
+ copy(scratch,b);
+ gcd(gc,scratch);
+
+
+ mulint(a,b,ab);
+
+ divint(ab,gc,c);
+
+}
+
+
+mul_row(N,D,l,offset)
+ lrs_mp *N,*D;
+ lrs_mp l;
+ int offset;
+{
+ lrs_mp factor,scratch;
+ int j;
+
+ for (j=offset;j<n; j++) {
+
+ /*
+ * Now multiply each numerator n_i by lcm/d_i.
+ * Implicitly, each denominator is now lcm
+ */
+
+ copy(scratch,l);
+ divint(scratch,D[j],factor);
+ mulint(N[j],factor,N[j]);
+ }
+
+}
+
+div_row(N,D,g,offset)
+ lrs_mp *N,*D;
+ lrs_mp g;
+ int offset;
+{
+ lrs_mp scratch;
+ int j;
+
+ for (j=0;j<n; j++)
+ {
+ copy(scratch,N[j]);
+
+ divint(scratch,g,N[j]);
+ }
+
+}
+
diff --git a/rat2int.doc b/rat2int.doc
new file mode 100644
index 0000000..905071c
--- /dev/null
+++ b/rat2int.doc
@@ -0,0 +1,10 @@
+
+$Id: rat2float.doc 2343 2006-04-04 12:34:35Z bremner $
+
+rat2canon takes a polytope file with rational or integer coefficents,
+and outputs an equivelent one with normalized right hand side.
+
+
+
+
+
diff --git a/rat2int.h b/rat2int.h
new file mode 100644
index 0000000..5da4256
--- /dev/null
+++ b/rat2int.h
@@ -0,0 +1,11 @@
+#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\
+"