2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 #include <isl_map_private.h>
12 #include "isl_equalities.h"
15 #include <isl_mat_private.h>
16 #include <isl_vec_private.h>
18 /* The input of this program is the same as that of the "polytope_scan"
19 * program from the barvinok distribution.
21 * Constraints of set is PolyLib format.
23 * The input set is assumed to be bounded.
27 struct isl_scan_callback callback
;
28 struct isl_mat
*samples
;
31 static isl_stat
scan_samples_add_sample(struct isl_scan_callback
*cb
,
32 __isl_take isl_vec
*sample
)
34 struct scan_samples
*ss
= (struct scan_samples
*)cb
;
36 ss
->samples
= isl_mat_extend(ss
->samples
, ss
->samples
->n_row
+ 1,
41 isl_seq_cpy(ss
->samples
->row
[ss
->samples
->n_row
- 1],
42 sample
->el
, sample
->size
);
48 return isl_stat_error
;
51 static __isl_give isl_mat
*isl_basic_set_scan_samples(
52 __isl_take isl_basic_set
*bset
)
56 struct scan_samples ss
;
58 ctx
= isl_basic_set_get_ctx(bset
);
59 dim
= isl_basic_set_dim(bset
, isl_dim_all
);
62 ss
.callback
.add
= scan_samples_add_sample
;
63 ss
.samples
= isl_mat_alloc(ctx
, 0, 1 + dim
);
67 if (isl_basic_set_scan(bset
, &ss
.callback
) < 0) {
68 isl_mat_free(ss
.samples
);
74 isl_basic_set_free(bset
);
78 static struct isl_mat
*isl_basic_set_samples(struct isl_basic_set
*bset
)
81 struct isl_mat
*samples
;
87 return isl_basic_set_scan_samples(bset
);
89 bset
= isl_basic_set_remove_equalities(bset
, &T
, NULL
);
90 samples
= isl_basic_set_scan_samples(bset
);
91 return isl_mat_product(samples
, isl_mat_transpose(T
));
94 int main(int argc
, char **argv
)
96 struct isl_ctx
*ctx
= isl_ctx_alloc();
97 struct isl_basic_set
*bset
;
98 struct isl_mat
*samples
;
100 bset
= isl_basic_set_read_from_file(ctx
, stdin
);
101 samples
= isl_basic_set_samples(bset
);
102 isl_mat_print_internal(samples
, stdout
, 0);
103 isl_mat_free(samples
);