fix merge of check_poly from verif_ehrhart.c and lexmin.cc
[barvinok.git] / options.c
blob17d930b12dcef1a31025c84f045c1814324b1b3d
1 #include <unistd.h>
2 #include <barvinok/options.h>
3 #include <barvinok/util.h>
4 #include "argp.h"
5 #include "config.h"
7 #ifdef HAVE_GROWING_CHERNIKOVA
8 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
9 #else
10 #define MAXRAYS 600
11 #endif
13 #ifndef HAVE_LIBGLPK
14 Vector *Polyhedron_Sample(Polyhedron *P, struct barvinok_options *options)
16 assert(0);
18 #endif
20 #define ALLOC(type) (type*)malloc(sizeof(type))
22 void barvinok_stats_clear(struct barvinok_stats *stats)
24 stats->base_cones = 0;
27 void barvinok_stats_print(struct barvinok_stats *stats, FILE *out)
29 fprintf(out, "Base cones: %d\n", stats->base_cones);
32 struct barvinok_options *barvinok_options_new_with_defaults()
34 struct barvinok_options *options = ALLOC(struct barvinok_options);
35 if (!options)
36 return NULL;
38 options->stats = ALLOC(struct barvinok_stats);
39 if (!options->stats) {
40 free(options);
41 return NULL;
44 barvinok_stats_clear(options->stats);
46 options->LLL_a = 1;
47 options->LLL_b = 1;
49 options->MaxRays = MAXRAYS;
51 #ifdef USE_INCREMENTAL_BF
52 options->incremental_specialization = 2;
53 #elif defined USE_INCREMENTAL_DF
54 options->incremental_specialization = 1;
55 #else
56 options->incremental_specialization = 0;
57 #endif
58 options->max_index = 1;
59 options->primal = 0;
60 #ifdef USE_MODULO
61 options->lookup_table = 0;
62 #else
63 options->lookup_table = 1;
64 #endif
65 #ifdef HAVE_LIBGLPK
66 options->count_sample_infinite = 1;
67 #else
68 options->count_sample_infinite = 0;
69 #endif
71 options->polynomial_approximation = BV_POLAPPROX_NONE;
73 #ifdef HAVE_LIBGLPK
74 options->gbr_lp_solver = BV_GBR_GLPK;
75 #elif defined HAVE_LIBCDDGMP
76 options->gbr_lp_solver = BV_GBR_CDD;
77 #else
78 options->gbr_lp_solver = BV_GBR_NONE;
79 #endif
81 options->bernstein_optimize = BV_BERNSTEIN_NONE;
83 options->bernstein_recurse = BV_BERNSTEIN_FACTORS;
85 return options;
88 void barvinok_options_free(struct barvinok_options *options)
90 free(options->stats);
91 free(options);
94 struct argp_option barvinok_argp_options[] = {
95 { "index", BV_OPT_MAXINDEX, "int", 0,
96 "maximal index of simple cones in decomposition" },
97 { "primal", BV_OPT_PRIMAL, 0, 0 },
98 { "table", BV_OPT_TABLE, 0, 0 },
99 { "specialization", BV_OPT_SPECIALIZATION, "[bf|df|random]", 0 },
100 { "polynomial-approximation",
101 BV_OPT_POLAPPROX,
102 "lower|upper|pre-lower|pre-upper|pre-approx", 0 },
103 { "gbr", BV_OPT_GBR, "[cdd]", 0,
104 "solver to use for basis reduction" },
105 { "version", 'V', 0, 0 },
106 { 0 }
109 error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state)
111 struct barvinok_options *options = state->input;
113 switch (key) {
114 case 'V':
115 printf(barvinok_version());
116 exit(0);
117 case BV_OPT_SPECIALIZATION:
118 if (!strcmp(arg, "bf"))
119 options->incremental_specialization = BV_SPECIALIZATION_BF;
120 else if (!strcmp(arg, "df"))
121 options->incremental_specialization = BV_SPECIALIZATION_DF;
122 else if (!strcmp(arg, "random"))
123 options->incremental_specialization = BV_SPECIALIZATION_RANDOM;
124 break;
125 case BV_OPT_PRIMAL:
126 options->primal = 1;
127 break;
128 case BV_OPT_TABLE:
129 options->lookup_table = 1;
130 break;
131 case BV_OPT_GBR:
132 if (!strcmp(arg, "cdd"))
133 options->gbr_lp_solver = BV_GBR_CDD;
134 break;
135 case BV_OPT_MAXINDEX:
136 options->max_index = strtoul(arg, NULL, 0);
137 break;
138 case BV_OPT_POLAPPROX:
139 if (!strcmp(arg, "pre-lower"))
140 options->polynomial_approximation = BV_POLAPPROX_PRE_LOWER;
141 else if (!strcmp(arg, "pre-upper"))
142 options->polynomial_approximation = BV_POLAPPROX_PRE_UPPER;
143 else if (!strcmp(arg, "pre-approx"))
144 options->polynomial_approximation = BV_POLAPPROX_PRE_APPROX;
145 else if (!strcmp(arg, "lower"))
146 options->polynomial_approximation = BV_POLAPPROX_LOWER;
147 else if (!strcmp(arg, "upper"))
148 options->polynomial_approximation = BV_POLAPPROX_UPPER;
149 break;
150 default:
151 return ARGP_ERR_UNKNOWN;
153 return 0;
156 struct argp barvinok_argp = {
157 barvinok_argp_options, barvinok_parse_opt, 0, 0