1/*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 *
4 * Use of this software is governed by the MIT license
5 *
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
9
10#include <assert.h>
11#include <isl_map_private.h>
12#include "isl_equalities.h"
13#include <isl_seq.h>
14#include "isl_scan.h"
15#include <isl_mat_private.h>
16#include <isl_vec_private.h>
17
18/* The input of this program is the same as that of the "polytope_scan"
19 * program from the barvinok distribution.
20 *
21 * Constraints of set is PolyLib format.
22 *
23 * The input set is assumed to be bounded.
24 */
25
26struct scan_samples {
27 struct isl_scan_callback callback;
28 struct isl_mat *samples;
29};
30
31static isl_stat scan_samples_add_sample(struct isl_scan_callback *cb,
32 __isl_take isl_vec *sample)
33{
34 struct scan_samples *ss = (struct scan_samples *)cb;
35
36 ss->samples = isl_mat_extend(mat: ss->samples, n_row: ss->samples->n_row + 1,
37 n_col: ss->samples->n_col);
38 if (!ss->samples)
39 goto error;
40
41 isl_seq_cpy(dst: ss->samples->row[ss->samples->n_row - 1],
42 src: sample->el, len: sample->size);
43
44 isl_vec_free(vec: sample);
45 return isl_stat_ok;
46error:
47 isl_vec_free(vec: sample);
48 return isl_stat_error;
49}
50
51static __isl_give isl_mat *isl_basic_set_scan_samples(
52 __isl_take isl_basic_set *bset)
53{
54 isl_ctx *ctx;
55 isl_size dim;
56 struct scan_samples ss;
57
58 ctx = isl_basic_set_get_ctx(bset);
59 dim = isl_basic_set_dim(bset, type: isl_dim_all);
60 if (dim < 0)
61 goto error;
62 ss.callback.add = scan_samples_add_sample;
63 ss.samples = isl_mat_alloc(ctx, n_row: 0, n_col: 1 + dim);
64 if (!ss.samples)
65 goto error;
66
67 if (isl_basic_set_scan(bset, callback: &ss.callback) < 0) {
68 isl_mat_free(mat: ss.samples);
69 return NULL;
70 }
71
72 return ss.samples;
73error:
74 isl_basic_set_free(bset);
75 return NULL;
76}
77
78static __isl_give isl_mat *isl_basic_set_samples(__isl_take isl_basic_set *bset)
79{
80 struct isl_mat *T;
81 struct isl_mat *samples;
82
83 if (!bset)
84 return NULL;
85
86 if (bset->n_eq == 0)
87 return isl_basic_set_scan_samples(bset);
88
89 bset = isl_basic_set_remove_equalities(bset, T: &T, NULL);
90 samples = isl_basic_set_scan_samples(bset);
91 return isl_mat_product(left: samples, right: isl_mat_transpose(mat: T));
92}
93
94int main(int argc, char **argv)
95{
96 struct isl_ctx *ctx = isl_ctx_alloc();
97 struct isl_basic_set *bset;
98 struct isl_mat *samples;
99
100 bset = isl_basic_set_read_from_file(ctx, stdin);
101 samples = isl_basic_set_samples(bset);
102 isl_mat_print_internal(mat: samples, stdout, indent: 0);
103 isl_mat_free(mat: samples);
104 isl_ctx_free(ctx);
105
106 return 0;
107}
108

source code of polly/lib/External/isl/polytope_scan.c