evalue.c: clean up emul and eadd
[barvinok/uuh.git] / testlib.cc
blob9f681ca396a4e92f961f7d83f593ccacf1545df9
1 #include <assert.h>
2 #include <sstream>
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"
10 #include "dpoly.h"
11 #include "lattice_point.h"
12 #include "counter.h"
13 #include "bernoulli.h"
14 #include "hilbert.h"
15 #include "hull.h"
16 #include "ilp.h"
17 #include "matrix_read.h"
18 #include "config.h"
20 using std::cout;
21 using std::cerr;
22 using std::endl;
24 template <typename T>
25 void set_from_string(T& v, const char *s)
27 std::istringstream str(s);
28 str >> v;
31 int test_evalue_read(struct barvinok_options *options)
33 unsigned nvar, nparam;
34 char **all_vars;
35 evalue *e1, *e2;
37 e1 = evalue_read_from_str("(1 * aa + 2 * a)",
38 NULL, &all_vars, &nvar, &nparam, options->MaxRays);
39 Free_ParamNames(all_vars, nvar+nparam);
40 e2 = evalue_read_from_str("(3 * aa)",
41 NULL, &all_vars, &nvar, &nparam, options->MaxRays);
42 Free_ParamNames(all_vars, nvar+nparam);
43 assert(!eequal(e1, e2));
44 evalue_free(e1);
45 evalue_free(e2);
48 int test_evalue(struct barvinok_options *options)
50 unsigned nvar, nparam;
51 char **all_vars;
52 evalue *poly1, poly2;
54 poly1 = evalue_read_from_str("(1/4 * n^4 + 1/2 * n^3 + 1/4 * n^2)",
55 NULL, &all_vars, &nvar, &nparam,
56 options->MaxRays);
57 Free_ParamNames(all_vars, nvar+nparam);
59 value_init(poly2.d);
60 evalue_copy(&poly2, poly1);
61 evalue_negate(poly1);
62 eadd(&poly2, poly1);
63 reduce_evalue(poly1);
64 assert(EVALUE_IS_ZERO(*poly1));
65 evalue_free(poly1);
66 free_evalue_refs(&poly2);
69 int test_split_periods(struct barvinok_options *options)
71 unsigned nvar, nparam;
72 char **all_vars;
73 evalue *e;
75 e = evalue_read_from_str("U + 2V + 3 >= 0\n- U -2V >= 0\n- U 10 >= 0\n"
76 "U >= 0\n\n({( 1/3 * U + ( 2/3 * V + 0 ))})",
77 NULL, &all_vars, &nvar, &nparam,
78 options->MaxRays);
79 Free_ParamNames(all_vars, nvar+nparam);
81 evalue_split_periods(e, 2, options->MaxRays);
82 assert(value_zero_p(e->d));
83 assert(e->x.p->type == partition);
84 assert(e->x.p->size == 4);
85 assert(value_zero_p(e->x.p->arr[1].d));
86 assert(e->x.p->arr[1].x.p->type == polynomial);
87 assert(value_zero_p(e->x.p->arr[3].d));
88 assert(e->x.p->arr[3].x.p->type == polynomial);
89 evalue_free(e);
92 int test_specialization(struct barvinok_options *options)
94 Value v;
95 value_init(v);
96 mpq_t count;
97 mpq_init(count);
99 value_set_si(v, 5);
100 dpoly n(2, v);
101 assert(value_cmp_si(n.coeff->p[0], 1) == 0);
102 assert(value_cmp_si(n.coeff->p[1], 5) == 0);
103 assert(value_cmp_si(n.coeff->p[2], 10) == 0);
105 value_set_si(v, 1);
106 dpoly d(2, v, 1);
107 value_set_si(v, 2);
108 dpoly d2(2, v, 1);
109 d *= d2;
110 assert(value_cmp_si(d.coeff->p[0], 2) == 0);
111 assert(value_cmp_si(d.coeff->p[1], 1) == 0);
112 assert(value_cmp_si(d.coeff->p[2], 0) == 0);
114 n.div(d, count, 1);
115 mpq_canonicalize(count);
116 assert(value_cmp_si(mpq_numref(count), 31) == 0);
117 assert(value_cmp_si(mpq_denref(count), 8) == 0);
119 value_set_si(v, -2);
120 dpoly n2(2, v);
121 assert(value_cmp_si(n2.coeff->p[0], 1) == 0);
122 assert(value_cmp_si(n2.coeff->p[1], -2) == 0);
123 assert(value_cmp_si(n2.coeff->p[2], 3) == 0);
125 n2.div(d, count, 1);
126 mpq_canonicalize(count);
127 assert(value_cmp_si(mpq_numref(count), 6) == 0);
128 assert(value_cmp_si(mpq_denref(count), 1) == 0);
130 value_clear(v);
131 mpq_clear(count);
134 int test_lattice_points(struct barvinok_options *options)
136 Param_Vertices V;
137 mat_ZZ tmp;
138 set_from_string(tmp, "[[0 0 0 0 4][0 0 0 0 4][-1 0 1 0 4]]");
139 V.Vertex = zz2matrix(tmp);
140 vec_ZZ lambda;
141 set_from_string(lambda, "[3 5 7]");
142 mat_ZZ rays;
143 set_from_string(rays, "[[0 1 0][4 0 1][0 0 -1]]");
144 term_info num;
145 evalue *point[4];
147 unsigned nvar, nparam;
148 char **all_vars;
149 point[0] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
150 "( 7 * {( 1/4 * a + ( 3/4 * c + 3/4 ) ) } + -21/4 ) ) )",
151 "a,b,c", &all_vars, &nvar, &nparam, options->MaxRays);
152 Free_ParamNames(all_vars, nvar+nparam);
153 point[1] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
154 "( 7 * {( 1/4 * a + ( 3/4 * c + 1/2 ) ) } + -1/2 ) ) )",
155 "a,b,c", &all_vars, &nvar, &nparam, options->MaxRays);
156 Free_ParamNames(all_vars, nvar+nparam);
157 point[2] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
158 "( 7 * {( 1/4 * a + ( 3/4 * c + 1/4 ) ) } + 17/4 ) ) )",
159 "a,b,c", &all_vars, &nvar, &nparam, options->MaxRays);
160 Free_ParamNames(all_vars, nvar+nparam);
161 point[3] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
162 "( 7 * {( 1/4 * a + ( 3/4 * c + 0 ) ) } + 9 ) ) )",
163 "a,b,c", &all_vars, &nvar, &nparam, options->MaxRays);
164 Free_ParamNames(all_vars, nvar+nparam);
166 lattice_point(&V, rays, lambda, &num, 4, options);
167 Matrix_Free(V.Vertex);
169 for (int i = 0; i < 4; ++i) {
170 assert(eequal(num.E[i], point[i]));
171 evalue_free(point[i]);
172 free_evalue_refs(num.E[i]);
173 delete num.E[i];
175 delete [] num.E;
178 static int test_icounter(struct barvinok_options *options)
180 icounter cnt(2);
181 vec_QQ n_coeff;
182 mat_ZZ n_power;
183 mat_ZZ d_power;
184 set_from_string(n_coeff, "[-2/1 1/1]");
185 set_from_string(n_power, "[[2 6][3 6]]");
186 d_power.SetDims(0, 2);
187 cnt.reduce(n_coeff, n_power, d_power);
188 assert(value_cmp_si(mpq_numref(cnt.count), -1) == 0);
189 assert(value_cmp_si(mpq_denref(cnt.count), 1) == 0);
192 static Matrix *matrix_read_from_str(const char *s)
194 std::istringstream str(s);
195 return Matrix_Read(str);
198 static int test_infinite_counter(struct barvinok_options *options)
200 Matrix *M = matrix_read_from_str("1 3\n 1 1 0\n");
201 Polyhedron *ctx = Constraints2Polyhedron(M, options->MaxRays);
202 Matrix_Free(M);
204 /* (1 -1/2 x^5 - 1/2 x^7)/(1-x) */
205 infinite_counter *cnt = new infinite_counter(1, 1);
206 cnt->init(ctx);
207 vec_QQ n_coeff;
208 mat_ZZ n_power;
209 mat_ZZ d_power;
210 set_from_string(n_coeff, "[1/1 -1/2 -1/2]");
211 set_from_string(n_power, "[[0][5][7]]");
212 set_from_string(d_power, "[[1]]");
213 cnt->reduce(n_coeff, n_power, d_power);
214 assert(value_cmp_si(mpq_numref(cnt->count[0]), 6) == 0);
215 assert(value_cmp_si(mpq_denref(cnt->count[0]), 1) == 0);
216 assert(value_cmp_si(mpq_numref(cnt->count[1]), 0) == 0);
217 assert(value_cmp_si(mpq_denref(cnt->count[1]), 1) == 0);
218 delete cnt;
219 Polyhedron_Free(ctx);
221 M = matrix_read_from_str("2 4\n 1 1 0 0\n 1 0 1 0\n");
222 ctx = Constraints2Polyhedron(M, options->MaxRays);
223 Matrix_Free(M);
225 /* (1 - xy)/((1-x)(1-xy)) */
226 cnt = new infinite_counter(2, 3);
227 cnt->init(ctx);
228 set_from_string(n_coeff, "[1/1 -1/1]");
229 set_from_string(n_power, "[[0 0][1 1]]");
230 set_from_string(d_power, "[[1 0][1 1]]");
231 cnt->reduce(n_coeff, n_power, d_power);
232 assert(value_cmp_si(mpq_numref(cnt->count[1]), 0) != 0);
233 assert(value_cmp_si(mpq_numref(cnt->count[2]), 0) == 0);
234 assert(value_cmp_si(mpq_denref(cnt->count[2]), 1) == 0);
235 assert(value_cmp_si(mpq_numref(cnt->count[3]), 0) == 0);
236 assert(value_cmp_si(mpq_denref(cnt->count[3]), 1) == 0);
237 delete cnt;
239 cnt = new infinite_counter(2, 2);
240 cnt->init(ctx);
241 set_from_string(n_coeff, "[-1/2 1/1 -1/3]");
242 set_from_string(n_power, "[[2 6][3 6]]");
243 d_power.SetDims(0, 2);
244 cnt->reduce(n_coeff, n_power, d_power);
245 assert(value_cmp_si(mpq_numref(cnt->count[0]), 1) == 0);
246 assert(value_cmp_si(mpq_denref(cnt->count[0]), 6) == 0);
247 assert(value_cmp_si(mpq_numref(cnt->count[1]), 0) == 0);
248 assert(value_cmp_si(mpq_denref(cnt->count[1]), 1) == 0);
249 assert(value_cmp_si(mpq_numref(cnt->count[2]), 0) == 0);
250 assert(value_cmp_si(mpq_denref(cnt->count[2]), 1) == 0);
251 delete cnt;
253 cnt = new infinite_counter(2, 2);
254 cnt->init(ctx);
255 set_from_string(n_coeff, "[1/1]");
256 set_from_string(n_power, "[[0 11]]");
257 set_from_string(d_power, "[[0 1]]");
258 cnt->reduce(n_coeff, n_power, d_power);
259 assert(value_cmp_si(mpq_numref(cnt->count[1]), 0) != 0);
260 assert(value_cmp_si(mpq_numref(cnt->count[2]), 0) == 0);
261 assert(value_cmp_si(mpq_denref(cnt->count[2]), 1) == 0);
262 delete cnt;
264 Polyhedron_Free(ctx);
266 return 0;
269 static int test_series(struct barvinok_options *options)
271 Matrix *M = matrix_read_from_str(
272 "12 11\n"
273 " 0 1 0 0 0 0 0 1 0 0 3 \n"
274 " 0 0 1 0 0 0 0 -1 1 0 -5 \n"
275 " 0 0 0 1 0 0 0 0 -2 -1 6 \n"
276 " 0 0 0 0 1 0 0 1 1 0 5 \n"
277 " 0 0 0 0 0 1 0 0 -1 0 0 \n"
278 " 0 0 0 0 0 0 1 -2 0 -1 -3 \n"
279 " 1 0 0 0 0 0 0 2 0 1 3 \n"
280 " 1 0 0 0 0 0 0 1 -1 0 5 \n"
281 " 1 0 0 0 0 0 0 -1 -1 0 -5 \n"
282 " 1 0 0 0 0 0 0 -1 0 0 -3 \n"
283 " 1 0 0 0 0 0 0 0 2 1 -6 \n"
284 " 1 0 0 0 0 0 0 0 1 0 0 \n");
285 Polyhedron *P = Constraints2Polyhedron(M, options->MaxRays);
286 Matrix_Free(M);
287 Polyhedron *C = Universe_Polyhedron(3);
288 gen_fun *gf = barvinok_series_with_options(P, C, options);
289 Polyhedron_Free(P);
290 Polyhedron_Free(C);
291 delete gf;
293 M = matrix_read_from_str(
294 "7 8\n"
295 " 0 1 1 0 0 1 0 2 \n"
296 " 0 0 0 1 0 -2 0 6 \n"
297 " 0 0 0 0 1 -1 0 -1 \n"
298 " 0 0 0 0 0 0 1 0 \n"
299 " 1 0 1 0 0 0 0 0 \n"
300 " 1 0 -1 0 0 -1 0 -2 \n"
301 " 1 0 0 0 0 1 0 -3 \n");
302 P = Constraints2Polyhedron(M, options->MaxRays);
303 Matrix_Free(M);
304 C = Universe_Polyhedron(2);
305 gf = barvinok_series_with_options(P, C, options);
306 Polyhedron_Free(P);
307 Polyhedron_Free(C);
308 delete gf;
310 M = matrix_read_from_str(
311 "2 3\n"
312 "1 1 0\n"
313 "1 -1 10\n");
314 P = Constraints2Polyhedron(M, options->MaxRays);
315 Matrix_Free(M);
316 C = Universe_Polyhedron(1);
317 gf = barvinok_series_with_options(P, C, options);
318 Polyhedron_Free(P);
319 Polyhedron_Free(C);
320 gen_fun *sum = gf->summate(1, options);
321 delete gf;
322 delete sum;
324 return 0;
327 int test_todd(struct barvinok_options *options)
329 tcounter t(2, options->max_index);
330 assert(value_cmp_si(t.todd.coeff->p[0], 1) == 0);
331 assert(value_cmp_si(t.todd.coeff->p[1], -3) == 0);
332 assert(value_cmp_si(t.todd.coeff->p[2], 3) == 0);
333 assert(value_cmp_si(t.todd_denom->p[0], 1) == 0);
334 assert(value_cmp_si(t.todd_denom->p[1], 6) == 0);
335 assert(value_cmp_si(t.todd_denom->p[2], 36) == 0);
337 vec_ZZ lambda;
338 set_from_string(lambda, "[1 -1]");
339 zz2values(lambda, t.lambda->p);
341 mat_ZZ rays;
342 set_from_string(rays, "[[-1 0][-1 1]]");
344 QQ one(1, 1);
346 vec_ZZ v;
347 set_from_string(v, "[2 0 1]");
348 Vector *vertex = Vector_Alloc(3);
349 zz2values(v, vertex->p);
351 t.handle(rays, vertex->p, one, 1, options);
352 assert(value_cmp_si(mpq_numref(t.count), 71) == 0);
353 assert(value_cmp_si(mpq_denref(t.count), 24) == 0);
355 set_from_string(rays, "[[0 -1][1 -1]]");
356 set_from_string(v, "[0 2 1]");
357 zz2values(v, vertex->p);
359 t.handle(rays, vertex->p, one, 1, options);
360 assert(value_cmp_si(mpq_numref(t.count), 71) == 0);
361 assert(value_cmp_si(mpq_denref(t.count), 12) == 0);
363 set_from_string(rays, "[[1 0][0 1]]");
364 set_from_string(v, "[0 0 1]");
365 zz2values(v, vertex->p);
367 t.handle(rays, vertex->p, one, 1, options);
368 assert(value_cmp_si(mpq_numref(t.count), 6) == 0);
369 assert(value_cmp_si(mpq_denref(t.count), 1) == 0);
371 Vector_Free(vertex);
374 int test_bernoulli(struct barvinok_options *options)
376 struct bernoulli_coef *bernoulli_coef;
377 struct poly_list *faulhaber, *bernoulli;
378 bernoulli_coef = bernoulli_coef_compute(2);
379 faulhaber = faulhaber_compute(4);
380 bernoulli_coef = bernoulli_coef_compute(8);
381 assert(value_cmp_si(bernoulli_coef->num->p[6], 1) == 0);
382 assert(value_cmp_si(bernoulli_coef->den->p[6], 42) == 0);
383 assert(value_cmp_si(faulhaber->poly[3]->p[0], 0) == 0);
384 assert(value_cmp_si(faulhaber->poly[3]->p[1], 0) == 0);
385 assert(value_cmp_si(faulhaber->poly[3]->p[2], 1) == 0);
386 assert(value_cmp_si(faulhaber->poly[3]->p[3], -2) == 0);
387 assert(value_cmp_si(faulhaber->poly[3]->p[4], 1) == 0);
388 assert(value_cmp_si(faulhaber->poly[3]->p[5], 4) == 0);
390 bernoulli = bernoulli_compute(6);
391 assert(value_cmp_si(bernoulli->poly[6]->p[0], 1) == 0);
392 assert(value_cmp_si(bernoulli->poly[6]->p[1], 0) == 0);
393 assert(value_cmp_si(bernoulli->poly[6]->p[2], -21) == 0);
394 assert(value_cmp_si(bernoulli->poly[6]->p[3], 0) == 0);
395 assert(value_cmp_si(bernoulli->poly[6]->p[4], 105) == 0);
396 assert(value_cmp_si(bernoulli->poly[6]->p[5], -126) == 0);
397 assert(value_cmp_si(bernoulli->poly[6]->p[6], 42) == 0);
398 assert(value_cmp_si(bernoulli->poly[6]->p[7], 42) == 0);
400 unsigned nvar, nparam;
401 char **all_vars;
402 evalue *base, *sum1, *sum2;
403 base = evalue_read_from_str("(1 * n + 1)", NULL, &all_vars, &nvar, &nparam,
404 options->MaxRays);
406 sum1 = evalue_polynomial(faulhaber->poly[3], base);
407 Free_ParamNames(all_vars, nvar+nparam);
409 sum2 = evalue_read_from_str("(1/4 * n^4 + 1/2 * n^3 + 1/4 * n^2)",
410 NULL, &all_vars, &nvar, &nparam,
411 options->MaxRays);
412 Free_ParamNames(all_vars, nvar+nparam);
413 assert(eequal(sum1, sum2));
414 evalue_free(base);
415 evalue_free(sum1);
416 evalue_free(sum2);
419 int test_bernoulli_sum(struct barvinok_options *options)
421 unsigned nvar, nparam;
422 char **all_vars;
423 evalue *e, *sum1, *sum2;
424 e = evalue_read_from_str("i + -1 >= 0\n -i + n >= 0\n\n 1 + (-1 *i) + i^2",
425 "i", &all_vars, &nvar, &nparam,
426 options->MaxRays);
427 Free_ParamNames(all_vars, nvar+nparam);
429 sum1 = Bernoulli_sum_evalue(e, 1, options);
430 sum2 = evalue_read_from_str("n -1 >= 0\n\n (1/3 * n^3 + 2/3 * n)",
431 NULL, &all_vars, &nvar, &nparam,
432 options->MaxRays);
433 Free_ParamNames(all_vars, nvar+nparam);
434 evalue_negate(sum1);
435 eadd(sum2, sum1);
436 reduce_evalue(sum1);
437 assert(EVALUE_IS_ZERO(*sum1));
438 evalue_free(e);
439 evalue_free(sum1);
441 e = evalue_read_from_str("-i + -1 >= 0\n i + n >= 0\n\n 1 + i + i^2",
442 "i", &all_vars, &nvar, &nparam,
443 options->MaxRays);
444 Free_ParamNames(all_vars, nvar+nparam);
445 sum1 = Bernoulli_sum_evalue(e, 1, options);
446 evalue_negate(sum1);
447 eadd(sum2, sum1);
448 reduce_evalue(sum1);
449 assert(EVALUE_IS_ZERO(*sum1));
450 evalue_free(e);
451 evalue_free(sum1);
453 evalue_free(sum2);
455 e = evalue_read_from_str("i + 4 >= 0\n -i + n >= 0\n\n i",
456 "i", &all_vars, &nvar, &nparam,
457 options->MaxRays);
458 Free_ParamNames(all_vars, nvar+nparam);
459 sum1 = Bernoulli_sum_evalue(e, 1, options);
460 sum2 = evalue_read_from_str("n + 0 >= 0\n\n (1/2 * n^2 + 1/2 * n + (-10))\n"
461 "n + 4 >= 0\n -n -1 >= 0\n\n (1/2 * n^2 + 1/2 * n + (-10))",
462 NULL, &all_vars, &nvar, &nparam,
463 options->MaxRays);
464 Free_ParamNames(all_vars, nvar+nparam);
465 evalue_negate(sum1);
466 eadd(sum2, sum1);
467 reduce_evalue(sum1);
468 assert(EVALUE_IS_ZERO(*sum1));
469 evalue_free(e);
470 evalue_free(sum1);
471 evalue_free(sum2);
473 e = evalue_read_from_str("i -5 >= 0\n -i + n >= 0\n j -1 >= 0\n i -j >= 0\n"
474 "k -1 >= 0\n j -k >= 0\n\n1",
475 "i,j,k", &all_vars, &nvar, &nparam,
476 options->MaxRays);
477 Free_ParamNames(all_vars, nvar+nparam);
478 sum1 = Bernoulli_sum_evalue(e, 3, options);
479 sum2 = evalue_read_from_str("n -5 >= 0\n\n"
480 "1/6 * n^3 + 1/2 * n^2 + 1/3 * n + -20",
481 NULL, &all_vars, &nvar, &nparam,
482 options->MaxRays);
483 Free_ParamNames(all_vars, nvar+nparam);
484 evalue_negate(sum1);
485 eadd(sum2, sum1);
486 reduce_evalue(sum1);
487 assert(EVALUE_IS_ZERO(*sum1));
488 evalue_free(e);
489 evalue_free(sum1);
490 evalue_free(sum2);
493 int test_hilbert(struct barvinok_options *options)
495 #ifdef USE_ZSOLVE
496 Matrix *M = matrix_read_from_str(
497 "2 4\n"
498 " 1 4 -3 0 \n"
499 " 1 3 2 0 \n");
500 Polyhedron *P = Constraints2Polyhedron(M, options->MaxRays);
501 Matrix_Free(M);
503 M = Cone_Hilbert_Basis(P, options->MaxRays);
504 assert(M->NbRows = 5);
505 assert(M->NbColumns = 3);
506 Matrix_Free(M);
508 M = Cone_Integer_Hull(P, NULL, 0, options);
509 assert(M->NbRows = 4);
510 assert(M->NbColumns = 3);
511 Matrix_Free(M);
513 Polyhedron_Free(P);
514 #endif
517 int test_ilp(struct barvinok_options *options)
519 Matrix *M = matrix_read_from_str(
520 "2 4\n"
521 " 1 4 -3 0 \n"
522 " 1 3 2 0 \n");
523 Polyhedron *P = Constraints2Polyhedron(M, options->MaxRays);
524 Matrix_Free(M);
525 Vector *obj = Vector_Alloc(2);
526 value_set_si(obj->p[0], 7);
527 value_set_si(obj->p[1], -1);
528 Value min, max;
529 value_init(min);
530 value_init(max);
532 value_set_si(min, 1);
533 value_set_si(max, 17);
534 Vector *opt = Polyhedron_Integer_Minimum(P, obj->p, min, max,
535 NULL, 0, options);
536 assert(opt);
537 assert(value_cmp_si(opt->p[0], 1) == 0);
538 assert(value_cmp_si(opt->p[1], 1) == 0);
539 assert(value_cmp_si(opt->p[2], 1) == 0);
540 Vector_Free(opt);
542 value_clear(min);
543 value_clear(max);
544 Vector_Free(obj);
545 Polyhedron_Free(P);
548 int test_hull(struct barvinok_options *options)
550 Matrix *M = matrix_read_from_str(
551 "4 4\n"
552 "1 32 -20 7\n"
553 "1 8 -44 187\n"
554 "1 -48 -4 285\n"
555 "1 8 68 -199\n");
556 Polyhedron *P = Constraints2Polyhedron(M, options->MaxRays);
557 Matrix_Free(M);
559 Matrix *hull = Polyhedron_Integer_Hull(P, options);
560 Polyhedron_Free(P);
561 assert(hull->NbRows == 4);
562 M = Matrix_Alloc(hull->NbRows, 1+hull->NbColumns);
563 for (int i = 0; i < hull->NbRows; ++i) {
564 value_set_si(M->p[i][0], 1);
565 Vector_Copy(hull->p[i], M->p[i]+1, hull->NbColumns);
567 Matrix_Free(hull);
568 Polyhedron *H = Constraints2Polyhedron(M, options->MaxRays);
569 Matrix_Free(M);
571 M = matrix_read_from_str(
572 "4 4\n"
573 "1 2 3 1 \n"
574 "1 3 4 1 \n"
575 "1 5 3 1 \n"
576 "1 5 5 1 \n");
577 P = Constraints2Polyhedron(M, options->MaxRays);
578 Matrix_Free(M);
579 assert(PolyhedronIncludes(P, H) && PolyhedronIncludes(H, P));
580 Polyhedron_Free(P);
581 Polyhedron_Free(H);
583 M = matrix_read_from_str(
584 "3 4\n"
585 "1 2 6 -3 \n"
586 "1 2 -6 3 \n"
587 "1 -2 0 3 \n");
588 P = Constraints2Polyhedron(M, options->MaxRays);
589 Matrix_Free(M);
590 assert(!emptyQ(P));
591 hull = Polyhedron_Integer_Hull(P, options);
592 Polyhedron_Free(P);
593 assert(hull->NbRows == 0);
594 Matrix_Free(hull);
597 int main(int argc, char **argv)
599 struct barvinok_options *options = barvinok_options_new_with_defaults();
600 test_evalue_read(options);
601 test_evalue(options);
602 test_split_periods(options);
603 test_specialization(options);
604 test_lattice_points(options);
605 test_icounter(options);
606 test_infinite_counter(options);
607 test_series(options);
608 test_todd(options);
609 test_bernoulli(options);
610 test_bernoulli_sum(options);
611 test_hilbert(options);
612 test_ilp(options);
613 test_hull(options);
614 barvinok_options_free(options);