5 #include <isl_set_polylib.h>
6 #include <barvinok/util.h>
7 #include <barvinok/barvinok.h>
8 #include <barvinok/sample.h>
11 #ifdef HAVE_SYS_TIMES_H
13 #include <sys/times.h>
15 static void time_diff(struct tms
*before
, struct tms
*after
)
17 long ticks
= sysconf(_SC_CLK_TCK
);
18 printf("User: %g; Sys: %g\n",
19 (0.0 + after
->tms_utime
- before
->tms_utime
) / ticks
,
20 (0.0 + after
->tms_stime
- before
->tms_stime
) / ticks
);
26 static void times(struct tms
* time
)
29 static void time_diff(struct tms
*before
, struct tms
*after
)
35 int main(int argc
, char **argv
)
38 int i
, nbPol
, nbVec
, nbMat
, func
, j
, n
;
39 Polyhedron
*A
, *B
, *C
, *D
;
41 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
43 argc
= barvinok_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
44 ctx
= isl_ctx_alloc_with_options(&barvinok_options_args
, options
);
46 nbPol
= nbVec
= nbMat
= 0;
49 ((sscanf(s
, "D %d", &nbPol
) < 1) &&
50 (sscanf(s
, "V %d", &nbVec
) < 1) &&
51 (sscanf(s
, "M %d", &nbMat
) < 1)))
54 for (i
= 0; i
< nbPol
; ++i
) {
55 Matrix
*M
= Matrix_Read();
56 A
= Constraints2Polyhedron(M
, options
->MaxRays
);
59 while ((*s
=='#') || (sscanf(s
, "F %d", &func
)<1))
68 /* workaround for apparent bug in older gmps */
69 *strchr(s
, '\n') = '\0';
70 while ((*s
=='#') || (value_read(ck
, s
) != 0)) {
72 /* workaround for apparent bug in older gmps */
73 *strchr(s
, '\n') = '\0';
75 barvinok_count_with_options(A
, &cb
, options
);
83 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
84 B
= Polyhedron_Polar(A
, options
->MaxRays
);
85 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
86 C
= Polyhedron_Polar(B
, options
->MaxRays
);
87 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
92 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
93 for (j
= 0; j
< A
->NbRays
; ++j
) {
94 B
= supporting_cone(A
, j
);
95 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
100 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
102 barvinok_decompose(A
,&B
,&C
);
104 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
106 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
112 struct tms tms_before
, tms_between
, tms_after
;
115 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
117 manual_count(A
, &cm
);
119 barvinok_count(A
, &cb
, 100);
122 value_print(stdout
, P_VALUE_FMT
, cm
);
124 time_diff(&tms_before
, &tms_between
);
125 printf("Barvinok: ");
126 value_print(stdout
, P_VALUE_FMT
, cb
);
128 time_diff(&tms_between
, &tms_after
);
134 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
135 B
= triangulate_cone(A
, 100);
136 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
137 check_triangulization(A
, B
);
141 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
142 B
= remove_equalities(A
, options
->MaxRays
);
143 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
148 Matrix
*M
= Matrix_Read();
149 const char **param_name
;
150 C
= Constraints2Polyhedron(M
, options
->MaxRays
);
152 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
153 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
154 EP
= barvinok_enumerate_with_options(A
, C
, options
);
155 param_name
= Read_ParamNames(stdin
, C
->Dimension
);
156 print_evalue(stdout
, EP
, (const char**)param_name
);
161 Polyhedron_Print(stdout
, P_VALUE_FMT
, A
);
162 Polyhedron_Polarize(A
);
164 barvinok_decompose(A
,&B
,&C
);
165 for (D
= B
; D
; D
= D
->next
)
166 Polyhedron_Polarize(D
);
167 for (D
= C
; D
; D
= D
->next
)
168 Polyhedron_Polarize(D
);
170 Polyhedron_Print(stdout
, P_VALUE_FMT
, B
);
172 Polyhedron_Print(stdout
, P_VALUE_FMT
, C
);
182 fgets(s
, 128, stdin
);
184 for (j
= 0; j
< n
; ++j
) {
187 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
189 A
= DomainConcat(P
, A
);
191 fgets(s
, 128, stdin
);
192 /* workaround for apparent bug in older gmps */
193 *strchr(s
, '\n') = '\0';
194 while ((*s
=='#') || (value_read(ck
, s
) != 0)) {
195 fgets(s
, 128, stdin
);
196 /* workaround for apparent bug in older gmps */
197 *strchr(s
, '\n') = '\0';
199 C
= Universe_Polyhedron(0);
200 EP
= barvinok_enumerate_union(A
, C
, options
->MaxRays
);
201 value_set_double(cb
, compute_evalue(EP
, &ck
)+.25);
202 if (value_ne(cb
, ck
))
213 fgets(s
, 128, stdin
);
214 sscanf(s
, "%d", &has_sample
);
216 sample
= Polyhedron_Sample(A
, options
);
217 if (!sample
&& has_sample
)
219 if (sample
&& !has_sample
)
221 if (sample
&& !in_domain(A
, sample
->p
))
228 for (i
= 0; i
< nbVec
; ++i
) {
230 Vector
*V
= Vector_Read();
231 Matrix
*M
= Matrix_Alloc(V
->Size
, V
->Size
);
232 Vector_Copy(V
->p
, M
->p
[0], V
->Size
);
233 ok
= unimodular_complete(M
, 1);
235 Matrix_Print(stdout
, P_VALUE_FMT
, M
);
239 for (i
= 0; i
< nbMat
; ++i
) {
241 Matrix
*M
= Matrix_Read();
242 Smith(M
, &U
, &V
, &S
);
243 Matrix_Print(stdout
, P_VALUE_FMT
, U
);
244 Matrix_Print(stdout
, P_VALUE_FMT
, V
);
245 Matrix_Print(stdout
, P_VALUE_FMT
, S
);