laurent_old.cc: laurent_summator_old: member initializer list: base classes first
[barvinok.git] / collect_polytopes.c
blobb649077df7893a096a2d6279a605c52359fc2563
1 #include <assert.h>
2 #include <dlfcn.h>
3 #include <limits.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <barvinok/evalue.h>
8 #include <barvinok/barvinok.h>
10 /* gcc -shared -g collect_polytopes.c -rdynamic -o libcollect.so -ldl -lc -lgmp */
12 evalue* barvinok_enumerate_e(Polyhedron *P,
13 unsigned exist, unsigned nparam, unsigned MaxRays)
15 static evalue *(*orig)(Polyhedron *, unsigned, unsigned, unsigned) = NULL;
16 static char *prefix = NULL;
17 evalue *res;
18 static int recurse = 0;
19 static int counter = 0;
21 if (!orig) {
22 void *handle = dlopen("libbarvinok.so", RTLD_LAZY);
23 assert(handle);
24 orig = dlsym(handle, "barvinok_enumerate_e");
25 assert(orig);
26 dlclose(handle);
28 prefix = getenv("POLYTOPE_PREFIX");
29 if (prefix)
30 prefix = strdup(prefix);
33 if (prefix && !recurse) {
34 char path[PATH_MAX];
35 FILE *f;
36 int i, j;
37 unsigned nr, nc;
39 snprintf(path, PATH_MAX, "%s%05d", prefix, counter++);
40 f = fopen(path, "w");
41 fprintf(f, "%d %d\n", nr=P->NbConstraints, nc=P->Dimension+2);
42 for (i=0; i < nr; i++) {
43 for (j=0; j < nc; j++) {
44 value_print(f," "P_VALUE_FMT" ", P->Constraint[i][j]);
46 fprintf(f, "\n");
48 fprintf(f, "\nE %d\nP %d\n", exist, nparam);
49 fclose(f);
52 recurse = 1;
53 res = orig(P, exist, nparam, MaxRays);
54 recurse = 0;
56 return res;