barvinok_summate: correct options description
[barvinok.git] / options.c
blob2593b88011aef48a9637f95c828f6efa371f16fb
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->summation = BV_SUM_BARVINOK;
95 options->bernstein_optimize = BV_BERNSTEIN_NONE;
97 options->bernstein_recurse = BV_BERNSTEIN_FACTORS;
99 return options;
102 void barvinok_options_free(struct barvinok_options *options)
104 free(options->stats);
105 free(options);
108 enum {
109 SCALE_FAST,
110 SCALE_SLOW,
111 SCALE_NARROW,
112 SCALE_NARROW2,
113 SCALE_CHAMBER,
116 const char *scale_opts[] = {
117 "fast",
118 "slow",
119 "narrow",
120 "narrow2",
121 "chamber",
122 NULL
125 static struct argp_option approx_argp_options[] = {
126 { "polynomial-approximation", BV_OPT_POLAPPROX, "lower|upper", 1 },
127 { "approximation-method", BV_OPT_APPROX, "scale|drop|volume|bernouilli", 0,
128 "method to use in polynomial approximation [default: drop]" },
129 { "scale-options", BV_OPT_SCALE,
130 "fast|slow,narrow|narrow2,chamber", 0 },
131 { "volume-triangulation", BV_OPT_VOL, "lift|vertex|barycenter", 0,
132 "type of triangulation to perform in volume computation [default: vertex]" },
133 { 0 }
136 static struct argp_option barvinok_argp_options[] = {
137 { "index", BV_OPT_MAXINDEX, "int", 0,
138 "maximal index of simple cones in decomposition" },
139 { "primal", BV_OPT_PRIMAL, 0, 0 },
140 { "table", BV_OPT_TABLE, 0, 0 },
141 { "specialization", BV_OPT_SPECIALIZATION, "[bf|df|random|todd]" },
142 { "gbr", BV_OPT_GBR,
143 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
144 "cdd|glpk|pip|pip-dual",
145 #elif defined(HAVE_LIBGLPK)
146 "glpk|pip|pip-dual",
147 #elif defined(HAVE_LIBCDDGMP)
148 "cdd|pip|pip-dual",
149 #else
150 "pip|pip-dual",
151 #endif
152 0, "lp solver to use for basis reduction "
153 #ifdef HAVE_LIBGLPK
154 "[default: glpk]"
155 #elif defined HAVE_LIBCDDGMP
156 "[default: cdd]"
157 #else
158 "[default: pip]"
159 #endif
161 { "lp", BV_OPT_LP,
162 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
163 "cdd|cddf|glpk|polylib",
164 #elif defined(HAVE_LIBGLPK)
165 "glpk|polylib",
166 #elif defined(HAVE_LIBCDDGMP)
167 "cdd|cddf|polylib",
168 #else
169 "polylib",
170 #endif
171 0, "lp solver to use "
172 #if defined(HAVE_LIBGLPK)
173 "[default: glpk]",
174 #elif defined(HAVE_LIBCDDGMP)
175 "[default: cdd]",
176 #else
177 "[default: polylib]",
178 #endif
180 { "summation", BV_OPT_SUM, "barvinok|euler", 0,
181 "[default: barvinok]" },
182 { "bernstein-recurse", BV_OPT_RECURSE, "none|factors|intervals|full", 0,
183 "[default: factors]" },
184 { "recurse", BV_OPT_RECURSE, "",
185 OPTION_ALIAS | OPTION_HIDDEN },
186 { "version", 'V', 0, 0 },
187 { 0 }
190 static error_t approx_parse_opt(int key, char *arg, struct argp_state *state)
192 struct barvinok_options *options = state->input;
193 char *subopt;
195 switch (key) {
196 case BV_OPT_POLAPPROX:
197 if (!arg) {
198 options->polynomial_approximation = BV_APPROX_SIGN_APPROX;
199 if (options->approximation_method == BV_APPROX_NONE)
200 options->approximation_method = BV_APPROX_SCALE;
201 } else {
202 if (!strcmp(arg, "lower"))
203 options->polynomial_approximation = BV_APPROX_SIGN_LOWER;
204 else if (!strcmp(arg, "upper"))
205 options->polynomial_approximation = BV_APPROX_SIGN_UPPER;
206 if (options->approximation_method == BV_APPROX_NONE)
207 options->approximation_method = BV_APPROX_DROP;
209 break;
210 case BV_OPT_APPROX:
211 if (!strcmp(arg, "scale"))
212 options->approximation_method = BV_APPROX_SCALE;
213 else if (!strcmp(arg, "drop"))
214 options->approximation_method = BV_APPROX_DROP;
215 else if (!strcmp(arg, "volume"))
216 options->approximation_method = BV_APPROX_VOLUME;
217 else if (!strcmp(arg, "bernoulli"))
218 options->approximation_method = BV_APPROX_BERNOULLI;
219 else
220 argp_error(state, "unknown value for --approximation-method option");
221 break;
222 case BV_OPT_SCALE:
223 options->approximation_method = BV_APPROX_SCALE;
224 while (*arg != '\0')
225 switch (getsubopt(&arg, scale_opts, &subopt)) {
226 case SCALE_FAST:
227 options->scale_flags |= BV_APPROX_SCALE_FAST;
228 break;
229 case SCALE_SLOW:
230 options->scale_flags &= ~BV_APPROX_SCALE_FAST;
231 break;
232 case SCALE_NARROW:
233 options->scale_flags |= BV_APPROX_SCALE_NARROW;
234 options->scale_flags &= ~BV_APPROX_SCALE_NARROW2;
235 break;
236 case SCALE_NARROW2:
237 options->scale_flags |= BV_APPROX_SCALE_NARROW2;
238 options->scale_flags &= ~BV_APPROX_SCALE_NARROW;
239 break;
240 case SCALE_CHAMBER:
241 options->scale_flags |= BV_APPROX_SCALE_CHAMBER;
242 break;
243 default:
244 argp_error(state, "unknown suboption '%s'\n", subopt);
246 break;
247 case BV_OPT_VOL:
248 if (!strcmp(arg, "lift"))
249 options->volume_triangulate = BV_VOL_LIFT;
250 else if (!strcmp(arg, "vertex"))
251 options->volume_triangulate = BV_VOL_VERTEX;
252 else if (!strcmp(arg, "barycenter"))
253 options->volume_triangulate = BV_VOL_BARYCENTER;
254 break;
255 case ARGP_KEY_END:
256 if (options->polynomial_approximation == BV_APPROX_SIGN_NONE &&
257 options->approximation_method != BV_APPROX_NONE) {
258 fprintf(stderr,
259 "no polynomial approximation selected; reseting approximation method\n");
260 options->approximation_method = BV_APPROX_NONE;
262 break;
263 default:
264 return ARGP_ERR_UNKNOWN;
266 return 0;
269 static error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state)
271 struct barvinok_options *options = state->input;
272 char *subopt;
274 switch (key) {
275 case ARGP_KEY_INIT:
276 state->child_inputs[0] = options;
277 break;
278 case 'V':
279 printf(barvinok_version());
280 exit(0);
281 case BV_OPT_SPECIALIZATION:
282 if (!strcmp(arg, "bf"))
283 options->incremental_specialization = BV_SPECIALIZATION_BF;
284 else if (!strcmp(arg, "df"))
285 options->incremental_specialization = BV_SPECIALIZATION_DF;
286 else if (!strcmp(arg, "random"))
287 options->incremental_specialization = BV_SPECIALIZATION_RANDOM;
288 else if (!strcmp(arg, "todd"))
289 options->incremental_specialization = BV_SPECIALIZATION_TODD;
290 break;
291 case BV_OPT_PRIMAL:
292 options->primal = 1;
293 break;
294 case BV_OPT_TABLE:
295 options->lookup_table = 1;
296 break;
297 case BV_OPT_GBR:
298 if (!strcmp(arg, "cdd"))
299 options->gbr_lp_solver = BV_GBR_CDD;
300 if (!strcmp(arg, "glpk"))
301 options->gbr_lp_solver = BV_GBR_GLPK;
302 if (!strcmp(arg, "pip"))
303 options->gbr_lp_solver = BV_GBR_PIP;
304 if (!strcmp(arg, "pip-dual"))
305 options->gbr_lp_solver = BV_GBR_PIP_DUAL;
306 break;
307 case BV_OPT_LP:
308 if (!strcmp(arg, "cdd"))
309 options->lp_solver = BV_LP_CDD;
310 if (!strcmp(arg, "cddf"))
311 options->lp_solver = BV_LP_CDDF;
312 if (!strcmp(arg, "glpk"))
313 options->lp_solver = BV_LP_GLPK;
314 if (!strcmp(arg, "polylib"))
315 options->lp_solver = BV_LP_POLYLIB;
316 break;
317 case BV_OPT_MAXINDEX:
318 options->max_index = strtoul(arg, NULL, 0);
319 break;
320 case BV_OPT_SUM:
321 if (!strcmp(arg, "barvinok"))
322 options->summation = BV_SUM_BARVINOK;
323 if (!strcmp(arg, "euler"))
324 options->summation = BV_SUM_EULER;
325 break;
326 case BV_OPT_RECURSE:
327 if (!strcmp(arg, "none"))
328 options->bernstein_recurse = 0;
329 else if (!strcmp(arg, "factors"))
330 options->bernstein_recurse = BV_BERNSTEIN_FACTORS;
331 else if (!strcmp(arg, "intervals"))
332 options->bernstein_recurse = BV_BERNSTEIN_INTERVALS;
333 else if (!strcmp(arg, "full"))
334 options->bernstein_recurse =
335 BV_BERNSTEIN_FACTORS | BV_BERNSTEIN_INTERVALS;
336 break;
337 default:
338 return ARGP_ERR_UNKNOWN;
340 return 0;
343 static struct argp approx_argp = {
344 approx_argp_options, approx_parse_opt, 0, 0
347 static struct argp_child barvinok_children[] = {
348 { &approx_argp, 0, "polynomial approximation", BV_GRP_APPROX },
349 { 0 }
352 struct argp barvinok_argp = {
353 barvinok_argp_options, barvinok_parse_opt, 0, 0, barvinok_children