+/*
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ *
+ * Use of this software is governed by the GNU LGPLv2.1 license
+ *
+ * Written by Sven Verdoolaege, K.U.Leuven, Departement
+ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
+ */
+
#include "isl_sample.h"
#include "isl_sample_piplib.h"
#include "isl_vec.h"
#include "isl_equalities.h"
#include "isl_tab.h"
#include "isl_basis_reduction.h"
+#include <isl_point_private.h>
static struct isl_vec *empty_sample(struct isl_basic_set *bset)
{
if (!tab)
return NULL;
- isl_assert(tab->mat->ctx, tab->bset, return NULL);
- bset = tab->bset;
+ bset = isl_tab_peek_bset(tab);
+ isl_assert(tab->mat->ctx, bset, return NULL);
n_eq = tab->n_var - tab->n_col + tab->n_dead;
if (tab->empty || n_eq == 0)
*
* The initial basis is the identity matrix. If the range in some direction
* contains more than one integer value, we perform basis reduction based
- * on the value of ctx->gbr
+ * on the value of ctx->opt->gbr
* - ISL_GBR_NEVER: never perform basis reduction
* - ISL_GBR_ONCE: only perform basis reduction the first
* time such a range is encountered
* - ISL_GBR_ALWAYS: always perform basis reduction when
* such a range is encountered
*
- * When ctx->gbr is set to ISL_GBR_ALWAYS, then we allow the basis
+ * When ctx->opt->gbr is set to ISL_GBR_ALWAYS, then we allow the basis
* reduction computation to return early. That is, as soon as it
* finds a reasonable first direction.
*/
ctx = tab->mat->ctx;
dim = tab->n_var;
- gbr = ctx->gbr;
+ gbr = ctx->opt->gbr;
if (tab->n_unbounded == tab->n_var) {
sample = isl_tab_get_sample_value(tab);
goto error;
if (!empty && isl_tab_sample_is_integer(tab))
break;
- if (!empty && !reduced && ctx->gbr != ISL_GBR_NEVER &&
+ if (!empty && !reduced &&
+ ctx->opt->gbr != ISL_GBR_NEVER &&
isl_int_lt(min->el[level], max->el[level])) {
unsigned gbr_only_first;
- if (ctx->gbr == ISL_GBR_ONCE)
- ctx->gbr = ISL_GBR_NEVER;
+ if (ctx->opt->gbr == ISL_GBR_ONCE)
+ ctx->opt->gbr = ISL_GBR_NEVER;
tab->n_zero = level;
- gbr_only_first = ctx->gbr_only_first;
- ctx->gbr_only_first =
- ctx->gbr == ISL_GBR_ALWAYS;
+ gbr_only_first = ctx->opt->gbr_only_first;
+ ctx->opt->gbr_only_first =
+ ctx->opt->gbr == ISL_GBR_ALWAYS;
tab = isl_tab_compute_reduced_basis(tab);
- ctx->gbr_only_first = gbr_only_first;
+ ctx->opt->gbr_only_first = gbr_only_first;
if (!tab || !tab->basis)
goto error;
reduced = 1;
level--;
init = 0;
if (level >= 0)
- isl_tab_rollback(tab, snap[level]);
+ if (isl_tab_rollback(tab, snap[level]) < 0)
+ goto error;
continue;
}
isl_int_neg(tab->basis->row[1 + level][0], min->el[level]);
} else
sample = isl_vec_alloc(ctx, 0);
- ctx->gbr = gbr;
+ ctx->opt->gbr = gbr;
isl_vec_free(min);
isl_vec_free(max);
free(snap);
return sample;
error:
- ctx->gbr = gbr;
+ ctx->opt->gbr = gbr;
isl_vec_free(min);
isl_vec_free(max);
free(snap);
ctx = bset->ctx;
tab = isl_tab_from_basic_set(bset);
+ if (tab && tab->empty) {
+ isl_tab_free(tab);
+ ISL_F_SET(bset, ISL_BASIC_SET_EMPTY);
+ sample = isl_vec_alloc(bset->ctx, 0);
+ isl_basic_set_free(bset);
+ return sample;
+ }
+
+ if (isl_tab_track_bset(tab, isl_basic_set_copy(bset)) < 0)
+ goto error;
if (!ISL_F_ISSET(bset, ISL_BASIC_SET_NO_IMPLICIT))
tab = isl_tab_detect_implicit_equalities(tab);
if (!tab)
goto error;
- tab->bset = isl_basic_set_copy(bset);
-
sample = isl_tab_sample(tab);
if (!sample)
goto error;
isl_int_init(v);
if (!tab || !tab_cone || !U)
goto error;
- bset = tab_cone->bset;
+ bset = isl_tab_peek_bset(tab_cone);
U = isl_mat_drop_cols(U, 0, tab->n_var - tab->n_unbounded);
for (i = 0; i < bset->n_ineq; ++i) {
+ int ok;
struct isl_vec *row = NULL;
if (isl_tab_is_equality(tab_cone, tab_cone->n_eq + i))
continue;
continue;
tab = isl_tab_extend(tab, 1);
isl_int_add(bset->ineq[i][0], bset->ineq[i][0], v);
- tab = isl_tab_add_ineq(tab, bset->ineq[i]);
+ ok = isl_tab_add_ineq(tab, bset->ineq[i]) >= 0;
isl_int_sub(bset->ineq[i][0], bset->ineq[i][0], v);
- if (!tab)
+ if (!ok)
goto error;
}
if (dim == 1)
return interval_sample(bset);
- switch (bset->ctx->ilp_solver) {
+ switch (bset->ctx->opt->ilp_solver) {
case ISL_ILP_PIP:
return pip_sample(bset);
case ISL_ILP_GBR:
{
return (isl_basic_set *) isl_map_sample((isl_map *)set);
}
+
+__isl_give isl_point *isl_basic_set_sample_point(__isl_take isl_basic_set *bset)
+{
+ isl_vec *vec;
+ isl_dim *dim;
+
+ dim = isl_basic_set_get_dim(bset);
+ bset = isl_basic_set_underlying_set(bset);
+ vec = isl_basic_set_sample_vec(bset);
+
+ return isl_point_alloc(dim, vec);
+}
+
+__isl_give isl_point *isl_set_sample_point(__isl_take isl_set *set)
+{
+ int i;
+ isl_point *pnt;
+
+ if (!set)
+ return NULL;
+
+ for (i = 0; i < set->n; ++i) {
+ pnt = isl_basic_set_sample_point(isl_basic_set_copy(set->p[i]));
+ if (!pnt)
+ goto error;
+ if (!isl_point_is_void(pnt))
+ break;
+ isl_point_free(pnt);
+ }
+ if (i == set->n)
+ pnt = isl_point_void(isl_set_get_dim(set));
+
+ isl_set_free(set);
+ return pnt;
+error:
+ isl_set_free(set);
+ return NULL;
+}