5 #include <isl_set_polylib.h>
6 #include <barvinok/util.h>
7 #include <barvinok/barvinok.h>
8 #include <barvinok/sample.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
)
40 int i
, nbPol
, nbVec
, nbMat
, func
, j
, n
;
41 Polyhedron
*A
, *B
, *C
, *D
, *E
, *F
, *G
;
43 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
45 argc
= barvinok_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
46 ctx
= isl_ctx_alloc_with_options(&barvinok_options_args
, options
);
48 nbPol
= nbVec
= nbMat
= 0;
51 ((sscanf(s
, "D %d", &nbPol
) < 1) &&
52 (sscanf(s
, "V %d", &nbVec
) < 1) &&
53 (sscanf(s
, "M %d", &nbMat
) < 1)))
56 for (i
= 0; i
< nbPol
; ++i
) {
57 Matrix
*M
= Matrix_Read();
58 A
= Constraints2Polyhedron(M
, options
->MaxRays
);
61 while ((*s
=='#') || (sscanf(s
, "F %d", &func
)<1))
70 /* workaround for apparent bug in older gmps */
71 *strchr(s
, '\n') = '\0';
72 while ((*s
=='#') || (value_read(ck
, s
) != 0)) {
74 /* workaround for apparent bug in older gmps */
75 *strchr(s
, '\n') = '\0';
77 barvinok_count_with_options(A
, &cb
, options
);
85 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
86 B
= Polyhedron_Polar(A
, options
->MaxRays
);
87 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
88 C
= Polyhedron_Polar(B
, options
->MaxRays
);
89 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
94 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
95 for (j
= 0; j
< A
->NbRays
; ++j
) {
96 B
= supporting_cone(A
, j
);
97 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
102 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
104 barvinok_decompose(A
,&B
,&C
);
106 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
108 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
114 struct tms tms_before
, tms_between
, tms_after
;
117 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
119 manual_count(A
, &cm
);
121 barvinok_count(A
, &cb
, 100);
124 value_print(stdout
, P_VALUE_FMT
, cm
);
126 time_diff(&tms_before
, &tms_between
);
127 printf("Barvinok: ");
128 value_print(stdout
, P_VALUE_FMT
, cb
);
130 time_diff(&tms_between
, &tms_after
);
136 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
137 B
= triangulate_cone(A
, 100);
138 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
139 check_triangulization(A
, B
);
143 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
144 B
= remove_equalities(A
, options
->MaxRays
);
145 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
150 Matrix
*M
= Matrix_Read();
151 const char **param_name
;
152 C
= Constraints2Polyhedron(M
, options
->MaxRays
);
154 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
155 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
156 EP
= barvinok_enumerate_with_options(A
, C
, options
);
157 param_name
= Read_ParamNames(stdin
, C
->Dimension
);
158 print_evalue(stdout
, EP
, (const char**)param_name
);
163 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
164 Polyhedron_Polarize(A
);
166 barvinok_decompose(A
,&B
,&C
);
167 for (D
= B
; D
; D
= D
->next
)
168 Polyhedron_Polarize(D
);
169 for (D
= C
; D
; D
= D
->next
)
170 Polyhedron_Polarize(D
);
172 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
174 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
184 fgets(s
, 128, stdin
);
186 for (j
= 0; j
< n
; ++j
) {
189 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
191 A
= DomainConcat(P
, A
);
193 fgets(s
, 128, stdin
);
194 /* workaround for apparent bug in older gmps */
195 *strchr(s
, '\n') = '\0';
196 while ((*s
=='#') || (value_read(ck
, s
) != 0)) {
197 fgets(s
, 128, stdin
);
198 /* workaround for apparent bug in older gmps */
199 *strchr(s
, '\n') = '\0';
201 C
= Universe_Polyhedron(0);
202 EP
= barvinok_enumerate_union(A
, C
, options
->MaxRays
);
203 value_set_double(cb
, compute_evalue(EP
, &ck
)+.25);
204 if (value_ne(cb
, ck
))
215 isl_pw_qpolynomial
*expected
, *computed
;
218 expected
= isl_pw_qpolynomial_read_from_file(ctx
, stdin
);
219 nparam
= isl_pw_qpolynomial_dim(expected
, isl_dim_param
);
220 dim
= isl_space_set_alloc(ctx
, nparam
, A
->Dimension
- nparam
);
221 bset
= isl_basic_set_new_from_polylib(A
, dim
);
222 computed
= isl_basic_set_lattice_width(bset
);
223 computed
= isl_pw_qpolynomial_sub(computed
, expected
);
224 if (!isl_pw_qpolynomial_is_zero(computed
))
226 isl_pw_qpolynomial_free(computed
);
232 fgets(s
, 128, stdin
);
233 sscanf(s
, "%d", &has_sample
);
235 sample
= Polyhedron_Sample(A
, options
);
236 if (!sample
&& has_sample
)
238 if (sample
&& !has_sample
)
240 if (sample
&& !in_domain(A
, sample
->p
))
247 for (i
= 0; i
< nbVec
; ++i
) {
249 Vector
*V
= Vector_Read();
250 Matrix
*M
= Matrix_Alloc(V
->Size
, V
->Size
);
251 Vector_Copy(V
->p
, M
->p
[0], V
->Size
);
252 ok
= unimodular_complete(M
, 1);
254 Matrix_Print(stdout
, P_VALUE_FMT
, M
);
258 for (i
= 0; i
< nbMat
; ++i
) {
260 Matrix
*M
= Matrix_Read();
261 Smith(M
, &U
, &V
, &S
);
262 Matrix_Print(stdout
, P_VALUE_FMT
, U
);
263 Matrix_Print(stdout
, P_VALUE_FMT
, V
);
264 Matrix_Print(stdout
, P_VALUE_FMT
, S
);