5 #include <barvinok/util.h>
6 #include <barvinok/barvinok.h>
7 #include <barvinok/sample.h>
11 #include "evalue_read.h"
12 #include "lattice_width.h"
14 #ifdef HAVE_SYS_TIMES_H
16 #include <sys/times.h>
18 static void time_diff(struct tms
*before
, struct tms
*after
)
20 long ticks
= sysconf(_SC_CLK_TCK
);
21 printf("User: %g; Sys: %g\n",
22 (0.0 + after
->tms_utime
- before
->tms_utime
) / ticks
,
23 (0.0 + after
->tms_stime
- before
->tms_stime
) / ticks
);
29 static void times(struct tms
* time
)
32 static void time_diff(struct tms
*before
, struct tms
*after
)
38 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 set_program_name(argv
[0]);
46 argp_parse(&barvinok_argp
, argc
, argv
, 0, 0, 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
))
213 evalue
*expected
, *computed
;
214 unsigned nvar
, nparam
;
217 expected
= evalue_read_from_file(stdin
, NULL
, &pp
, &nvar
, &nparam
,
219 C
= Universe_Polyhedron(0);
220 computed
= Polyhedron_Lattice_Width(A
, C
, options
);
221 assert(value_zero_p(computed
->d
));
222 assert(computed
->x
.p
->type
== partition
);
223 if (!eequal(expected
, &computed
->x
.p
->arr
[1]))
227 evalue_free(computed
);
228 evalue_free(expected
);
234 fgets(s
, 128, stdin
);
235 sscanf(s
, "%d", &has_sample
);
237 sample
= Polyhedron_Sample(A
, options
);
238 if (!sample
&& has_sample
)
240 if (sample
&& !has_sample
)
242 if (sample
&& !in_domain(A
, sample
->p
))
249 for (i
= 0; i
< nbVec
; ++i
) {
251 Vector
*V
= Vector_Read();
252 Matrix
*M
= Matrix_Alloc(V
->Size
, V
->Size
);
253 Vector_Copy(V
->p
, M
->p
[0], V
->Size
);
254 ok
= unimodular_complete(M
, 1);
256 Matrix_Print(stdout
, P_VALUE_FMT
, M
);
260 for (i
= 0; i
< nbMat
; ++i
) {
262 Matrix
*M
= Matrix_Read();
263 Smith(M
, &U
, &V
, &S
);
264 Matrix_Print(stdout
, P_VALUE_FMT
, U
);
265 Matrix_Print(stdout
, P_VALUE_FMT
, V
);
266 Matrix_Print(stdout
, P_VALUE_FMT
, S
);
273 barvinok_options_free(options
);