From 17616dd24fc38f5711d1c2abd6f4b23466d02da9 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 4 Jan 2007 23:25:34 +0100 Subject: [PATCH] barvinok_enumerate_e: extract out verification options --- Makefile.am | 2 ++ barvinok_enumerate_e.cc | 78 ++++++------------------------------------- verify.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ verify.h | 20 +++++++++++ 4 files changed, 122 insertions(+), 67 deletions(-) create mode 100644 verify.c create mode 100644 verify.h diff --git a/Makefile.am b/Makefile.am index 341124e..e917b17 100644 --- a/Makefile.am +++ b/Makefile.am @@ -96,6 +96,8 @@ else BEEO_SOURCES = endif barvinok_enumerate_e_SOURCES = \ + verify.h \ + verify.c \ barvinok_enumerate_e.cc \ $(BEEO_SOURCES) barvinok_enumerate_e_CPPFLAGS = @OMEGA_CPPFLAGS@ $(AM_CPPFLAGS) diff --git a/barvinok_enumerate_e.cc b/barvinok_enumerate_e.cc index 6325808..c5f2f66 100644 --- a/barvinok_enumerate_e.cc +++ b/barvinok_enumerate_e.cc @@ -9,6 +9,7 @@ #ifdef HAVE_OMEGA #include "omega/convert.h" #endif +#include "verify.h" /* The input of this example program is a polytope in combined * data and parameter space followed by two lines indicating @@ -27,16 +28,12 @@ struct argp_option argp_options[] = { { "convert", 'c', 0, 0 }, { "floor", 'f', 0, 0 }, { "range-reduction", 'R', 0, 0 }, - { "verify", 'T', 0, 0 }, - { "print-all", 'A', 0, 0 }, - { "min", 'm', "int", 0 }, - { "max", 'M', "int", 0 }, - { "range", 'r', "int", 0 }, { 0 } }; struct arguments { struct barvinok_options *options; + struct verify_options verify; int range; int convert; int omega; @@ -44,10 +41,6 @@ struct arguments { int scarf; int series; int floor; - int verify; - int print_all; - int m; - int M; }; error_t parse_opt(int key, char *arg, struct argp_state *state) @@ -57,6 +50,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) switch (key) { case ARGP_KEY_INIT: state->child_inputs[0] = arguments->options; + state->child_inputs[1] = &arguments->verify; break; case 's': arguments->series = 1; @@ -87,25 +81,6 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) case 'R': arguments->range = 1; break; - case 'T': - arguments->verify = 1; - break; - case 'A': - arguments->print_all = 1; - break; - case 'm': - arguments->m = atoi(arg); - arguments->verify = 1; - break; - case 'M': - arguments->M = atoi(arg); - arguments->verify = 1; - break; - case 'r': - arguments->M = atoi(arg); - arguments->m = -arguments->M; - arguments->verify = 1; - break; default: return ARGP_ERR_UNKNOWN; } @@ -134,21 +109,6 @@ Polyhedron *Omega_simplify(Polyhedron *P, /* define this to continue the test after first error found */ /* #define DONT_BREAK_ON_ERROR */ -/* RANGE : normal range for evalutations (-RANGE -> RANGE) */ -#define RANGE 50 - -/* SRANGE : small range for evalutations */ -#define SRANGE 15 - -/* if dimension >= BIDDIM, use SRANGE */ -#define BIGDIM 5 - -/* VSRANGE : very small range for evalutations */ -#define VSRANGE 5 - -/* if dimension >= VBIDDIM, use VSRANGE */ -#define VBIGDIM 8 - static Value min_val, max_val; static char **params; @@ -169,10 +129,10 @@ int main(int argc, char **argv) char s[128]; evalue *EP; int print_solution = 1; - int r; struct arguments arguments; static struct argp_child argp_children[] = { - { &barvinok_argp, 0, 0, 0 }, + { &barvinok_argp, 0, 0, 0 }, + { &verify_argp, 0, "verification", 1 }, { 0 } }; static struct argp argp = { argp_options, parse_opt, 0, 0, argp_children }; @@ -186,10 +146,6 @@ int main(int argc, char **argv) arguments.scarf = 0; arguments.series = 0; arguments.floor = 0; - arguments.verify = 0; - arguments.print_all = 0; - arguments.m = INT_MAX; - arguments.M = INT_MIN; argp_parse(&argp, argc, argv, 0, 0, &arguments); @@ -212,22 +168,9 @@ int main(int argc, char **argv) fgets(s, 128, stdin); /******* Read the options: initialize Min and Max ********/ - if (A->Dimension >= VBIGDIM) - r = VSRANGE; - else if (A->Dimension >= BIGDIM) - r = SRANGE; - else - r = RANGE; - if (arguments.M == INT_MIN) - arguments.M = r; - if (arguments.m == INT_MAX) - arguments.m = -r; + verify_options_set_range(&arguments.verify, A); - if (arguments.verify && arguments.m > arguments.M) { - fprintf(stderr,"Nothing to do: min > max !\n"); - return(0); - } - if (arguments.verify) + if (arguments.verify.verify) print_solution = 0; if (print_solution) { @@ -277,9 +220,10 @@ int main(int argc, char **argv) if (print_solution) print_evalue(stdout, EP, param_name); } - if (arguments.verify) - verify_results(A, EP, exist, nparam, arguments.m, arguments.M, - arguments.print_all, options->MaxRays); + if (arguments.verify.verify) + verify_results(A, EP, exist, nparam, arguments.verify.m, + arguments.verify.M, arguments.verify.print_all, + options->MaxRays); free_evalue_refs(EP); free(EP); } diff --git a/verify.c b/verify.c new file mode 100644 index 0000000..b1806cc --- /dev/null +++ b/verify.c @@ -0,0 +1,89 @@ +#include +#include "verify.h" + +/* RANGE : normal range for evalutations (-RANGE -> RANGE) */ +#define RANGE 50 + +/* SRANGE : small range for evalutations */ +#define SRANGE 15 + +/* if dimension >= BIDDIM, use SRANGE */ +#define BIGDIM 5 + +/* VSRANGE : very small range for evalutations */ +#define VSRANGE 5 + +/* if dimension >= VBIDDIM, use VSRANGE */ +#define VBIGDIM 8 + +static struct argp_option argp_options[] = { + { "verify", 'T', 0, 0 }, + { "print-all", 'A', 0, 0 }, + { "min", 'm', "int", 0 }, + { "max", 'M', "int", 0 }, + { "range", 'r', "int", 0 }, + { 0 } +}; + +static error_t parse_opt(int key, char *arg, struct argp_state *state) +{ + struct verify_options *options = state->input; + + switch (key) { + case ARGP_KEY_INIT: + options->verify = 0; + options->print_all = 0; + options->m = INT_MAX; + options->M = INT_MIN; + break; + case ARGP_KEY_FINI: + break; + case 'T': + options->verify = 1; + break; + case 'A': + options->print_all = 1; + break; + case 'm': + options->m = atoi(arg); + options->verify = 1; + break; + case 'M': + options->M = atoi(arg); + options->verify = 1; + break; + case 'r': + options->M = atoi(arg); + options->m = -options->M; + options->verify = 1; + break; + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +void verify_options_set_range(struct verify_options *options, Polyhedron *P) +{ + int r; + + if (P->Dimension >= VBIGDIM) + r = VSRANGE; + else if (P->Dimension >= BIGDIM) + r = SRANGE; + else + r = RANGE; + if (options->M == INT_MIN) + options->M = r; + if (options->m == INT_MAX) + options->m = -r; + + if (options->verify && options->m > options->M) { + fprintf(stderr,"Nothing to do: min > max !\n"); + exit(0); + } +} + +struct argp verify_argp = { + argp_options, parse_opt, 0, 0 +}; diff --git a/verify.h b/verify.h new file mode 100644 index 0000000..6209db8 --- /dev/null +++ b/verify.h @@ -0,0 +1,20 @@ +#include +#include "argp.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +struct verify_options { + int verify; + int print_all; + int m; + int M; +}; + +extern struct argp verify_argp; +void verify_options_set_range(struct verify_options *options, Polyhedron *P); + +#if defined(__cplusplus) +} +#endif -- 2.11.4.GIT