polymake/README: mention --with-barvinok configure option
[barvinok.git] / options.c
blob18d661810fe1adcb0d25bee14343a703d8823065
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 memset(stats, 0, sizeof(*stats));
24 void barvinok_stats_print(struct barvinok_stats *stats, FILE *out)
26 fprintf(out, "Base cones: %d\n", stats->base_cones);
27 if (stats->volume_simplices)
28 fprintf(out, "Volume simplices: %d\n", stats->volume_simplices);
29 if (stats->topcom_chambers) {
30 fprintf(out, "TOPCOM empty chambers: %d\n",
31 stats->topcom_empty_chambers);
32 fprintf(out, "TOPCOM chambers: %d\n", stats->topcom_chambers);
33 fprintf(out, "TOPCOM distinct chambers: %d\n",
34 stats->topcom_distinct_chambers);
38 struct barvinok_options *barvinok_options_new_with_defaults()
40 struct barvinok_options *options = ALLOC(struct barvinok_options);
41 if (!options)
42 return NULL;
44 options->stats = ALLOC(struct barvinok_stats);
45 if (!options->stats) {
46 free(options);
47 return NULL;
50 barvinok_stats_clear(options->stats);
52 options->LLL_a = 1;
53 options->LLL_b = 1;
55 options->MaxRays = MAXRAYS;
57 #ifdef USE_INCREMENTAL_BF
58 options->incremental_specialization = 2;
59 #elif defined USE_INCREMENTAL_DF
60 options->incremental_specialization = 1;
61 #else
62 options->incremental_specialization = 0;
63 #endif
64 options->max_index = 1;
65 options->primal = 0;
66 #ifdef USE_MODULO
67 options->lookup_table = 0;
68 #else
69 options->lookup_table = 1;
70 #endif
71 #ifdef HAVE_LIBGLPK
72 options->count_sample_infinite = 1;
73 #else
74 options->count_sample_infinite = 0;
75 #endif
76 options->try_Delaunay_triangulation = 0;
78 options->chambers = BV_CHAMBERS_POLYLIB;
80 options->polynomial_approximation = BV_APPROX_SIGN_NONE;
81 options->approximation_method = BV_APPROX_NONE;
82 options->scale_flags = 0;
83 options->volume_triangulate = BV_VOL_VERTEX;
85 #ifdef HAVE_LIBGLPK
86 options->gbr_lp_solver = BV_GBR_GLPK;
87 #elif defined HAVE_LIBCDDGMP
88 options->gbr_lp_solver = BV_GBR_CDD;
89 #else
90 options->gbr_lp_solver = BV_GBR_PIP;
91 #endif
93 #ifdef HAVE_LIBGLPK
94 options->lp_solver = BV_LP_GLPK;
95 #elif defined HAVE_LIBCDDGMP
96 options->lp_solver = BV_LP_CDD;
97 #else
98 options->lp_solver = BV_LP_POLYLIB;
99 #endif
101 options->summation = BV_SUM_BARVINOK;
103 options->bernstein_optimize = BV_BERNSTEIN_NONE;
105 options->bernstein_recurse = BV_BERNSTEIN_FACTORS;
107 return options;
110 void barvinok_options_free(struct barvinok_options *options)
112 free(options->stats);
113 free(options);
116 enum {
117 SCALE_FAST,
118 SCALE_SLOW,
119 SCALE_NARROW,
120 SCALE_NARROW2,
121 SCALE_CHAMBER,
124 const char *scale_opts[] = {
125 "fast",
126 "slow",
127 "narrow",
128 "narrow2",
129 "chamber",
130 NULL
133 static struct argp_option approx_argp_options[] = {
134 { "polynomial-approximation", BV_OPT_POLAPPROX, "lower|upper", 1 },
135 { "approximation-method", BV_OPT_APPROX, "scale|drop|volume|bernoulli", 0,
136 "method to use in polynomial approximation [default: drop]" },
137 { "scale-options", BV_OPT_SCALE,
138 "fast|slow,narrow|narrow2,chamber", 0 },
139 { "volume-triangulation", BV_OPT_VOL, "lift|vertex|barycenter", 0,
140 "type of triangulation to perform in volume computation [default: vertex]" },
141 { 0 }
144 static struct argp_option barvinok_argp_options[] = {
145 { "index", BV_OPT_MAXINDEX, "int", 0,
146 "maximal index of simple cones in decomposition" },
147 { "primal", BV_OPT_PRIMAL, 0, 0 },
148 { "table", BV_OPT_TABLE, 0, 0 },
149 { "specialization", BV_OPT_SPECIALIZATION, "[bf|df|random|todd]" },
150 #ifdef POINTS2TRIANGS_PATH
151 { "chamber-decomposition", BV_OPT_CHAMBERS, "polylib|topcom", 0,
152 "tool to use for chamber decomposition [default: polylib]" },
153 #endif
154 { "gbr", BV_OPT_GBR,
155 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
156 "cdd|glpk|pip|pip-dual",
157 #elif defined(HAVE_LIBGLPK)
158 "glpk|pip|pip-dual",
159 #elif defined(HAVE_LIBCDDGMP)
160 "cdd|pip|pip-dual",
161 #else
162 "pip|pip-dual",
163 #endif
164 0, "lp solver to use for basis reduction "
165 #ifdef HAVE_LIBGLPK
166 "[default: glpk]"
167 #elif defined HAVE_LIBCDDGMP
168 "[default: cdd]"
169 #else
170 "[default: pip]"
171 #endif
173 { "lp", BV_OPT_LP,
174 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
175 "cdd|cddf|glpk|polylib",
176 #elif defined(HAVE_LIBGLPK)
177 "glpk|polylib",
178 #elif defined(HAVE_LIBCDDGMP)
179 "cdd|cddf|polylib",
180 #else
181 "polylib",
182 #endif
183 0, "lp solver to use "
184 #if defined(HAVE_LIBGLPK)
185 "[default: glpk]",
186 #elif defined(HAVE_LIBCDDGMP)
187 "[default: cdd]",
188 #else
189 "[default: polylib]",
190 #endif
192 { "summation", BV_OPT_SUM, "barvinok|euler", 0,
193 "[default: barvinok]" },
194 { "bernstein-recurse", BV_OPT_RECURSE, "none|factors|intervals|full", 0,
195 "[default: factors]" },
196 { "recurse", BV_OPT_RECURSE, "",
197 OPTION_ALIAS | OPTION_HIDDEN },
198 { "version", 'V', 0, 0 },
199 { 0 }
202 static error_t approx_parse_opt(int key, char *arg, struct argp_state *state)
204 struct barvinok_options *options = state->input;
205 char *subopt;
207 switch (key) {
208 case BV_OPT_POLAPPROX:
209 if (!arg) {
210 options->polynomial_approximation = BV_APPROX_SIGN_APPROX;
211 if (options->approximation_method == BV_APPROX_NONE)
212 options->approximation_method = BV_APPROX_SCALE;
213 } else {
214 if (!strcmp(arg, "lower"))
215 options->polynomial_approximation = BV_APPROX_SIGN_LOWER;
216 else if (!strcmp(arg, "upper"))
217 options->polynomial_approximation = BV_APPROX_SIGN_UPPER;
218 if (options->approximation_method == BV_APPROX_NONE)
219 options->approximation_method = BV_APPROX_DROP;
221 break;
222 case BV_OPT_APPROX:
223 if (!strcmp(arg, "scale"))
224 options->approximation_method = BV_APPROX_SCALE;
225 else if (!strcmp(arg, "drop"))
226 options->approximation_method = BV_APPROX_DROP;
227 else if (!strcmp(arg, "volume"))
228 options->approximation_method = BV_APPROX_VOLUME;
229 else if (!strcmp(arg, "bernoulli"))
230 options->approximation_method = BV_APPROX_BERNOULLI;
231 else
232 argp_error(state, "unknown value for --approximation-method option");
233 break;
234 case BV_OPT_SCALE:
235 options->approximation_method = BV_APPROX_SCALE;
236 while (*arg != '\0')
237 switch (getsubopt(&arg, scale_opts, &subopt)) {
238 case SCALE_FAST:
239 options->scale_flags |= BV_APPROX_SCALE_FAST;
240 break;
241 case SCALE_SLOW:
242 options->scale_flags &= ~BV_APPROX_SCALE_FAST;
243 break;
244 case SCALE_NARROW:
245 options->scale_flags |= BV_APPROX_SCALE_NARROW;
246 options->scale_flags &= ~BV_APPROX_SCALE_NARROW2;
247 break;
248 case SCALE_NARROW2:
249 options->scale_flags |= BV_APPROX_SCALE_NARROW2;
250 options->scale_flags &= ~BV_APPROX_SCALE_NARROW;
251 break;
252 case SCALE_CHAMBER:
253 options->scale_flags |= BV_APPROX_SCALE_CHAMBER;
254 break;
255 default:
256 argp_error(state, "unknown suboption '%s'\n", subopt);
258 break;
259 case BV_OPT_VOL:
260 if (!strcmp(arg, "lift"))
261 options->volume_triangulate = BV_VOL_LIFT;
262 else if (!strcmp(arg, "vertex"))
263 options->volume_triangulate = BV_VOL_VERTEX;
264 else if (!strcmp(arg, "barycenter"))
265 options->volume_triangulate = BV_VOL_BARYCENTER;
266 break;
267 case ARGP_KEY_END:
268 if (options->polynomial_approximation == BV_APPROX_SIGN_NONE &&
269 options->approximation_method != BV_APPROX_NONE) {
270 fprintf(stderr,
271 "no polynomial approximation selected; reseting approximation method\n");
272 options->approximation_method = BV_APPROX_NONE;
274 break;
275 default:
276 return ARGP_ERR_UNKNOWN;
278 return 0;
281 static error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state)
283 struct barvinok_options *options = state->input;
284 char *subopt;
286 switch (key) {
287 case ARGP_KEY_INIT:
288 state->child_inputs[0] = options;
289 break;
290 case 'V':
291 printf(barvinok_version());
292 exit(0);
293 case BV_OPT_SPECIALIZATION:
294 if (!strcmp(arg, "bf"))
295 options->incremental_specialization = BV_SPECIALIZATION_BF;
296 else if (!strcmp(arg, "df"))
297 options->incremental_specialization = BV_SPECIALIZATION_DF;
298 else if (!strcmp(arg, "random"))
299 options->incremental_specialization = BV_SPECIALIZATION_RANDOM;
300 else if (!strcmp(arg, "todd"))
301 options->incremental_specialization = BV_SPECIALIZATION_TODD;
302 break;
303 case BV_OPT_PRIMAL:
304 options->primal = 1;
305 break;
306 case BV_OPT_TABLE:
307 options->lookup_table = 1;
308 break;
309 case BV_OPT_CHAMBERS:
310 if (!strcmp(arg, "polylib"))
311 options->chambers = BV_CHAMBERS_POLYLIB;
312 if (!strcmp(arg, "topcom"))
313 options->chambers = BV_CHAMBERS_TOPCOM;
314 break;
315 case BV_OPT_GBR:
316 if (!strcmp(arg, "cdd"))
317 options->gbr_lp_solver = BV_GBR_CDD;
318 if (!strcmp(arg, "glpk"))
319 options->gbr_lp_solver = BV_GBR_GLPK;
320 if (!strcmp(arg, "pip"))
321 options->gbr_lp_solver = BV_GBR_PIP;
322 if (!strcmp(arg, "pip-dual"))
323 options->gbr_lp_solver = BV_GBR_PIP_DUAL;
324 break;
325 case BV_OPT_LP:
326 if (!strcmp(arg, "cdd"))
327 options->lp_solver = BV_LP_CDD;
328 if (!strcmp(arg, "cddf"))
329 options->lp_solver = BV_LP_CDDF;
330 if (!strcmp(arg, "glpk"))
331 options->lp_solver = BV_LP_GLPK;
332 if (!strcmp(arg, "polylib"))
333 options->lp_solver = BV_LP_POLYLIB;
334 break;
335 case BV_OPT_MAXINDEX:
336 options->max_index = strtoul(arg, NULL, 0);
337 break;
338 case BV_OPT_SUM:
339 if (!strcmp(arg, "barvinok"))
340 options->summation = BV_SUM_BARVINOK;
341 if (!strcmp(arg, "euler"))
342 options->summation = BV_SUM_EULER;
343 break;
344 case BV_OPT_RECURSE:
345 if (!strcmp(arg, "none"))
346 options->bernstein_recurse = 0;
347 else if (!strcmp(arg, "factors"))
348 options->bernstein_recurse = BV_BERNSTEIN_FACTORS;
349 else if (!strcmp(arg, "intervals"))
350 options->bernstein_recurse = BV_BERNSTEIN_INTERVALS;
351 else if (!strcmp(arg, "full"))
352 options->bernstein_recurse =
353 BV_BERNSTEIN_FACTORS | BV_BERNSTEIN_INTERVALS;
354 break;
355 default:
356 return ARGP_ERR_UNKNOWN;
358 return 0;
361 static struct argp approx_argp = {
362 approx_argp_options, approx_parse_opt, 0, 0
365 static struct argp_child barvinok_children[] = {
366 { &approx_argp, 0, "polynomial approximation", BV_GRP_APPROX },
367 { 0 }
370 struct argp barvinok_argp = {
371 barvinok_argp_options, barvinok_parse_opt, 0, 0, barvinok_children