introduce barvinok_summate as a wrapper for evalue_sum
[barvinok.git] / options.c
blobf8dcde466ad4dbf1a4e438675a10ee116916af5a
1 #include <assert.h>
2 #include <unistd.h>
3 #include <barvinok/options.h>
4 #include <barvinok/util.h>
5 #include "argp.h"
6 #include "config.h"
8 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
10 #ifndef HAVE_LIBGLPK
11 Vector *Polyhedron_Sample(Polyhedron *P, struct barvinok_options *options)
13 assert(0);
15 #endif
17 #define ALLOC(type) (type*)malloc(sizeof(type))
19 void barvinok_stats_clear(struct barvinok_stats *stats)
21 stats->base_cones = 0;
22 stats->volume_simplices = 0;
25 void barvinok_stats_print(struct barvinok_stats *stats, FILE *out)
27 fprintf(out, "Base cones: %d\n", stats->base_cones);
28 if (stats->volume_simplices)
29 fprintf(out, "Volume simplices: %d\n", stats->volume_simplices);
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
70 options->try_Delaunay_triangulation = 0;
72 options->polynomial_approximation = BV_APPROX_SIGN_NONE;
73 options->approximation_method = BV_APPROX_NONE;
74 options->scale_flags = 0;
75 options->volume_triangulate = BV_VOL_VERTEX;
77 #ifdef HAVE_LIBGLPK
78 options->gbr_lp_solver = BV_GBR_GLPK;
79 #elif defined HAVE_LIBCDDGMP
80 options->gbr_lp_solver = BV_GBR_CDD;
81 #else
82 options->gbr_lp_solver = BV_GBR_PIP;
83 #endif
85 #ifdef HAVE_LIBGLPK
86 options->lp_solver = BV_LP_GLPK;
87 #elif defined HAVE_LIBCDDGMP
88 options->lp_solver = BV_LP_CDD;
89 #else
90 options->lp_solver = BV_LP_POLYLIB;
91 #endif
93 options->bernstein_optimize = BV_BERNSTEIN_NONE;
95 options->bernstein_recurse = BV_BERNSTEIN_FACTORS;
97 return options;
100 void barvinok_options_free(struct barvinok_options *options)
102 free(options->stats);
103 free(options);
106 enum {
107 SCALE_FAST,
108 SCALE_SLOW,
109 SCALE_NARROW,
110 SCALE_NARROW2,
111 SCALE_CHAMBER,
114 const char *scale_opts[] = {
115 "fast",
116 "slow",
117 "narrow",
118 "narrow2",
119 "chamber",
120 NULL
123 static struct argp_option approx_argp_options[] = {
124 { "polynomial-approximation", BV_OPT_POLAPPROX, "lower|upper", 1 },
125 { "approximation-method", BV_OPT_APPROX, "scale|drop|volume|bernouilli", 0,
126 "method to use in polynomial approximation [default: drop]" },
127 { "scale-options", BV_OPT_SCALE,
128 "fast|slow,narrow|narrow2,chamber", 0 },
129 { "volume-triangulation", BV_OPT_VOL, "lift|vertex|barycenter", 0,
130 "type of triangulation to perform in volume computation [default: vertex]" },
131 { 0 }
134 static struct argp_option barvinok_argp_options[] = {
135 { "index", BV_OPT_MAXINDEX, "int", 0,
136 "maximal index of simple cones in decomposition" },
137 { "primal", BV_OPT_PRIMAL, 0, 0 },
138 { "table", BV_OPT_TABLE, 0, 0 },
139 { "specialization", BV_OPT_SPECIALIZATION, "[bf|df|random|todd]" },
140 { "gbr", BV_OPT_GBR,
141 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
142 "cdd|glpk|pip|pip-dual",
143 #elif defined(HAVE_LIBGLPK)
144 "glpk|pip|pip-dual",
145 #elif defined(HAVE_LIBCDDGMP)
146 "cdd|pip|pip-dual",
147 #else
148 "pip|pip-dual",
149 #endif
150 0, "lp solver to use for basis reduction "
151 #ifdef HAVE_LIBGLPK
152 "[default: glpk]"
153 #elif defined HAVE_LIBCDDGMP
154 "[default: cdd]"
155 #else
156 "[default: pip]"
157 #endif
159 { "lp", BV_OPT_LP,
160 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
161 "cdd|cddf|glpk|polylib",
162 #elif defined(HAVE_LIBGLPK)
163 "glpk|polylib",
164 #elif defined(HAVE_LIBCDDGMP)
165 "cdd|cddf|polylib",
166 #else
167 "polylib",
168 #endif
169 0, "lp solver to use "
170 #if defined(HAVE_LIBGLPK)
171 "[default: glpk]",
172 #elif defined(HAVE_LIBCDDGMP)
173 "[default: cdd]",
174 #else
175 "[default: polylib]",
176 #endif
178 { "bernstein-recurse", BV_OPT_RECURSE, "none|factors|intervals|full", 0,
179 "[default: factors]" },
180 { "recurse", BV_OPT_RECURSE, "",
181 OPTION_ALIAS | OPTION_HIDDEN },
182 { "version", 'V', 0, 0 },
183 { 0 }
186 static error_t approx_parse_opt(int key, char *arg, struct argp_state *state)
188 struct barvinok_options *options = state->input;
189 char *subopt;
191 switch (key) {
192 case BV_OPT_POLAPPROX:
193 if (!arg) {
194 options->polynomial_approximation = BV_APPROX_SIGN_APPROX;
195 if (options->approximation_method == BV_APPROX_NONE)
196 options->approximation_method = BV_APPROX_SCALE;
197 } else {
198 if (!strcmp(arg, "lower"))
199 options->polynomial_approximation = BV_APPROX_SIGN_LOWER;
200 else if (!strcmp(arg, "upper"))
201 options->polynomial_approximation = BV_APPROX_SIGN_UPPER;
202 if (options->approximation_method == BV_APPROX_NONE)
203 options->approximation_method = BV_APPROX_DROP;
205 break;
206 case BV_OPT_APPROX:
207 if (!strcmp(arg, "scale"))
208 options->approximation_method = BV_APPROX_SCALE;
209 else if (!strcmp(arg, "drop"))
210 options->approximation_method = BV_APPROX_DROP;
211 else if (!strcmp(arg, "volume"))
212 options->approximation_method = BV_APPROX_VOLUME;
213 else if (!strcmp(arg, "bernoulli"))
214 options->approximation_method = BV_APPROX_BERNOULLI;
215 else
216 argp_error(state, "unknown value for --approximation-method option");
217 break;
218 case BV_OPT_SCALE:
219 options->approximation_method = BV_APPROX_SCALE;
220 while (*arg != '\0')
221 switch (getsubopt(&arg, scale_opts, &subopt)) {
222 case SCALE_FAST:
223 options->scale_flags |= BV_APPROX_SCALE_FAST;
224 break;
225 case SCALE_SLOW:
226 options->scale_flags &= ~BV_APPROX_SCALE_FAST;
227 break;
228 case SCALE_NARROW:
229 options->scale_flags |= BV_APPROX_SCALE_NARROW;
230 options->scale_flags &= ~BV_APPROX_SCALE_NARROW2;
231 break;
232 case SCALE_NARROW2:
233 options->scale_flags |= BV_APPROX_SCALE_NARROW2;
234 options->scale_flags &= ~BV_APPROX_SCALE_NARROW;
235 break;
236 case SCALE_CHAMBER:
237 options->scale_flags |= BV_APPROX_SCALE_CHAMBER;
238 break;
239 default:
240 argp_error(state, "unknown suboption '%s'\n", subopt);
242 break;
243 case BV_OPT_VOL:
244 if (!strcmp(arg, "lift"))
245 options->volume_triangulate = BV_VOL_LIFT;
246 else if (!strcmp(arg, "vertex"))
247 options->volume_triangulate = BV_VOL_VERTEX;
248 else if (!strcmp(arg, "barycenter"))
249 options->volume_triangulate = BV_VOL_BARYCENTER;
250 break;
251 case ARGP_KEY_END:
252 if (options->polynomial_approximation == BV_APPROX_SIGN_NONE &&
253 options->approximation_method != BV_APPROX_NONE) {
254 fprintf(stderr,
255 "no polynomial approximation selected; reseting approximation method\n");
256 options->approximation_method = BV_APPROX_NONE;
258 break;
259 default:
260 return ARGP_ERR_UNKNOWN;
262 return 0;
265 static error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state)
267 struct barvinok_options *options = state->input;
268 char *subopt;
270 switch (key) {
271 case ARGP_KEY_INIT:
272 state->child_inputs[0] = options;
273 break;
274 case 'V':
275 printf(barvinok_version());
276 exit(0);
277 case BV_OPT_SPECIALIZATION:
278 if (!strcmp(arg, "bf"))
279 options->incremental_specialization = BV_SPECIALIZATION_BF;
280 else if (!strcmp(arg, "df"))
281 options->incremental_specialization = BV_SPECIALIZATION_DF;
282 else if (!strcmp(arg, "random"))
283 options->incremental_specialization = BV_SPECIALIZATION_RANDOM;
284 else if (!strcmp(arg, "todd"))
285 options->incremental_specialization = BV_SPECIALIZATION_TODD;
286 break;
287 case BV_OPT_PRIMAL:
288 options->primal = 1;
289 break;
290 case BV_OPT_TABLE:
291 options->lookup_table = 1;
292 break;
293 case BV_OPT_GBR:
294 if (!strcmp(arg, "cdd"))
295 options->gbr_lp_solver = BV_GBR_CDD;
296 if (!strcmp(arg, "glpk"))
297 options->gbr_lp_solver = BV_GBR_GLPK;
298 if (!strcmp(arg, "pip"))
299 options->gbr_lp_solver = BV_GBR_PIP;
300 if (!strcmp(arg, "pip-dual"))
301 options->gbr_lp_solver = BV_GBR_PIP_DUAL;
302 break;
303 case BV_OPT_LP:
304 if (!strcmp(arg, "cdd"))
305 options->lp_solver = BV_LP_CDD;
306 if (!strcmp(arg, "cddf"))
307 options->lp_solver = BV_LP_CDDF;
308 if (!strcmp(arg, "glpk"))
309 options->lp_solver = BV_LP_GLPK;
310 if (!strcmp(arg, "polylib"))
311 options->lp_solver = BV_LP_POLYLIB;
312 break;
313 case BV_OPT_MAXINDEX:
314 options->max_index = strtoul(arg, NULL, 0);
315 break;
316 case BV_OPT_RECURSE:
317 if (!strcmp(arg, "none"))
318 options->bernstein_recurse = 0;
319 else if (!strcmp(arg, "factors"))
320 options->bernstein_recurse = BV_BERNSTEIN_FACTORS;
321 else if (!strcmp(arg, "intervals"))
322 options->bernstein_recurse = BV_BERNSTEIN_INTERVALS;
323 else if (!strcmp(arg, "full"))
324 options->bernstein_recurse =
325 BV_BERNSTEIN_FACTORS | BV_BERNSTEIN_INTERVALS;
326 break;
327 default:
328 return ARGP_ERR_UNKNOWN;
330 return 0;
333 static struct argp approx_argp = {
334 approx_argp_options, approx_parse_opt, 0, 0
337 static struct argp_child barvinok_children[] = {
338 { &approx_argp, 0, "polynomial approximation", BV_GRP_APPROX },
339 { 0 }
342 struct argp barvinok_argp = {
343 barvinok_argp_options, barvinok_parse_opt, 0, 0, barvinok_children