5 #include <barvinok/util.h>
6 #include <barvinok/barvinok.h>
7 #include <barvinok/sample.h>
9 #include "evalue_read.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
)
38 int i
, nbPol
, nbVec
, nbMat
, func
, j
, n
;
39 Polyhedron
*A
, *B
, *C
, *D
, *E
, *F
, *G
;
41 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
43 argc
= barvinok_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
45 nbPol
= nbVec
= nbMat
= 0;
48 ((sscanf(s
, "D %d", &nbPol
) < 1) &&
49 (sscanf(s
, "V %d", &nbVec
) < 1) &&
50 (sscanf(s
, "M %d", &nbMat
) < 1)))
53 for (i
= 0; i
< nbPol
; ++i
) {
54 Matrix
*M
= Matrix_Read();
55 A
= Constraints2Polyhedron(M
, options
->MaxRays
);
58 while ((*s
=='#') || (sscanf(s
, "F %d", &func
)<1))
67 /* workaround for apparent bug in older gmps */
68 *strchr(s
, '\n') = '\0';
69 while ((*s
=='#') || (value_read(ck
, s
) != 0)) {
71 /* workaround for apparent bug in older gmps */
72 *strchr(s
, '\n') = '\0';
74 barvinok_count_with_options(A
, &cb
, options
);
82 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
83 B
= Polyhedron_Polar(A
, options
->MaxRays
);
84 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
85 C
= Polyhedron_Polar(B
, options
->MaxRays
);
86 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
91 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
92 for (j
= 0; j
< A
->NbRays
; ++j
) {
93 B
= supporting_cone(A
, j
);
94 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
99 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
101 barvinok_decompose(A
,&B
,&C
);
103 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
105 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
111 struct tms tms_before
, tms_between
, tms_after
;
114 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
116 manual_count(A
, &cm
);
118 barvinok_count(A
, &cb
, 100);
121 value_print(stdout
, P_VALUE_FMT
, cm
);
123 time_diff(&tms_before
, &tms_between
);
124 printf("Barvinok: ");
125 value_print(stdout
, P_VALUE_FMT
, cb
);
127 time_diff(&tms_between
, &tms_after
);
133 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
134 B
= triangulate_cone(A
, 100);
135 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
136 check_triangulization(A
, B
);
140 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
141 B
= remove_equalities(A
, options
->MaxRays
);
142 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
147 Matrix
*M
= Matrix_Read();
148 const char **param_name
;
149 C
= Constraints2Polyhedron(M
, options
->MaxRays
);
151 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
152 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
153 EP
= barvinok_enumerate_with_options(A
, C
, options
);
154 param_name
= Read_ParamNames(stdin
, C
->Dimension
);
155 print_evalue(stdout
, EP
, (const char**)param_name
);
160 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
161 Polyhedron_Polarize(A
);
163 barvinok_decompose(A
,&B
,&C
);
164 for (D
= B
; D
; D
= D
->next
)
165 Polyhedron_Polarize(D
);
166 for (D
= C
; D
; D
= D
->next
)
167 Polyhedron_Polarize(D
);
169 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
171 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
181 fgets(s
, 128, stdin
);
183 for (j
= 0; j
< n
; ++j
) {
186 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
188 A
= DomainConcat(P
, A
);
190 fgets(s
, 128, stdin
);
191 /* workaround for apparent bug in older gmps */
192 *strchr(s
, '\n') = '\0';
193 while ((*s
=='#') || (value_read(ck
, s
) != 0)) {
194 fgets(s
, 128, stdin
);
195 /* workaround for apparent bug in older gmps */
196 *strchr(s
, '\n') = '\0';
198 C
= Universe_Polyhedron(0);
199 EP
= barvinok_enumerate_union(A
, C
, options
->MaxRays
);
200 value_set_double(cb
, compute_evalue(EP
, &ck
)+.25);
201 if (value_ne(cb
, ck
))
210 evalue
*expected
, *computed
;
211 unsigned nvar
, nparam
;
214 expected
= evalue_read_from_file(stdin
, NULL
, &pp
, &nvar
, &nparam
,
216 C
= Universe_Polyhedron(0);
217 computed
= Polyhedron_Lattice_Width(A
, C
, options
);
218 assert(value_zero_p(computed
->d
));
219 assert(computed
->x
.p
->type
== partition
);
220 if (!eequal(expected
, &computed
->x
.p
->arr
[1]))
224 evalue_free(computed
);
225 evalue_free(expected
);
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
);
270 barvinok_options_free(options
);