3 #include <barvinok/barvinok.h>
4 #include <barvinok/set.h>
5 #include <barvinok/options.h>
6 #include <barvinok/evalue.h>
7 #include <barvinok/util.h>
8 #include "conversion.h"
9 #include "evalue_read.h"
11 #include "lattice_point.h"
13 #include "bernoulli.h"
18 #include "matrix_read.h"
19 #include "remove_equalities.h"
27 void set_from_string(T
& v
, const char *s
)
29 std::istringstream
str(s
);
33 static Matrix
*matrix_read_from_str(const char *s
)
35 std::istringstream
str(s
);
36 return Matrix_Read(str
);
39 static int test_equalities(struct barvinok_options
*options
)
41 Matrix
*M
= matrix_read_from_str(
43 " 0 23 0 0 -10 0 0 0 7 -44 -8 \n"
44 " 0 0 23 0 5 0 0 0 -15 114 27 \n"
45 " 0 0 0 1 0 0 0 0 0 -1 2 \n"
46 " 0 0 0 0 0 1 0 0 -1 8 0 \n"
47 " 0 0 0 0 0 0 1 0 0 -1 2 \n"
48 " 0 0 0 0 0 0 0 1 0 -1 -1 \n"
49 " 1 0 0 0 10 0 0 0 -7 44 8 \n"
50 " 1 0 0 0 -5 0 0 0 15 -114 -27 \n"
51 " 1 0 0 0 1 0 0 0 0 0 0 \n"
52 " 1 0 0 0 0 0 0 0 1 -8 0 \n"
53 " 1 0 0 0 0 0 0 0 0 1 -2 \n");
54 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
57 remove_all_equalities(&P
, NULL
, NULL
, NULL
, 2, options
->MaxRays
);
65 int test_evalue_read(struct barvinok_options
*options
)
67 unsigned nvar
, nparam
;
68 const char **all_vars
;
71 e1
= evalue_read_from_str("(1 * aa + 2 * a)",
72 NULL
, &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
73 Free_ParamNames(all_vars
, nvar
+nparam
);
74 e2
= evalue_read_from_str("(3 * aa)",
75 NULL
, &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
76 Free_ParamNames(all_vars
, nvar
+nparam
);
77 assert(!eequal(e1
, e2
));
83 static void evalue_check_disjoint(evalue
*e
)
89 if (EVALUE_IS_ZERO(*e
))
91 for (i
= 0; i
< e
->x
.p
->size
/2; ++i
) {
92 Polyhedron
*A
= EVALUE_DOMAIN(e
->x
.p
->arr
[2*i
]);
93 for (j
= i
+1; j
< e
->x
.p
->size
/2; ++j
) {
94 Polyhedron
*B
= EVALUE_DOMAIN(e
->x
.p
->arr
[2*j
]);
95 Polyhedron
*I
= DomainIntersection(A
, B
, 0);
102 static int test_eadd(struct barvinok_options
*options
)
104 unsigned nvar
, nparam
;
105 const char **all_vars
;
108 e1
= evalue_read_from_str(" d -1 = 0\n"
113 "d,h", &all_vars
, &nvar
, &nparam
,
115 Free_ParamNames(all_vars
, nvar
+nparam
);
116 e2
= evalue_read_from_str(
128 "d,h", &all_vars
, &nvar
, &nparam
,
130 Free_ParamNames(all_vars
, nvar
+nparam
);
132 evalue_check_disjoint(e1
);
138 int test_evalue(struct barvinok_options
*options
)
140 unsigned nvar
, nparam
;
141 const char **all_vars
;
142 evalue
*poly1
, poly2
;
144 poly1
= evalue_read_from_str("(1/4 * n^4 + 1/2 * n^3 + 1/4 * n^2)",
145 NULL
, &all_vars
, &nvar
, &nparam
,
147 Free_ParamNames(all_vars
, nvar
+nparam
);
150 evalue_copy(&poly2
, poly1
);
151 evalue_negate(poly1
);
153 reduce_evalue(poly1
);
154 assert(EVALUE_IS_ZERO(*poly1
));
156 free_evalue_refs(&poly2
);
160 int test_substitute(struct barvinok_options
*options
)
162 unsigned nvar
, nparam
;
163 const char **all_vars
;
164 const char *vars
= "a,b";
168 e1
= evalue_read_from_str("[ { 1/3 * a } = 0 ] * \n"
169 " ([ { 1/5 * b + 2/5 } = 0 ] * 5) + \n"
170 "[ { 1/3 * a } != 0 ] * 42",
171 vars
, &all_vars
, &nvar
, &nparam
,
173 Free_ParamNames(all_vars
, nvar
+nparam
);
175 subs
[0] = evalue_read_from_str("(2 * b + 5)",
176 vars
, &all_vars
, &nvar
, &nparam
,
178 Free_ParamNames(all_vars
, nvar
+nparam
);
179 subs
[1] = evalue_read_from_str("(a + 1)",
180 vars
, &all_vars
, &nvar
, &nparam
,
182 Free_ParamNames(all_vars
, nvar
+nparam
);
184 evalue_substitute(e1
, subs
);
185 evalue_free(subs
[0]);
186 evalue_free(subs
[1]);
189 e2
= evalue_read_from_str("[ { 2/3 * b + 2/3 } = 0 ] * \n"
190 " ([ { 1/5 * a + 3/5 } = 0 ] * 5) + \n"
191 "[ { 2/3 * b + 2/3 } != 0 ] * 42",
192 vars
, &all_vars
, &nvar
, &nparam
,
194 Free_ParamNames(all_vars
, nvar
+nparam
);
197 assert(eequal(e1
, e2
));
204 int test_split_periods(struct barvinok_options
*options
)
206 unsigned nvar
, nparam
;
207 const char **all_vars
;
210 e
= evalue_read_from_str("U + 2V + 3 >= 0\n- U -2V >= 0\n- U 10 >= 0\n"
211 "U >= 0\n\n({( 1/3 * U + ( 2/3 * V + 0 ))})",
212 NULL
, &all_vars
, &nvar
, &nparam
,
214 Free_ParamNames(all_vars
, nvar
+nparam
);
216 evalue_split_periods(e
, 2, options
->MaxRays
);
217 assert(value_zero_p(e
->d
));
218 assert(e
->x
.p
->type
== partition
);
219 assert(e
->x
.p
->size
== 4);
220 assert(value_zero_p(e
->x
.p
->arr
[1].d
));
221 assert(e
->x
.p
->arr
[1].x
.p
->type
== polynomial
);
222 assert(value_zero_p(e
->x
.p
->arr
[3].d
));
223 assert(e
->x
.p
->arr
[3].x
.p
->type
== polynomial
);
228 int test_specialization(struct barvinok_options
*options
)
237 assert(value_cmp_si(n
.coeff
->p
[0], 1) == 0);
238 assert(value_cmp_si(n
.coeff
->p
[1], 5) == 0);
239 assert(value_cmp_si(n
.coeff
->p
[2], 10) == 0);
246 assert(value_cmp_si(d
.coeff
->p
[0], 2) == 0);
247 assert(value_cmp_si(d
.coeff
->p
[1], 1) == 0);
248 assert(value_cmp_si(d
.coeff
->p
[2], 0) == 0);
251 mpq_canonicalize(count
);
252 assert(value_cmp_si(mpq_numref(count
), 31) == 0);
253 assert(value_cmp_si(mpq_denref(count
), 8) == 0);
257 assert(value_cmp_si(n2
.coeff
->p
[0], 1) == 0);
258 assert(value_cmp_si(n2
.coeff
->p
[1], -2) == 0);
259 assert(value_cmp_si(n2
.coeff
->p
[2], 3) == 0);
262 mpq_canonicalize(count
);
263 assert(value_cmp_si(mpq_numref(count
), 6) == 0);
264 assert(value_cmp_si(mpq_denref(count
), 1) == 0);
271 int test_lattice_points(struct barvinok_options
*options
)
275 set_from_string(tmp
, "[[0 0 0 0 4][0 0 0 0 4][-1 0 1 0 4]]");
276 V
.Vertex
= zz2matrix(tmp
);
278 set_from_string(lambda
, "[3 5 7]");
280 set_from_string(rays
, "[[0 1 0][4 0 1][0 0 -1]]");
284 unsigned nvar
, nparam
;
285 const char **all_vars
;
286 point
[0] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
287 "( 7 * {( 1/4 * a + ( 3/4 * c + 3/4 ) ) } + -21/4 ) ) )",
288 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
289 Free_ParamNames(all_vars
, nvar
+nparam
);
290 point
[1] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
291 "( 7 * {( 1/4 * a + ( 3/4 * c + 1/2 ) ) } + -1/2 ) ) )",
292 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
293 Free_ParamNames(all_vars
, nvar
+nparam
);
294 point
[2] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
295 "( 7 * {( 1/4 * a + ( 3/4 * c + 1/4 ) ) } + 17/4 ) ) )",
296 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
297 Free_ParamNames(all_vars
, nvar
+nparam
);
298 point
[3] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
299 "( 7 * {( 1/4 * a + ( 3/4 * c + 0 ) ) } + 9 ) ) )",
300 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
301 Free_ParamNames(all_vars
, nvar
+nparam
);
303 lattice_point(&V
, rays
, lambda
, &num
, 4, options
);
304 Matrix_Free(V
.Vertex
);
306 for (int i
= 0; i
< 4; ++i
) {
307 assert(eequal(num
.E
[i
], point
[i
]));
308 evalue_free(point
[i
]);
309 evalue_free(num
.E
[i
]);
315 static int test_icounter(struct barvinok_options
*options
)
321 set_from_string(n_coeff
, "[-2/1 1/1]");
322 set_from_string(n_power
, "[[2 6][3 6]]");
323 d_power
.SetDims(0, 2);
324 cnt
.reduce(n_coeff
, n_power
, d_power
);
325 assert(value_cmp_si(mpq_numref(cnt
.count
), -1) == 0);
326 assert(value_cmp_si(mpq_denref(cnt
.count
), 1) == 0);
330 static int test_infinite_counter(struct barvinok_options
*options
)
332 Matrix
*M
= matrix_read_from_str("1 3\n 1 1 0\n");
333 Polyhedron
*ctx
= Constraints2Polyhedron(M
, options
->MaxRays
);
336 /* (1 -1/2 x^5 - 1/2 x^7)/(1-x) */
337 infinite_counter
*cnt
= new infinite_counter(1, 1);
342 set_from_string(n_coeff
, "[1/1 -1/2 -1/2]");
343 set_from_string(n_power
, "[[0][5][7]]");
344 set_from_string(d_power
, "[[1]]");
345 cnt
->reduce(n_coeff
, n_power
, d_power
);
346 assert(value_cmp_si(mpq_numref(cnt
->count
[0]), 6) == 0);
347 assert(value_cmp_si(mpq_denref(cnt
->count
[0]), 1) == 0);
348 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) == 0);
349 assert(value_cmp_si(mpq_denref(cnt
->count
[1]), 1) == 0);
351 Polyhedron_Free(ctx
);
353 M
= matrix_read_from_str("2 4\n 1 1 0 0\n 1 0 1 0\n");
354 ctx
= Constraints2Polyhedron(M
, options
->MaxRays
);
357 /* (1 - xy)/((1-x)(1-xy)) */
358 cnt
= new infinite_counter(2, 3);
360 set_from_string(n_coeff
, "[1/1 -1/1]");
361 set_from_string(n_power
, "[[0 0][1 1]]");
362 set_from_string(d_power
, "[[1 0][1 1]]");
363 cnt
->reduce(n_coeff
, n_power
, d_power
);
364 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) != 0);
365 assert(value_cmp_si(mpq_numref(cnt
->count
[2]), 0) == 0);
366 assert(value_cmp_si(mpq_denref(cnt
->count
[2]), 1) == 0);
367 assert(value_cmp_si(mpq_numref(cnt
->count
[3]), 0) == 0);
368 assert(value_cmp_si(mpq_denref(cnt
->count
[3]), 1) == 0);
371 cnt
= new infinite_counter(2, 2);
373 set_from_string(n_coeff
, "[-1/2 1/1 -1/3]");
374 set_from_string(n_power
, "[[2 6][3 6]]");
375 d_power
.SetDims(0, 2);
376 cnt
->reduce(n_coeff
, n_power
, d_power
);
377 assert(value_cmp_si(mpq_numref(cnt
->count
[0]), 1) == 0);
378 assert(value_cmp_si(mpq_denref(cnt
->count
[0]), 6) == 0);
379 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) == 0);
380 assert(value_cmp_si(mpq_denref(cnt
->count
[1]), 1) == 0);
381 assert(value_cmp_si(mpq_numref(cnt
->count
[2]), 0) == 0);
382 assert(value_cmp_si(mpq_denref(cnt
->count
[2]), 1) == 0);
385 cnt
= new infinite_counter(2, 2);
387 set_from_string(n_coeff
, "[1/1]");
388 set_from_string(n_power
, "[[0 11]]");
389 set_from_string(d_power
, "[[0 1]]");
390 cnt
->reduce(n_coeff
, n_power
, d_power
);
391 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) != 0);
392 assert(value_cmp_si(mpq_numref(cnt
->count
[2]), 0) == 0);
393 assert(value_cmp_si(mpq_denref(cnt
->count
[2]), 1) == 0);
396 Polyhedron_Free(ctx
);
401 static int test_series(struct barvinok_options
*options
)
403 Matrix
*M
= matrix_read_from_str(
405 " 0 1 0 0 0 0 0 1 0 0 3 \n"
406 " 0 0 1 0 0 0 0 -1 1 0 -5 \n"
407 " 0 0 0 1 0 0 0 0 -2 -1 6 \n"
408 " 0 0 0 0 1 0 0 1 1 0 5 \n"
409 " 0 0 0 0 0 1 0 0 -1 0 0 \n"
410 " 0 0 0 0 0 0 1 -2 0 -1 -3 \n"
411 " 1 0 0 0 0 0 0 2 0 1 3 \n"
412 " 1 0 0 0 0 0 0 1 -1 0 5 \n"
413 " 1 0 0 0 0 0 0 -1 -1 0 -5 \n"
414 " 1 0 0 0 0 0 0 -1 0 0 -3 \n"
415 " 1 0 0 0 0 0 0 0 2 1 -6 \n"
416 " 1 0 0 0 0 0 0 0 1 0 0 \n");
417 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
419 Polyhedron
*C
= Universe_Polyhedron(3);
420 gen_fun
*gf
= barvinok_series_with_options(P
, C
, options
);
425 M
= matrix_read_from_str(
427 " 0 1 1 0 0 1 0 2 \n"
428 " 0 0 0 1 0 -2 0 6 \n"
429 " 0 0 0 0 1 -1 0 -1 \n"
430 " 0 0 0 0 0 0 1 0 \n"
431 " 1 0 1 0 0 0 0 0 \n"
432 " 1 0 -1 0 0 -1 0 -2 \n"
433 " 1 0 0 0 0 1 0 -3 \n");
434 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
436 C
= Universe_Polyhedron(2);
437 gf
= barvinok_series_with_options(P
, C
, options
);
442 M
= matrix_read_from_str(
446 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
448 C
= Universe_Polyhedron(1);
449 gf
= barvinok_series_with_options(P
, C
, options
);
452 gen_fun
*sum
= gf
->summate(1, options
);
459 int test_todd(struct barvinok_options
*options
)
461 tcounter
t(2, options
->max_index
);
462 assert(value_cmp_si(t
.todd
.coeff
->p
[0], 1) == 0);
463 assert(value_cmp_si(t
.todd
.coeff
->p
[1], -3) == 0);
464 assert(value_cmp_si(t
.todd
.coeff
->p
[2], 3) == 0);
465 assert(value_cmp_si(t
.todd_denom
->p
[0], 1) == 0);
466 assert(value_cmp_si(t
.todd_denom
->p
[1], 6) == 0);
467 assert(value_cmp_si(t
.todd_denom
->p
[2], 36) == 0);
470 set_from_string(lambda
, "[1 -1]");
471 zz2values(lambda
, t
.lambda
->p
);
474 set_from_string(rays
, "[[-1 0][-1 1]]");
479 set_from_string(v
, "[2 0 1]");
480 Vector
*vertex
= Vector_Alloc(3);
481 zz2values(v
, vertex
->p
);
483 t
.handle(rays
, vertex
->p
, one
, 1, options
);
484 assert(value_cmp_si(mpq_numref(t
.count
), 71) == 0);
485 assert(value_cmp_si(mpq_denref(t
.count
), 24) == 0);
487 set_from_string(rays
, "[[0 -1][1 -1]]");
488 set_from_string(v
, "[0 2 1]");
489 zz2values(v
, vertex
->p
);
491 t
.handle(rays
, vertex
->p
, one
, 1, options
);
492 assert(value_cmp_si(mpq_numref(t
.count
), 71) == 0);
493 assert(value_cmp_si(mpq_denref(t
.count
), 12) == 0);
495 set_from_string(rays
, "[[1 0][0 1]]");
496 set_from_string(v
, "[0 0 1]");
497 zz2values(v
, vertex
->p
);
499 t
.handle(rays
, vertex
->p
, one
, 1, options
);
500 assert(value_cmp_si(mpq_numref(t
.count
), 6) == 0);
501 assert(value_cmp_si(mpq_denref(t
.count
), 1) == 0);
507 int test_bernoulli(struct barvinok_options
*options
)
509 struct bernoulli_coef
*bernoulli_coef
;
510 struct poly_list
*faulhaber
, *bernoulli
;
511 bernoulli_coef
= bernoulli_coef_compute(2);
512 faulhaber
= faulhaber_compute(4);
513 bernoulli_coef
= bernoulli_coef_compute(8);
514 assert(value_cmp_si(bernoulli_coef
->num
->p
[6], 1) == 0);
515 assert(value_cmp_si(bernoulli_coef
->den
->p
[6], 42) == 0);
516 assert(value_cmp_si(faulhaber
->poly
[3]->p
[0], 0) == 0);
517 assert(value_cmp_si(faulhaber
->poly
[3]->p
[1], 0) == 0);
518 assert(value_cmp_si(faulhaber
->poly
[3]->p
[2], 1) == 0);
519 assert(value_cmp_si(faulhaber
->poly
[3]->p
[3], -2) == 0);
520 assert(value_cmp_si(faulhaber
->poly
[3]->p
[4], 1) == 0);
521 assert(value_cmp_si(faulhaber
->poly
[3]->p
[5], 4) == 0);
523 bernoulli
= bernoulli_compute(6);
524 assert(value_cmp_si(bernoulli
->poly
[6]->p
[0], 1) == 0);
525 assert(value_cmp_si(bernoulli
->poly
[6]->p
[1], 0) == 0);
526 assert(value_cmp_si(bernoulli
->poly
[6]->p
[2], -21) == 0);
527 assert(value_cmp_si(bernoulli
->poly
[6]->p
[3], 0) == 0);
528 assert(value_cmp_si(bernoulli
->poly
[6]->p
[4], 105) == 0);
529 assert(value_cmp_si(bernoulli
->poly
[6]->p
[5], -126) == 0);
530 assert(value_cmp_si(bernoulli
->poly
[6]->p
[6], 42) == 0);
531 assert(value_cmp_si(bernoulli
->poly
[6]->p
[7], 42) == 0);
533 unsigned nvar
, nparam
;
534 const char **all_vars
;
535 evalue
*base
, *sum1
, *sum2
;
536 base
= evalue_read_from_str("(1 * n + 1)", NULL
, &all_vars
, &nvar
, &nparam
,
539 sum1
= evalue_polynomial(faulhaber
->poly
[3], base
);
540 Free_ParamNames(all_vars
, nvar
+nparam
);
542 sum2
= evalue_read_from_str("(1/4 * n^4 + 1/2 * n^3 + 1/4 * n^2)",
543 NULL
, &all_vars
, &nvar
, &nparam
,
545 Free_ParamNames(all_vars
, nvar
+nparam
);
546 assert(eequal(sum1
, sum2
));
553 int test_bernoulli_sum(struct barvinok_options
*options
)
555 int summation
= options
->summation
;
556 options
->summation
= BV_SUM_BERNOULLI
;
558 unsigned nvar
, nparam
;
559 const char **all_vars
;
560 evalue
*e
, *sum1
, *sum2
;
561 e
= evalue_read_from_str("i + -1 >= 0\n -i + n >= 0\n\n 1 + (-1 *i) + i^2",
562 "i", &all_vars
, &nvar
, &nparam
,
564 Free_ParamNames(all_vars
, nvar
+nparam
);
566 sum1
= barvinok_summate(e
, 1, options
);
567 sum2
= evalue_read_from_str("n -1 >= 0\n\n (1/3 * n^3 + 2/3 * n)",
568 NULL
, &all_vars
, &nvar
, &nparam
,
570 Free_ParamNames(all_vars
, nvar
+nparam
);
574 assert(EVALUE_IS_ZERO(*sum1
));
578 e
= evalue_read_from_str("-i + -1 >= 0\n i + n >= 0\n\n 1 + i + i^2",
579 "i", &all_vars
, &nvar
, &nparam
,
581 Free_ParamNames(all_vars
, nvar
+nparam
);
582 sum1
= barvinok_summate(e
, 1, options
);
586 assert(EVALUE_IS_ZERO(*sum1
));
592 e
= evalue_read_from_str("i + 4 >= 0\n -i + n >= 0\n\n i",
593 "i", &all_vars
, &nvar
, &nparam
,
595 Free_ParamNames(all_vars
, nvar
+nparam
);
596 sum1
= barvinok_summate(e
, 1, options
);
597 sum2
= evalue_read_from_str("n + 0 >= 0\n\n (1/2 * n^2 + 1/2 * n + (-10))\n"
598 "n + 4 >= 0\n -n -1 >= 0\n\n (1/2 * n^2 + 1/2 * n + (-10))",
599 NULL
, &all_vars
, &nvar
, &nparam
,
601 Free_ParamNames(all_vars
, nvar
+nparam
);
605 assert(EVALUE_IS_ZERO(*sum1
));
610 e
= evalue_read_from_str("i -5 >= 0\n -i + n >= 0\n j -1 >= 0\n i -j >= 0\n"
611 "k -1 >= 0\n j -k >= 0\n\n1",
612 "i,j,k", &all_vars
, &nvar
, &nparam
,
614 Free_ParamNames(all_vars
, nvar
+nparam
);
615 sum1
= barvinok_summate(e
, 3, options
);
616 sum2
= evalue_read_from_str("n -5 >= 0\n\n"
617 "1/6 * n^3 + 1/2 * n^2 + 1/3 * n + -20",
618 NULL
, &all_vars
, &nvar
, &nparam
,
620 Free_ParamNames(all_vars
, nvar
+nparam
);
624 assert(EVALUE_IS_ZERO(*sum1
));
629 options
->summation
= summation
;
633 int test_hilbert(struct barvinok_options
*options
)
636 Matrix
*M
= matrix_read_from_str(
640 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
643 M
= Cone_Hilbert_Basis(P
, options
->MaxRays
);
644 assert(M
->NbRows
= 5);
645 assert(M
->NbColumns
= 3);
648 M
= Cone_Integer_Hull(P
, NULL
, 0, options
);
649 assert(M
->NbRows
= 4);
650 assert(M
->NbColumns
= 3);
658 int test_ilp(struct barvinok_options
*options
)
660 Matrix
*M
= matrix_read_from_str(
664 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
666 Vector
*obj
= Vector_Alloc(2);
667 value_set_si(obj
->p
[0], 7);
668 value_set_si(obj
->p
[1], -1);
673 value_set_si(min
, 1);
674 value_set_si(max
, 17);
675 Vector
*opt
= Polyhedron_Integer_Minimum(P
, obj
->p
, min
, max
,
678 assert(value_cmp_si(opt
->p
[0], 1) == 0);
679 assert(value_cmp_si(opt
->p
[1], 1) == 0);
680 assert(value_cmp_si(opt
->p
[2], 1) == 0);
690 int test_hull(struct barvinok_options
*options
)
692 Matrix
*M
= matrix_read_from_str(
698 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
701 Matrix
*hull
= Polyhedron_Integer_Hull(P
, options
);
703 assert(hull
->NbRows
== 4);
704 M
= Matrix_Alloc(hull
->NbRows
, 1+hull
->NbColumns
);
705 for (int i
= 0; i
< hull
->NbRows
; ++i
) {
706 value_set_si(M
->p
[i
][0], 1);
707 Vector_Copy(hull
->p
[i
], M
->p
[i
]+1, hull
->NbColumns
);
710 Polyhedron
*H
= Constraints2Polyhedron(M
, options
->MaxRays
);
713 M
= matrix_read_from_str(
719 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
721 assert(PolyhedronIncludes(P
, H
) && PolyhedronIncludes(H
, P
));
725 M
= matrix_read_from_str(
730 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
733 hull
= Polyhedron_Integer_Hull(P
, options
);
735 assert(hull
->NbRows
== 0);
740 static int test_laurent(struct barvinok_options
*options
)
742 unsigned nvar
, nparam
;
743 const char **all_vars
;
744 evalue
*e
, *sum
, *res
;
746 e
= evalue_read_from_str(" x1 >= 0\n"
748 " -x1 -x2 + 2 >= 0\n"
751 "x1,x2", &all_vars
, &nvar
, &nparam
,
753 Free_ParamNames(all_vars
, nvar
+nparam
);
755 int summation
= options
->summation
;
756 options
->summation
= BV_SUM_LAURENT
;
757 sum
= barvinok_summate(e
, nvar
, options
);
758 options
->summation
= summation
;
760 res
= evalue_read_from_str("(6 * N + 4 * M)",
761 "", &all_vars
, &nvar
, &nparam
,
763 Free_ParamNames(all_vars
, nvar
+nparam
);
765 assert(value_zero_p(sum
->d
));
766 assert(sum
->x
.p
->type
== partition
);
767 assert(sum
->x
.p
->size
== 2);
769 assert(eequal(res
, &sum
->x
.p
->arr
[1]));
777 int main(int argc
, char **argv
)
779 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
780 test_equalities(options
);
781 test_evalue_read(options
);
783 test_evalue(options
);
784 test_substitute(options
);
785 test_split_periods(options
);
786 test_specialization(options
);
787 test_lattice_points(options
);
788 test_icounter(options
);
789 test_infinite_counter(options
);
790 test_series(options
);
792 test_bernoulli(options
);
793 test_bernoulli_sum(options
);
794 test_hilbert(options
);
797 test_laurent(options
);
798 barvinok_options_free(options
);