update isl to version 0.20
[barvinok.git] / sample.c
blobdc3b1d48debaad25745dedca29308ac17e0e4fea
1 #include <assert.h>
2 #include <isl/ctx.h>
3 #include <isl/val.h>
4 #include <isl/val_gmp.h>
5 #include <isl/space.h>
6 #include <isl/point.h>
7 #include <isl/set.h>
8 #include <isl_set_polylib.h>
9 #include <barvinok/polylib.h>
10 #include <barvinok/sample.h>
12 Vector *Polyhedron_Sample(Polyhedron *P, struct barvinok_options *options)
14 int i;
15 isl_ctx *ctx = isl_ctx_alloc();
16 isl_space *dim;
17 int nvar = P->Dimension;
18 isl_basic_set *bset;
19 isl_point *pnt;
20 Vector *sample = NULL;
22 dim = isl_space_set_alloc(ctx, 0, nvar);
23 bset = isl_basic_set_new_from_polylib(P, dim);
24 pnt = isl_basic_set_sample_point(bset);
26 if (!isl_point_is_void(pnt)) {
27 isl_val *v;
29 sample = Vector_Alloc(1 + nvar);
30 assert(sample);
31 for (i = 0; i < nvar; ++i) {
32 v = isl_point_get_coordinate_val(pnt, isl_dim_set, i);
33 isl_val_get_num_gmp(v, sample->p[i]);
34 isl_val_free(v);
36 value_set_si(sample->p[nvar], 1);
39 isl_point_free(pnt);
41 isl_ctx_free(ctx);
43 return sample;