2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 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>
17 /* The input of this program is the same as that of the "polytope_scan"
18 * program from the barvinok distribution.
20 * Constraints of set is PolyLib format.
22 * The input set is assumed to be bounded.
26 struct isl_scan_callback callback
;
27 struct isl_mat
*samples
;
30 static int scan_samples_add_sample(struct isl_scan_callback
*cb
,
31 __isl_take isl_vec
*sample
)
33 struct scan_samples
*ss
= (struct scan_samples
*)cb
;
35 ss
->samples
= isl_mat_extend(ss
->samples
, ss
->samples
->n_row
+ 1,
40 isl_seq_cpy(ss
->samples
->row
[ss
->samples
->n_row
- 1],
41 sample
->el
, sample
->size
);
50 static struct isl_mat
*isl_basic_set_scan_samples(struct isl_basic_set
*bset
)
54 struct scan_samples ss
;
56 ctx
= isl_basic_set_get_ctx(bset
);
57 dim
= isl_basic_set_total_dim(bset
);
58 ss
.callback
.add
= scan_samples_add_sample
;
59 ss
.samples
= isl_mat_alloc(ctx
, 0, 1 + dim
);
63 if (isl_basic_set_scan(bset
, &ss
.callback
) < 0) {
64 isl_mat_free(ss
.samples
);
70 isl_basic_set_free(bset
);
74 static struct isl_mat
*isl_basic_set_samples(struct isl_basic_set
*bset
)
77 struct isl_mat
*samples
;
83 return isl_basic_set_scan_samples(bset
);
85 bset
= isl_basic_set_remove_equalities(bset
, &T
, NULL
);
86 samples
= isl_basic_set_scan_samples(bset
);
87 return isl_mat_product(samples
, isl_mat_transpose(T
));
90 int main(int argc
, char **argv
)
92 struct isl_ctx
*ctx
= isl_ctx_alloc();
93 struct isl_basic_set
*bset
;
94 struct isl_mat
*samples
;
96 bset
= isl_basic_set_read_from_file(ctx
, stdin
);
97 samples
= isl_basic_set_samples(bset
);
98 isl_mat_print_internal(samples
, stdout
, 0);
99 isl_mat_free(samples
);