From fba57b9c6727f39ce4f3e5554752ff648502fffc Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 28 Oct 2006 18:33:34 +0200 Subject: [PATCH] util.c: move duplicate Polyhedron_Read --- barvinok/util.h | 1 + barvinok_count.c | 30 +----------------------------- barvinok_ehrhart.cc | 30 +----------------------------- polytope_scan.c | 30 +----------------------------- util.c | 28 ++++++++++++++++++++++++++++ 5 files changed, 32 insertions(+), 87 deletions(-) diff --git a/barvinok/util.h b/barvinok/util.h index ee518dd..dd4eeed 100644 --- a/barvinok/util.h +++ b/barvinok/util.h @@ -36,6 +36,7 @@ extern "C" { void value_lcm(Value i, Value j, Value* lcm); int random_int(int max); +Polyhedron *Polyhedron_Read(unsigned MaxRays); Polyhedron* Polyhedron_Polar(Polyhedron *P, unsigned NbMaxRays); void Polyhedron_Polarize(Polyhedron *P); Polyhedron* supporting_cone(Polyhedron *P, int v); diff --git a/barvinok_count.c b/barvinok_count.c index ce3f5ab..8de090e 100644 --- a/barvinok_count.c +++ b/barvinok_count.c @@ -22,34 +22,6 @@ struct option options[] = { }; #endif -static Polyhedron *Polyhedron_Read() -{ - int vertices = 0; - unsigned NbRows, NbColumns; - Matrix *M; - Polyhedron *P; - char s[128]; - - while (fgets(s, sizeof(s), stdin)) { - if (*s == '#') - continue; - if (strncasecmp(s, "vertices", sizeof("vertices")-1) == 0) - vertices = 1; - if (sscanf(s, "%u %u", &NbRows, &NbColumns) == 2) - break; - } - if (feof(stdin)) - return NULL; - M = Matrix_Alloc(NbRows,NbColumns); - Matrix_Read_Input(M); - if (vertices) - P = Rays2Polyhedron(M, MAXRAYS); - else - P = Constraints2Polyhedron(M, MAXRAYS); - Matrix_Free(M); - return P; -} - int main(int argc, char **argv) { Value cb; @@ -65,7 +37,7 @@ int main(int argc, char **argv) } } - A = Polyhedron_Read(); + A = Polyhedron_Read(MAXRAYS); value_init(cb); Polyhedron_Print(stdout, P_VALUE_FMT, A); barvinok_count(A, &cb, MAXRAYS); diff --git a/barvinok_ehrhart.cc b/barvinok_ehrhart.cc index ac65acd..9899d8c 100644 --- a/barvinok_ehrhart.cc +++ b/barvinok_ehrhart.cc @@ -39,34 +39,6 @@ struct option options[] = { }; #endif -static Polyhedron *Polyhedron_Read() -{ - int vertices = 0; - unsigned NbRows, NbColumns; - Matrix *M; - Polyhedron *P; - char s[128]; - - while (fgets(s, sizeof(s), stdin)) { - if (*s == '#') - continue; - if (strncasecmp(s, "vertices", sizeof("vertices")-1) == 0) - vertices = 1; - if (sscanf(s, "%u %u", &NbRows, &NbColumns) == 2) - break; - } - if (feof(stdin)) - return NULL; - M = Matrix_Alloc(NbRows,NbColumns); - Matrix_Read_Input(M); - if (vertices) - P = Rays2Polyhedron(M, MAXRAYS); - else - P = Constraints2Polyhedron(M, MAXRAYS); - Matrix_Free(M); - return P; -} - int main(int argc, char **argv) { Polyhedron *A, *C, *U; @@ -94,7 +66,7 @@ int main(int argc, char **argv) } } - A = Polyhedron_Read(); + A = Polyhedron_Read(MAXRAYS); param_name = Read_ParamNames(stdin, 1); Polyhedron_Print(stdout, P_VALUE_FMT, A); C = Cone_over_Polyhedron(A); diff --git a/polytope_scan.c b/polytope_scan.c index 0e0c6c2..03f8e0b 100644 --- a/polytope_scan.c +++ b/polytope_scan.c @@ -25,34 +25,6 @@ struct option options[] = { }; #endif -static Polyhedron *Polyhedron_Read() -{ - int vertices = 0; - unsigned NbRows, NbColumns; - Matrix *M; - Polyhedron *P; - char s[128]; - - while (fgets(s, sizeof(s), stdin)) { - if (*s == '#') - continue; - if (strncasecmp(s, "vertices", sizeof("vertices")-1) == 0) - vertices = 1; - if (sscanf(s, "%u %u", &NbRows, &NbColumns) == 2) - break; - } - if (feof(stdin)) - return NULL; - M = Matrix_Alloc(NbRows,NbColumns); - Matrix_Read_Input(M); - if (vertices) - P = Rays2Polyhedron(M, MAXRAYS); - else - P = Constraints2Polyhedron(M, MAXRAYS); - Matrix_Free(M); - return P; -} - static void scan_poly(Polyhedron *S, int pos, Value *z, Matrix *T) { if (!S) { @@ -108,7 +80,7 @@ int main(int argc, char **argv) } } - A = Polyhedron_Read(); + A = Polyhedron_Read(MAXRAYS); if (direct) { inv = Identity(A->Dimension+1); diff --git a/util.c b/util.c index 8a18292..0dca567 100644 --- a/util.c +++ b/util.c @@ -46,6 +46,34 @@ int random_int(int max) { return (int) (((double)(max))*rand()/(RAND_MAX+1.0)); } +Polyhedron *Polyhedron_Read(unsigned MaxRays) +{ + int vertices = 0; + unsigned NbRows, NbColumns; + Matrix *M; + Polyhedron *P; + char s[128]; + + while (fgets(s, sizeof(s), stdin)) { + if (*s == '#') + continue; + if (strncasecmp(s, "vertices", sizeof("vertices")-1) == 0) + vertices = 1; + if (sscanf(s, "%u %u", &NbRows, &NbColumns) == 2) + break; + } + if (feof(stdin)) + return NULL; + M = Matrix_Alloc(NbRows,NbColumns); + Matrix_Read_Input(M); + if (vertices) + P = Rays2Polyhedron(M, MaxRays); + else + P = Constraints2Polyhedron(M, MaxRays); + Matrix_Free(M); + return P; +} + /* Inplace polarization */ void Polyhedron_Polarize(Polyhedron *P) -- 2.11.4.GIT