5 #include <barvinok/util.h>
6 #include <barvinok/barvinok.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
)
37 int i
, nbPol
, nbVec
, nbMat
, func
, j
, n
;
38 Polyhedron
*A
, *B
, *C
, *D
, *E
, *F
, *G
;
40 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
42 set_program_name(argv
[0]);
43 argp_parse(&barvinok_argp
, argc
, argv
, 0, 0, options
);
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();
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
, param_name
);
156 free_evalue_refs(EP
);
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
))
207 free_evalue_refs(EP
);
213 for (i
= 0; i
< nbVec
; ++i
) {
215 Vector
*V
= Vector_Read();
216 Matrix
*M
= Matrix_Alloc(V
->Size
, V
->Size
);
217 Vector_Copy(V
->p
, M
->p
[0], V
->Size
);
218 ok
= unimodular_complete(M
, 1);
220 Matrix_Print(stdout
, P_VALUE_FMT
, M
);
224 for (i
= 0; i
< nbMat
; ++i
) {
226 Matrix
*M
= Matrix_Read();
227 Smith(M
, &U
, &V
, &S
);
228 Matrix_Print(stdout
, P_VALUE_FMT
, U
);
229 Matrix_Print(stdout
, P_VALUE_FMT
, V
);
230 Matrix_Print(stdout
, P_VALUE_FMT
, S
);
237 barvinok_options_free(options
);