From f9ab3991f7de5de150eacbc645a3983044e507bb Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 18 Mar 2007 22:18:52 +0100 Subject: [PATCH] reorganize polynomial approximation options --- barvinok.cc | 33 ++++++++++++++++++--------------- barvinok/options.h | 17 ++++++++++------- options.c | 49 +++++++++++++++++++++++++++++++++++-------------- verif_ehrhart.c | 6 +++--- 4 files changed, 66 insertions(+), 39 deletions(-) diff --git a/barvinok.cc b/barvinok.cc index 68a1a21..6ec7122 100644 --- a/barvinok.cc +++ b/barvinok.cc @@ -1708,10 +1708,12 @@ constant: eres = barvinok_enumerate_cst(P, CEq ? CEq : Polyhedron_Copy(C), options); out: emul(&factor, eres); - if (options->polynomial_approximation == BV_POLAPPROX_UPPER) - evalue_frac2polynomial(eres, 1, options->MaxRays); - if (options->polynomial_approximation == BV_POLAPPROX_LOWER) - evalue_frac2polynomial(eres, -1, options->MaxRays); + if (options->approximation_method == BV_APPROX_DROP) { + if (options->polynomial_approximation == BV_APPROX_SIGN_UPPER) + evalue_frac2polynomial(eres, 1, options->MaxRays); + if (options->polynomial_approximation == BV_APPROX_SIGN_LOWER) + evalue_frac2polynomial(eres, -1, options->MaxRays); + } reduce_evalue(eres); free_evalue_refs(&factor); Domain_Free(P); @@ -1855,8 +1857,7 @@ static evalue* barvinok_enumerate_ev_f(Polyhedron *P, Polyhedron* C, barvinok_options *options) { unsigned nparam = C->Dimension; - bool pre_approx = options->polynomial_approximation >= BV_POLAPPROX_PRE_LOWER && - options->polynomial_approximation <= BV_POLAPPROX_PRE_APPROX; + bool pre_approx = options->approximation_method == BV_APPROX_SCALE; if (P->Dimension - nparam == 1 && !pre_approx) return ParamLine_Length(P, C, options); @@ -1871,15 +1872,17 @@ static evalue* barvinok_enumerate_ev_f(Polyhedron *P, Polyhedron* C, Value det; Polyhedron *T; - if (options->polynomial_approximation == BV_POLAPPROX_PRE_UPPER) - P = Polyhedron_Inflate(P, nparam, options->MaxRays); - if (options->polynomial_approximation == BV_POLAPPROX_PRE_LOWER) { - P = Polyhedron_Deflate(P, nparam, options->MaxRays); - POL_ENSURE_VERTICES(P); - if (emptyQ(P)) { - eres = barvinok_enumerate_cst(P, Polyhedron_Copy(C), options); - Polyhedron_Free(P); - return eres; + if (options->approximation_method == BV_APPROX_SCALE) { + if (options->polynomial_approximation == BV_APPROX_SIGN_UPPER) + P = Polyhedron_Inflate(P, nparam, options->MaxRays); + if (options->polynomial_approximation == BV_APPROX_SIGN_LOWER) { + P = Polyhedron_Deflate(P, nparam, options->MaxRays); + POL_ENSURE_VERTICES(P); + if (emptyQ(P)) { + eres = barvinok_enumerate_cst(P, Polyhedron_Copy(C), options); + Polyhedron_Free(P); + return eres; + } } } diff --git a/barvinok/options.h b/barvinok/options.h index 8e978b0..0cda29e 100644 --- a/barvinok/options.h +++ b/barvinok/options.h @@ -39,13 +39,15 @@ struct barvinok_options { int lookup_table; int count_sample_infinite; - #define BV_POLAPPROX_NONE 0 - #define BV_POLAPPROX_PRE_LOWER 1 - #define BV_POLAPPROX_PRE_UPPER 2 - #define BV_POLAPPROX_PRE_APPROX 3 - #define BV_POLAPPROX_LOWER 4 - #define BV_POLAPPROX_UPPER 5 + #define BV_APPROX_SIGN_NONE 0 + #define BV_APPROX_SIGN_APPROX 1 + #define BV_APPROX_SIGN_LOWER 2 + #define BV_APPROX_SIGN_UPPER 3 int polynomial_approximation; + #define BV_APPROX_NONE 0 + #define BV_APPROX_DROP 1 + #define BV_APPROX_SCALE 2 + int approximation_method; /* basis reduction options */ #define BV_GBR_NONE 0 @@ -75,7 +77,8 @@ void barvinok_options_free(struct barvinok_options *options); #define BV_OPT_GBR 259 #define BV_OPT_MAXINDEX 260 #define BV_OPT_POLAPPROX 261 -#define BV_OPT_LAST 261 +#define BV_OPT_APPROX 262 +#define BV_OPT_LAST 262 struct argp; extern struct argp barvinok_argp; diff --git a/options.c b/options.c index 17d930b..9013ccd 100644 --- a/options.c +++ b/options.c @@ -68,7 +68,8 @@ struct barvinok_options *barvinok_options_new_with_defaults() options->count_sample_infinite = 0; #endif - options->polynomial_approximation = BV_POLAPPROX_NONE; + options->polynomial_approximation = BV_APPROX_SIGN_NONE; + options->approximation_method = BV_APPROX_NONE; #ifdef HAVE_LIBGLPK options->gbr_lp_solver = BV_GBR_GLPK; @@ -97,9 +98,9 @@ struct argp_option barvinok_argp_options[] = { { "primal", BV_OPT_PRIMAL, 0, 0 }, { "table", BV_OPT_TABLE, 0, 0 }, { "specialization", BV_OPT_SPECIALIZATION, "[bf|df|random]", 0 }, - { "polynomial-approximation", - BV_OPT_POLAPPROX, - "lower|upper|pre-lower|pre-upper|pre-approx", 0 }, + { "polynomial-approximation", BV_OPT_POLAPPROX, "lower|upper", 1 }, + { "approximation-method", BV_OPT_APPROX, "scale|drop", 0, + "method to use in polynomial approximation [default: drop]" }, { "gbr", BV_OPT_GBR, "[cdd]", 0, "solver to use for basis reduction" }, { "version", 'V', 0, 0 }, @@ -136,16 +137,36 @@ error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state) options->max_index = strtoul(arg, NULL, 0); break; case BV_OPT_POLAPPROX: - if (!strcmp(arg, "pre-lower")) - options->polynomial_approximation = BV_POLAPPROX_PRE_LOWER; - else if (!strcmp(arg, "pre-upper")) - options->polynomial_approximation = BV_POLAPPROX_PRE_UPPER; - else if (!strcmp(arg, "pre-approx")) - options->polynomial_approximation = BV_POLAPPROX_PRE_APPROX; - else if (!strcmp(arg, "lower")) - options->polynomial_approximation = BV_POLAPPROX_LOWER; - else if (!strcmp(arg, "upper")) - options->polynomial_approximation = BV_POLAPPROX_UPPER; + if (!arg) { + options->polynomial_approximation = BV_APPROX_SIGN_APPROX; + if (options->approximation_method == BV_APPROX_NONE) + options->approximation_method = BV_APPROX_SCALE; + } else { + if (!strcmp(arg, "lower")) + options->polynomial_approximation = BV_APPROX_SIGN_LOWER; + else if (!strcmp(arg, "upper")) + options->polynomial_approximation = BV_APPROX_SIGN_UPPER; + if (options->approximation_method == BV_APPROX_NONE) + options->approximation_method = BV_APPROX_DROP; + } + break; + case BV_OPT_APPROX: + if (!strcmp(arg, "scale")) + options->approximation_method = BV_APPROX_SCALE; + else if (!strcmp(arg, "drop")) + options->approximation_method = BV_APPROX_DROP; + break; + case ARGP_KEY_END: + if (options->polynomial_approximation == BV_APPROX_SIGN_APPROX && + options->approximation_method == BV_APPROX_DROP) + argp_error(state, + "drop method only available for lower and upper bounds"); + if (options->polynomial_approximation == BV_APPROX_SIGN_NONE && + options->approximation_method != BV_APPROX_NONE) { + fprintf(stderr, + "no polynomial approximation selected; reseting approximation method\n"); + options->approximation_method = BV_APPROX_NONE; + } break; default: return ARGP_ERR_UNKNOWN; diff --git a/verif_ehrhart.c b/verif_ehrhart.c index 1400398..3afc382 100644 --- a/verif_ehrhart.c +++ b/verif_ehrhart.c @@ -78,12 +78,12 @@ static int cp_EP(const struct check_poly_data *data, int nparam, Value *z, printf(". "); } - if (pa == BV_POLAPPROX_PRE_APPROX) + if (pa == BV_APPROX_SIGN_APPROX) /* just accept everything */ ok = 1; - else if (pa == BV_POLAPPROX_PRE_LOWER || pa == BV_POLAPPROX_LOWER) + else if (pa == BV_APPROX_SIGN_LOWER) ok = value_le(c, tmp); - else if (pa == BV_POLAPPROX_PRE_UPPER || pa == BV_POLAPPROX_UPPER) + else if (pa == BV_APPROX_SIGN_UPPER) ok = value_ge(c, tmp); else ok = value_eq(c, tmp); -- 2.11.4.GIT