4 #include <polylib/polylibgmp.h>
5 #include <barvinok/util.h>
6 #include "basis_reduction.h"
9 #ifdef HAVE_GROWING_CHERNIKOVA
10 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
15 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
18 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
21 struct option options
[] = {
22 { "direct", no_argument
, 0, 'd' },
23 { "version", no_argument
, 0, 'V' },
28 static Polyhedron
*Polyhedron_Read()
31 unsigned NbRows
, NbColumns
;
36 while (fgets(s
, sizeof(s
), stdin
)) {
39 if (strncasecmp(s
, "vertices", sizeof("vertices")-1) == 0)
41 if (sscanf(s
, "%u %u", &NbRows
, &NbColumns
) == 2)
46 M
= Matrix_Alloc(NbRows
,NbColumns
);
49 P
= Rays2Polyhedron(M
, MAXRAYS
);
51 P
= Constraints2Polyhedron(M
, MAXRAYS
);
56 static void scan_poly(Polyhedron
*S
, int pos
, Value
*z
, Matrix
*T
)
62 v
= Vector_Alloc(T
->NbRows
);
63 Matrix_Vector_Product(T
, z
+1, v
->p
);
64 value_print(stdout
, VALUE_FMT
, v
->p
[0]);
65 for (k
=1; k
< pos
; ++k
) {
67 value_print(stdout
,VALUE_FMT
, v
->p
[k
]);
77 ok
= !(lower_upper_bounds(1+pos
, S
, z
, &LB
, &UB
));
79 for (value_assign(tmp
,LB
); value_le(tmp
,UB
); value_increment(tmp
,tmp
)) {
80 value_assign(z
[pos
+1], tmp
);
81 scan_poly(S
->next
, pos
+1, z
, T
);
83 value_set_si(z
[pos
+1], 0);
90 int main(int argc
, char **argv
)
92 Polyhedron
*A
, *P
, *U
, *S
;
95 Matrix
*basis
, *T
, *inv
;
99 while ((c
= getopt_long(argc
, argv
, "dV", options
, &ind
)) != -1) {
105 printf(barvinok_version());
111 A
= Polyhedron_Read();
114 inv
= Identity(A
->Dimension
+1);
117 basis
= reduced_basis(A
);
119 T
= Matrix_Alloc(A
->Dimension
+1, A
->Dimension
+1);
120 inv
= Matrix_Alloc(A
->Dimension
+1, A
->Dimension
+1);
121 for (i
= 0; i
< A
->Dimension
; ++i
)
122 for (j
= 0; j
< A
->Dimension
; ++j
)
123 value_assign(T
->p
[i
][j
], basis
->p
[i
][j
]);
124 value_set_si(T
->p
[A
->Dimension
][A
->Dimension
], 1);
127 ok
= Matrix_Inverse(T
, inv
);
131 P
= Polyhedron_Preimage(A
, inv
, MAXRAYS
);
135 U
= Universe_Polyhedron(0);
136 S
= Polyhedron_Scan(P
, U
, MAXRAYS
);
138 p
= ALLOCN(Value
, P
->Dimension
+2);
139 for(i
=0;i
<=P
->Dimension
;i
++) {
141 value_set_si(p
[i
],0);
144 value_set_si(p
[i
],1);
146 scan_poly(S
, 0, p
, inv
);
149 for(i
=0;i
<=(P
->Dimension
+1);i
++)