From 67497edd0ff3657eab38d3b71b3fff7131c0f412 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 7 Mar 2009 23:24:40 +0100 Subject: [PATCH] isl_solve_lp: accept affine object function instead of linear function --- isl_convex_hull.c | 22 +++++++++------------- isl_lp.c | 10 ++++++++++ isl_lp_piplib.c | 3 ++- isl_map.c | 8 ++++---- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/isl_convex_hull.c b/isl_convex_hull.c index b1aa2df..02a6e34 100644 --- a/isl_convex_hull.c +++ b/isl_convex_hull.c @@ -50,7 +50,7 @@ int isl_basic_map_constraint_is_redundant(struct isl_basic_map **bmap, if (i < total) return 0; - res = isl_solve_lp(*bmap, 0, c+1, (*bmap)->ctx->one, opt_n, opt_d); + res = isl_solve_lp(*bmap, 0, c, (*bmap)->ctx->one, opt_n, opt_d); if (res == isl_lp_unbounded) return 0; if (res == isl_lp_error) @@ -59,10 +59,6 @@ int isl_basic_map_constraint_is_redundant(struct isl_basic_map **bmap, *bmap = isl_basic_map_set_to_empty(*bmap); return 0; } - if (opt_d) - isl_int_addmul(*opt_n, *opt_d, c[0]); - else - isl_int_add(*opt_n, *opt_n, c[0]); return !isl_int_is_neg(*opt_n); } @@ -134,7 +130,7 @@ static int uset_is_bound(struct isl_ctx *ctx, struct isl_set *set, continue; res = isl_solve_lp((struct isl_basic_map*)set->p[j], - 0, c+1, ctx->one, &opt, &opt_denom); + 0, c, ctx->one, &opt, &opt_denom); if (res == isl_lp_unbounded) break; if (res == isl_lp_error) @@ -147,13 +143,12 @@ static int uset_is_bound(struct isl_ctx *ctx, struct isl_set *set, } if (!isl_int_is_one(opt_denom)) isl_seq_scale(c, c, opt_denom, len); - if (first || isl_int_lt(opt, c[0])) - isl_int_set(c[0], opt); + if (first || isl_int_is_neg(opt)) + isl_int_sub(c[0], c[0], opt); first = 0; } isl_int_clear(opt); isl_int_clear(opt_denom); - isl_int_neg(c[0], c[0]); return j >= set->n; error: isl_int_clear(opt); @@ -482,13 +477,14 @@ static isl_int *wrap_facet(struct isl_set *set, isl_int *facet, isl_int *ridge) if (!set) goto error; lp = wrap_constraints(set); - obj = isl_vec_alloc(set->ctx, dim*set->n); + obj = isl_vec_alloc(set->ctx, 1 + dim*set->n); if (!obj) goto error; + isl_int_set_si(obj->block.data[0], 0); for (i = 0; i < set->n; ++i) { - isl_seq_clr(obj->block.data+dim*i, 2); - isl_int_set_si(obj->block.data[dim*i+2], 1); - isl_seq_clr(obj->block.data+dim*i+3, dim-3); + isl_seq_clr(obj->block.data + 1 + dim*i, 2); + isl_int_set_si(obj->block.data[1 + dim*i+2], 1); + isl_seq_clr(obj->block.data + 1 + dim*i+3, dim-3); } isl_int_init(num); isl_int_init(den); diff --git a/isl_lp.c b/isl_lp.c index acecd22..08401a1 100644 --- a/isl_lp.c +++ b/isl_lp.c @@ -2,6 +2,16 @@ #include "isl_lp.h" #include "isl_lp_piplib.h" +/* Given a basic map "bmap" and an affine combination of the variables "f" + * with denominator "denom", set *opt/*opt_denom to the minimal + * (or maximal if "maximize" is true) value attained by f/d over "bmap", + * assuming the basic map is not empty and the expression cannot attain + * arbitrarily small (or large) values. + * If opt_denom is NULL, then *opt is rounded up (or down) + * to the nearest integer. + * The return value reflects the nature of the result (empty, unbounded, + * minmimal or maximal value returned in *opt). + */ enum isl_lp_result isl_solve_lp(struct isl_basic_map *bmap, int maximize, isl_int *f, isl_int denom, isl_int *opt, isl_int *opt_denom) diff --git a/isl_lp_piplib.c b/isl_lp_piplib.c index 609093a..b4e9bd9 100644 --- a/isl_lp_piplib.c +++ b/isl_lp_piplib.c @@ -18,7 +18,8 @@ enum isl_lp_result isl_pip_solve_lp(struct isl_basic_map *bmap, int maximize, if (!domain) goto error; entier_set_si(domain->p[0][1], -1); - isl_seq_cpy_to_pip(domain->p[0]+2, f, total); + isl_int_set(domain->p[0][domain->NbColumns - 1], f[0]); + isl_seq_cpy_to_pip(domain->p[0]+2, f+1, total); options = pip_options_init(); if (!options) diff --git a/isl_map.c b/isl_map.c index d5bc808..cba9f28 100644 --- a/isl_map.c +++ b/isl_map.c @@ -3895,10 +3895,10 @@ int isl_basic_set_compare_at(struct isl_basic_set *bset1, goto error; total = isl_basic_map_total_dim(bmap1); ctx = bmap1->ctx; - obj = isl_vec_alloc(ctx, total); - isl_seq_clr(obj->block.data, total); - isl_int_set_si(obj->block.data[nparam+pos], 1); - isl_int_set_si(obj->block.data[nparam+pos+(dim1-pos)], -1); + obj = isl_vec_alloc(ctx, 1 + total); + isl_seq_clr(obj->block.data, 1 + total); + isl_int_set_si(obj->block.data[1+nparam+pos], 1); + isl_int_set_si(obj->block.data[1+nparam+pos+(dim1-pos)], -1); if (!obj) goto error; isl_int_init(num); -- 2.7.4