5 #include <barvinok/util.h>
6 #include <barvinok/barvinok.h>
10 #include "evalue_read.h"
11 #include "lattice_width.h"
13 #ifdef HAVE_SYS_TIMES_H
15 #include <sys/times.h>
17 static void time_diff(struct tms
*before
, struct tms
*after
)
19 long ticks
= sysconf(_SC_CLK_TCK
);
20 printf("User: %g; Sys: %g\n",
21 (0.0 + after
->tms_utime
- before
->tms_utime
) / ticks
,
22 (0.0 + after
->tms_stime
- before
->tms_stime
) / ticks
);
28 static void times(struct tms
* time
)
31 static void time_diff(struct tms
*before
, struct tms
*after
)
37 int main(int argc
, char **argv
)
39 int i
, nbPol
, nbVec
, nbMat
, func
, j
, n
;
40 Polyhedron
*A
, *B
, *C
, *D
, *E
, *F
, *G
;
42 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
44 set_program_name(argv
[0]);
45 argp_parse(&barvinok_argp
, argc
, argv
, 0, 0, options
);
47 nbPol
= nbVec
= nbMat
= 0;
50 ((sscanf(s
, "D %d", &nbPol
) < 1) &&
51 (sscanf(s
, "V %d", &nbVec
) < 1) &&
52 (sscanf(s
, "M %d", &nbMat
) < 1)))
55 for (i
= 0; i
< nbPol
; ++i
) {
56 Matrix
*M
= Matrix_Read();
57 A
= Constraints2Polyhedron(M
, options
->MaxRays
);
60 while ((*s
=='#') || (sscanf(s
, "F %d", &func
)<1))
69 /* workaround for apparent bug in older gmps */
70 *strchr(s
, '\n') = '\0';
71 while ((*s
=='#') || (value_read(ck
, s
) != 0)) {
73 /* workaround for apparent bug in older gmps */
74 *strchr(s
, '\n') = '\0';
76 barvinok_count_with_options(A
, &cb
, options
);
84 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
85 B
= Polyhedron_Polar(A
, options
->MaxRays
);
86 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
87 C
= Polyhedron_Polar(B
, options
->MaxRays
);
88 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
93 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
94 for (j
= 0; j
< A
->NbRays
; ++j
) {
95 B
= supporting_cone(A
, j
);
96 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
101 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
103 barvinok_decompose(A
,&B
,&C
);
105 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
107 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
113 struct tms tms_before
, tms_between
, tms_after
;
116 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
118 manual_count(A
, &cm
);
120 barvinok_count(A
, &cb
, 100);
123 value_print(stdout
, P_VALUE_FMT
, cm
);
125 time_diff(&tms_before
, &tms_between
);
126 printf("Barvinok: ");
127 value_print(stdout
, P_VALUE_FMT
, cb
);
129 time_diff(&tms_between
, &tms_after
);
135 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
136 B
= triangulate_cone(A
, 100);
137 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
138 check_triangulization(A
, B
);
142 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
143 B
= remove_equalities(A
, options
->MaxRays
);
144 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
149 Matrix
*M
= Matrix_Read();
151 C
= Constraints2Polyhedron(M
, options
->MaxRays
);
153 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
154 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
155 EP
= barvinok_enumerate_with_options(A
, C
, options
);
156 param_name
= Read_ParamNames(stdin
, C
->Dimension
);
157 print_evalue(stdout
, EP
, (const char**)param_name
);
162 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
163 Polyhedron_Polarize(A
);
165 barvinok_decompose(A
,&B
,&C
);
166 for (D
= B
; D
; D
= D
->next
)
167 Polyhedron_Polarize(D
);
168 for (D
= C
; D
; D
= D
->next
)
169 Polyhedron_Polarize(D
);
171 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
173 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
183 fgets(s
, 128, stdin
);
185 for (j
= 0; j
< n
; ++j
) {
188 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
190 A
= DomainConcat(P
, A
);
192 fgets(s
, 128, stdin
);
193 /* workaround for apparent bug in older gmps */
194 *strchr(s
, '\n') = '\0';
195 while ((*s
=='#') || (value_read(ck
, s
) != 0)) {
196 fgets(s
, 128, stdin
);
197 /* workaround for apparent bug in older gmps */
198 *strchr(s
, '\n') = '\0';
200 C
= Universe_Polyhedron(0);
201 EP
= barvinok_enumerate_union(A
, C
, options
->MaxRays
);
202 value_set_double(cb
, compute_evalue(EP
, &ck
)+.25);
203 if (value_ne(cb
, ck
))
212 evalue
*expected
, *computed
;
213 unsigned nvar
, nparam
;
216 expected
= evalue_read_from_file(stdin
, NULL
, &pp
, &nvar
, &nparam
,
218 C
= Universe_Polyhedron(0);
219 computed
= Polyhedron_Lattice_Width(A
, C
, options
);
220 assert(value_zero_p(computed
->d
));
221 assert(computed
->x
.p
->type
== partition
);
222 if (!eequal(expected
, &computed
->x
.p
->arr
[1]))
226 evalue_free(computed
);
227 evalue_free(expected
);
233 for (i
= 0; i
< nbVec
; ++i
) {
235 Vector
*V
= Vector_Read();
236 Matrix
*M
= Matrix_Alloc(V
->Size
, V
->Size
);
237 Vector_Copy(V
->p
, M
->p
[0], V
->Size
);
238 ok
= unimodular_complete(M
, 1);
240 Matrix_Print(stdout
, P_VALUE_FMT
, M
);
244 for (i
= 0; i
< nbMat
; ++i
) {
246 Matrix
*M
= Matrix_Read();
247 Smith(M
, &U
, &V
, &S
);
248 Matrix_Print(stdout
, P_VALUE_FMT
, U
);
249 Matrix_Print(stdout
, P_VALUE_FMT
, V
);
250 Matrix_Print(stdout
, P_VALUE_FMT
, S
);
257 barvinok_options_free(options
);