5 #include <isl_set_polylib.h>
6 #include <barvinok/util.h>
7 #include <barvinok/barvinok.h>
8 #include <barvinok/sample.h>
10 #include "lattice_width.h"
12 #ifdef HAVE_SYS_TIMES_H
14 #include <sys/times.h>
16 static void time_diff(struct tms
*before
, struct tms
*after
)
18 long ticks
= sysconf(_SC_CLK_TCK
);
19 printf("User: %g; Sys: %g\n",
20 (0.0 + after
->tms_utime
- before
->tms_utime
) / ticks
,
21 (0.0 + after
->tms_stime
- before
->tms_stime
) / ticks
);
27 static void times(struct tms
* time
)
30 static void time_diff(struct tms
*before
, struct tms
*after
)
36 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 argc
= barvinok_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
45 ctx
= isl_ctx_alloc_with_options(&barvinok_options_args
, 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();
150 const char **param_name
;
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
))
214 isl_pw_qpolynomial
*expected
, *computed
;
217 expected
= isl_pw_qpolynomial_read_from_file(ctx
, stdin
);
218 nparam
= isl_pw_qpolynomial_dim(expected
, isl_dim_param
);
219 dim
= isl_space_set_alloc(ctx
, nparam
, A
->Dimension
- nparam
);
220 bset
= isl_basic_set_new_from_polylib(A
, dim
);
221 computed
= isl_basic_set_lattice_width(bset
);
222 computed
= isl_pw_qpolynomial_sub(computed
, expected
);
223 if (!isl_pw_qpolynomial_is_zero(computed
))
225 isl_pw_qpolynomial_free(computed
);
231 fgets(s
, 128, stdin
);
232 sscanf(s
, "%d", &has_sample
);
234 sample
= Polyhedron_Sample(A
, options
);
235 if (!sample
&& has_sample
)
237 if (sample
&& !has_sample
)
239 if (sample
&& !in_domain(A
, sample
->p
))
246 for (i
= 0; i
< nbVec
; ++i
) {
248 Vector
*V
= Vector_Read();
249 Matrix
*M
= Matrix_Alloc(V
->Size
, V
->Size
);
250 Vector_Copy(V
->p
, M
->p
[0], V
->Size
);
251 ok
= unimodular_complete(M
, 1);
253 Matrix_Print(stdout
, P_VALUE_FMT
, M
);
257 for (i
= 0; i
< nbMat
; ++i
) {
259 Matrix
*M
= Matrix_Read();
260 Smith(M
, &U
, &V
, &S
);
261 Matrix_Print(stdout
, P_VALUE_FMT
, U
);
262 Matrix_Print(stdout
, P_VALUE_FMT
, V
);
263 Matrix_Print(stdout
, P_VALUE_FMT
, S
);