#include <assert.h>
#include <string.h>
-#include "isl_set.h"
+#include <isl_map_private.h>
+#include <isl/set.h>
#include "isl_tab.h"
-#include "isl_map_private.h"
#include "isl_sample.h"
#include "isl_scan.h"
-#include "isl_seq.h"
-#include "isl_ilp.h"
+#include <isl/seq.h>
+#include <isl/ilp.h>
+#include <isl_point_private.h>
/* The input of this program is the same as that of the "example" program
* from the PipLib distribution, except that the "big parameter column"
* Urs_unknowns don't assume unknowns are non-negative
*/
-struct pip_options {
+struct options {
struct isl_options *isl;
unsigned verify;
};
-struct isl_arg pip_options_arg[] = {
-ISL_ARG_CHILD(struct pip_options, isl, "isl", isl_options_arg)
-ISL_ARG_BOOL(struct pip_options, verify, 'T', "verify", 0)
+struct isl_arg options_arg[] = {
+ISL_ARG_CHILD(struct options, isl, "isl", isl_options_arg, "isl options")
+ISL_ARG_BOOL(struct options, verify, 'T', "verify", 0, NULL)
+ISL_ARG_END
};
-ISL_ARG_DEF(pip_options, struct pip_options, pip_options_arg)
+ISL_ARG_DEF(options, struct options, options_arg)
-static struct isl_basic_set *to_parameter_domain(struct isl_basic_set *context)
+static __isl_give isl_basic_set *set_bounds(__isl_take isl_basic_set *bset)
{
- struct isl_dim *param_dim;
- struct isl_basic_set *model;
+ unsigned nparam;
+ int i, r;
+ isl_point *pt, *pt2;
+ isl_basic_set *box;
- param_dim = isl_dim_set_alloc(context->ctx,
- isl_basic_set_n_dim(context), 0);
- model = isl_basic_set_empty(param_dim);
- context = isl_basic_set_from_underlying_set(context, model);
+ nparam = isl_basic_set_dim(bset, isl_dim_param);
+ r = nparam >= 8 ? 4 : nparam >= 5 ? 6 : 30;
- return context;
-}
+ pt = isl_basic_set_sample_point(isl_basic_set_copy(bset));
+ pt2 = isl_point_copy(pt);
-static isl_basic_set *construct_cube(isl_basic_set *context)
-{
- int i;
- unsigned dim;
- int range;
- isl_int m, M;
- struct isl_basic_set *cube;
- struct isl_basic_set *interval;
- struct isl_basic_set_list *list;
-
- dim = isl_basic_set_total_dim(context);
- if (dim == 0) {
- struct isl_dim *dims;
- dims = isl_dim_set_alloc(context->ctx, 0, 0);
- return isl_basic_set_universe(dims);
+ for (i = 0; i < nparam; ++i) {
+ pt = isl_point_add_ui(pt, isl_dim_param, i, r);
+ pt2 = isl_point_sub_ui(pt2, isl_dim_param, i, r);
}
- if (dim >= 8)
- range = 4;
- else if (dim >= 5)
- range = 6;
- else
- range = 30;
-
- isl_int_init(m);
- isl_int_init(M);
+ box = isl_basic_set_box_from_points(pt, pt2);
- isl_int_set_si(m, -range);
- isl_int_set_si(M, range);
-
- interval = isl_basic_set_interval(context->ctx, m, M);
- list = isl_basic_set_list_alloc(context->ctx, dim);
- for (i = 0; i < dim; ++i)
- list = isl_basic_set_list_add(list, isl_basic_set_copy(interval));
- isl_basic_set_free(interval);
- cube = isl_basic_set_product(list);
-
- isl_int_clear(m);
- isl_int_clear(M);
+ return isl_basic_set_intersect(bset, box);
+}
- return cube;
+static struct isl_basic_set *to_parameter_domain(struct isl_basic_set *context)
+{
+ return isl_basic_set_move_dims(context, isl_dim_param, 0, isl_dim_set, 0,
+ isl_basic_set_dim(context, isl_dim_set));
}
isl_basic_set *plug_in_parameters(isl_basic_set *bset, struct isl_vec *params)
bset = isl_basic_set_fix(bset,
isl_dim_param, i, params->el[1 + i]);
- bset = isl_basic_set_remove(bset, isl_dim_param, 0, params->size - 1);
+ bset = isl_basic_set_remove_dims(bset,
+ isl_dim_param, 0, params->size - 1);
isl_vec_free(params);
for (i = 0; i < params->size - 1; ++i)
set = isl_set_fix(set, isl_dim_param, i, params->el[1 + i]);
- set = isl_set_remove(set, isl_dim_param, 0, params->size - 1);
+ set = isl_set_remove_dims(set, isl_dim_param, 0, params->size - 1);
isl_vec_free(params);
bset = plug_in_parameters(bset, params);
- if (isl_basic_set_fast_is_empty(bset)) {
+ if (isl_basic_set_plain_is_empty(bset)) {
opt = isl_vec_alloc(bset->ctx, 0);
isl_basic_set_free(bset);
return opt;
struct isl_scan_pip *sp = (struct isl_scan_pip *)callback;
struct isl_vec *opt;
+ sp->n--;
+
opt = opt_at(isl_basic_set_copy(sp->bset), isl_vec_copy(sample), sp->max);
assert(opt);
if (opt->size == 0) {
- isl_set *sample_set;
- sample_set = isl_set_from_basic_set(
- isl_basic_set_from_vec(sample));
- assert(isl_set_is_subset(sample_set, sp->empty));
- isl_set_free(sample_set);
+ isl_point *sample_pnt;
+ sample_pnt = isl_point_alloc(isl_set_get_dim(sp->empty), sample);
+ assert(isl_set_contains_point(sp->empty, sample_pnt));
+ isl_point_free(sample_pnt);
isl_vec_free(opt);
} else {
isl_set *sol;
isl_set_free(opt_set);
}
- if (!(sp->n++ % sp->stride)) {
+ if (!(sp->n % sp->stride)) {
printf("o");
fflush(stdout);
}
- return 0;
-}
-
-struct isl_scan_count {
- struct isl_scan_callback callback;
- int n;
-};
-
-static int count_one(struct isl_scan_callback *callback,
- __isl_take isl_vec *sample)
-{
- struct isl_scan_count *sc = (struct isl_scan_count *)callback;
- isl_vec_free(sample);
-
- sc->n++;
-
- return 0;
+ return sp->n >= 1 ? 0 : -1;
}
static void check_solution(isl_basic_set *bset, isl_basic_set *context,
isl_set *sol, isl_set *empty, int max)
{
- isl_basic_set *cube;
- struct isl_scan_count sc;
struct isl_scan_pip sp;
- int i;
+ isl_int count, count_max;
+ int i, n;
int r;
+ context = set_bounds(context);
context = isl_basic_set_underlying_set(context);
- cube = construct_cube(context);
- context = isl_basic_set_intersect(context, cube);
+ isl_int_init(count);
+ isl_int_init(count_max);
- sc.callback.add = count_one;
- sc.n = 0;
+ isl_int_set_si(count_max, 2000);
+ r = isl_basic_set_count_upto(context, count_max, &count);
+ assert(r >= 0);
+ n = isl_int_get_si(count);
- r = isl_basic_set_scan(isl_basic_set_copy(context), &sc.callback);
- assert (r == 0);
+ isl_int_clear(count_max);
+ isl_int_clear(count);
sp.callback.add = scan_one;
sp.bset = bset;
sp.sol = sol;
sp.empty = empty;
- sp.n = 0;
- sp.stride = sc.n > 70 ? 1 + (sc.n + 1)/70 : 1;
+ sp.n = n;
+ sp.stride = n > 70 ? 1 + (n + 1)/70 : 1;
sp.max = max;
- for (i = 0; i < sc.n; i += sp.stride)
+ for (i = 0; i < n; i += sp.stride)
printf(".");
printf("\r");
fflush(stdout);
- r = isl_basic_set_scan(context, &sp.callback);
- assert(r == 0);
+ isl_basic_set_scan(context, &sp.callback);
printf("\n");
int max = 0;
int rational = 0;
int n;
- struct pip_options *options;
+ struct options *options;
- options = pip_options_new_with_defaults();
+ options = options_new_with_defaults();
assert(options);
- argc = pip_options_parse(options, argc, argv);
+ argc = options_parse(options, argc, argv, ISL_ARG_ALL);
- ctx = isl_ctx_alloc_with_options(options->isl);
- options->isl = NULL;
+ ctx = isl_ctx_alloc_with_options(options_arg, options);
context = isl_basic_set_read_from_file(ctx, stdin, 0);
assert(context);
assert(!rational);
check_solution(copy, context_copy, set, empty, max);
} else {
- isl_set_dump(set, stdout, 0);
- fprintf(stdout, "no solution:\n");
- isl_set_dump(empty, stdout, 4);
+ isl_set_print(set, stdout, 0, ISL_FORMAT_ISL);
+ fprintf(stdout, "\n");
+ fprintf(stdout, "no solution: ");
+ isl_set_print(empty, stdout, 0, ISL_FORMAT_ISL);
+ fprintf(stdout, "\n");
}
isl_set_free(set);
isl_set_free(empty);
isl_ctx_free(ctx);
- free(options);
return 0;
}