3 #include <barvinok/options.h>
4 #include <barvinok/util.h>
8 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
10 #define ALLOC(type) (type*)malloc(sizeof(type))
12 void barvinok_stats_clear(struct barvinok_stats
*stats
)
14 memset(stats
, 0, sizeof(*stats
));
17 void barvinok_stats_print(struct barvinok_stats
*stats
, FILE *out
)
19 fprintf(out
, "Base cones: %d\n", stats
->base_cones
);
20 if (stats
->volume_simplices
)
21 fprintf(out
, "Volume simplices: %d\n", stats
->volume_simplices
);
22 if (stats
->topcom_chambers
) {
23 fprintf(out
, "TOPCOM empty chambers: %d\n",
24 stats
->topcom_empty_chambers
);
25 fprintf(out
, "TOPCOM chambers: %d\n", stats
->topcom_chambers
);
26 fprintf(out
, "TOPCOM distinct chambers: %d\n",
27 stats
->topcom_distinct_chambers
);
29 if (stats
->gbr_solved_lps
)
30 fprintf(out
, "LPs solved during GBR: %d\n", stats
->gbr_solved_lps
);
31 if (stats
->bernoulli_sums
)
32 fprintf(out
, "Bernoulli sums: %d\n", stats
->bernoulli_sums
);
35 struct barvinok_options
*barvinok_options_new_with_defaults()
37 struct barvinok_options
*options
= ALLOC(struct barvinok_options
);
41 options
->stats
= ALLOC(struct barvinok_stats
);
42 if (!options
->stats
) {
47 barvinok_stats_clear(options
->stats
);
52 options
->MaxRays
= MAXRAYS
;
54 #ifdef USE_INCREMENTAL_BF
55 options
->incremental_specialization
= 2;
56 #elif defined USE_INCREMENTAL_DF
57 options
->incremental_specialization
= 1;
59 options
->incremental_specialization
= 0;
61 options
->max_index
= 1;
64 options
->lookup_table
= 0;
66 options
->lookup_table
= 1;
68 options
->count_sample_infinite
= 1;
69 options
->try_Delaunay_triangulation
= 0;
71 options
->chambers
= BV_CHAMBERS_POLYLIB
;
73 options
->polynomial_approximation
= BV_APPROX_SIGN_NONE
;
74 options
->approximation_method
= BV_APPROX_NONE
;
75 options
->scale_flags
= 0;
76 options
->volume_triangulate
= BV_VOL_VERTEX
;
79 options
->gbr_lp_solver
= BV_GBR_GLPK
;
80 #elif defined HAVE_LIBCDDGMP
81 options
->gbr_lp_solver
= BV_GBR_CDD
;
83 options
->gbr_lp_solver
= BV_GBR_PIP
;
87 options
->lp_solver
= BV_LP_GLPK
;
88 #elif defined HAVE_LIBCDDGMP
89 options
->lp_solver
= BV_LP_CDD
;
91 options
->lp_solver
= BV_LP_PIP
;
94 options
->summation
= BV_SUM_LAURENT
;
96 options
->bernstein_optimize
= BV_BERNSTEIN_NONE
;
98 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
100 options
->integer_hull
= BV_HULL_GBR
;
102 options
->verbose
= 0;
104 options
->print_stats
= 0;
106 options
->gbr_only_first
= 0;
111 void barvinok_options_free(struct barvinok_options
*options
)
113 free(options
->stats
);
125 const char *scale_opts
[] = {
134 static struct argp_option approx_argp_options
[] = {
135 { "polynomial-approximation", BV_OPT_POLAPPROX
, "lower|upper", 1 },
136 { "approximation-method", BV_OPT_APPROX
, "scale|drop|volume|bernoulli", 0,
137 "method to use in polynomial approximation [default: drop]" },
138 { "scale-options", BV_OPT_SCALE
,
139 "fast|slow,narrow|narrow2,chamber", 0 },
140 { "volume-triangulation", BV_OPT_VOL
, "lift|vertex|barycenter", 0,
141 "type of triangulation to perform in volume computation [default: vertex]" },
145 static struct argp_option barvinok_argp_options
[] = {
146 { "index", BV_OPT_MAXINDEX
, "int", 0,
147 "maximal index of simple cones in decomposition" },
148 { "primal", BV_OPT_PRIMAL
, 0, 0 },
149 { "table", BV_OPT_TABLE
, 0, 0 },
150 { "specialization", BV_OPT_SPECIALIZATION
, "[bf|df|random|todd]" },
151 #ifdef POINTS2TRIANGS_PATH
152 { "chamber-decomposition", BV_OPT_CHAMBERS
, "polylib|topcom", 0,
153 "tool to use for chamber decomposition [default: polylib]" },
156 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
157 "cdd|glpk|pip|pip-dual",
158 #elif defined(HAVE_LIBGLPK)
160 #elif defined(HAVE_LIBCDDGMP)
165 0, "lp solver to use for basis reduction "
168 #elif defined HAVE_LIBCDDGMP
175 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
176 "cdd|cddf|glpk|pip|polylib",
177 #elif defined(HAVE_LIBGLPK)
179 #elif defined(HAVE_LIBCDDGMP)
180 "cdd|cddf|pip|polylib",
184 0, "lp solver to use "
185 #if defined(HAVE_LIBGLPK)
187 #elif defined(HAVE_LIBCDDGMP)
193 { "summation", BV_OPT_SUM
, "box|bernoulli|euler|laurent", 0,
194 "[default: laurent]" },
195 { "bernstein-recurse", BV_OPT_RECURSE
, "none|factors|intervals|full", 0,
196 "[default: factors]" },
197 { "recurse", BV_OPT_RECURSE
, "",
198 OPTION_ALIAS
| OPTION_HIDDEN
},
199 { "integer-hull", BV_OPT_HULL
,
205 0, "[default: gbr]" },
206 { "version", 'V', 0, 0 },
208 { "print-stats", BV_OPT_PRINT_STATS
, 0, 0 },
212 static error_t
approx_parse_opt(int key
, char *arg
, struct argp_state
*state
)
214 struct barvinok_options
*options
= state
->input
;
218 case BV_OPT_POLAPPROX
:
220 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
221 if (options
->approximation_method
== BV_APPROX_NONE
)
222 options
->approximation_method
= BV_APPROX_SCALE
;
224 if (!strcmp(arg
, "lower"))
225 options
->polynomial_approximation
= BV_APPROX_SIGN_LOWER
;
226 else if (!strcmp(arg
, "upper"))
227 options
->polynomial_approximation
= BV_APPROX_SIGN_UPPER
;
228 if (options
->approximation_method
== BV_APPROX_NONE
)
229 options
->approximation_method
= BV_APPROX_DROP
;
233 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
)
234 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
235 if (!strcmp(arg
, "scale"))
236 options
->approximation_method
= BV_APPROX_SCALE
;
237 else if (!strcmp(arg
, "drop"))
238 options
->approximation_method
= BV_APPROX_DROP
;
239 else if (!strcmp(arg
, "volume"))
240 options
->approximation_method
= BV_APPROX_VOLUME
;
241 else if (!strcmp(arg
, "bernoulli"))
242 options
->approximation_method
= BV_APPROX_BERNOULLI
;
244 argp_error(state
, "unknown value for --approximation-method option");
247 options
->approximation_method
= BV_APPROX_SCALE
;
249 switch (getsubopt(&arg
, scale_opts
, &subopt
)) {
251 options
->scale_flags
|= BV_APPROX_SCALE_FAST
;
254 options
->scale_flags
&= ~BV_APPROX_SCALE_FAST
;
257 options
->scale_flags
|= BV_APPROX_SCALE_NARROW
;
258 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW2
;
261 options
->scale_flags
|= BV_APPROX_SCALE_NARROW2
;
262 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW
;
265 options
->scale_flags
|= BV_APPROX_SCALE_CHAMBER
;
268 argp_error(state
, "unknown suboption '%s'\n", subopt
);
272 if (!strcmp(arg
, "lift"))
273 options
->volume_triangulate
= BV_VOL_LIFT
;
274 else if (!strcmp(arg
, "vertex"))
275 options
->volume_triangulate
= BV_VOL_VERTEX
;
276 else if (!strcmp(arg
, "barycenter"))
277 options
->volume_triangulate
= BV_VOL_BARYCENTER
;
280 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
&&
281 options
->approximation_method
!= BV_APPROX_NONE
) {
283 "no polynomial approximation selected; reseting approximation method\n");
284 options
->approximation_method
= BV_APPROX_NONE
;
288 return ARGP_ERR_UNKNOWN
;
293 static error_t
barvinok_parse_opt(int key
, char *arg
, struct argp_state
*state
)
295 struct barvinok_options
*options
= state
->input
;
300 state
->child_inputs
[0] = options
;
306 printf(barvinok_version());
308 case BV_OPT_SPECIALIZATION
:
309 if (!strcmp(arg
, "bf"))
310 options
->incremental_specialization
= BV_SPECIALIZATION_BF
;
311 else if (!strcmp(arg
, "df"))
312 options
->incremental_specialization
= BV_SPECIALIZATION_DF
;
313 else if (!strcmp(arg
, "random"))
314 options
->incremental_specialization
= BV_SPECIALIZATION_RANDOM
;
315 else if (!strcmp(arg
, "todd"))
316 options
->incremental_specialization
= BV_SPECIALIZATION_TODD
;
322 options
->lookup_table
= 1;
324 case BV_OPT_CHAMBERS
:
325 if (!strcmp(arg
, "polylib"))
326 options
->chambers
= BV_CHAMBERS_POLYLIB
;
327 if (!strcmp(arg
, "topcom"))
328 options
->chambers
= BV_CHAMBERS_TOPCOM
;
331 if (!strcmp(arg
, "cdd"))
332 options
->gbr_lp_solver
= BV_GBR_CDD
;
333 if (!strcmp(arg
, "glpk"))
334 options
->gbr_lp_solver
= BV_GBR_GLPK
;
335 if (!strcmp(arg
, "pip"))
336 options
->gbr_lp_solver
= BV_GBR_PIP
;
337 if (!strcmp(arg
, "pip-dual"))
338 options
->gbr_lp_solver
= BV_GBR_PIP_DUAL
;
341 if (!strcmp(arg
, "cdd"))
342 options
->lp_solver
= BV_LP_CDD
;
343 if (!strcmp(arg
, "cddf"))
344 options
->lp_solver
= BV_LP_CDDF
;
345 if (!strcmp(arg
, "glpk"))
346 options
->lp_solver
= BV_LP_GLPK
;
347 if (!strcmp(arg
, "pip"))
348 options
->lp_solver
= BV_LP_PIP
;
349 if (!strcmp(arg
, "polylib"))
350 options
->lp_solver
= BV_LP_POLYLIB
;
352 case BV_OPT_MAXINDEX
:
353 options
->max_index
= strtoul(arg
, NULL
, 0);
356 if (!strcmp(arg
, "box"))
357 options
->summation
= BV_SUM_BOX
;
358 else if (!strcmp(arg
, "barvinok"))
359 options
->summation
= BV_SUM_BOX
;
360 else if (!strcmp(arg
, "euler"))
361 options
->summation
= BV_SUM_EULER
;
362 else if (!strcmp(arg
, "bernoulli"))
363 options
->summation
= BV_SUM_BERNOULLI
;
364 else if (!strcmp(arg
, "laurent"))
365 options
->summation
= BV_SUM_LAURENT
;
366 else if (!strcmp(arg
, "laurent_old"))
367 options
->summation
= BV_SUM_LAURENT_OLD
;
369 argp_error(state
, "unknown summation method '%s'\n", arg
);
372 if (!strcmp(arg
, "none"))
373 options
->bernstein_recurse
= 0;
374 else if (!strcmp(arg
, "factors"))
375 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
376 else if (!strcmp(arg
, "intervals"))
377 options
->bernstein_recurse
= BV_BERNSTEIN_INTERVALS
;
378 else if (!strcmp(arg
, "full"))
379 options
->bernstein_recurse
=
380 BV_BERNSTEIN_FACTORS
| BV_BERNSTEIN_INTERVALS
;
383 if (!strcmp(arg
, "gbr"))
384 options
->integer_hull
= BV_HULL_GBR
;
385 else if (!strcmp(arg
, "hilbert"))
386 options
->integer_hull
= BV_HULL_HILBERT
;
388 case BV_OPT_PRINT_STATS
:
389 options
->print_stats
= 1;
392 return ARGP_ERR_UNKNOWN
;
397 static struct argp approx_argp
= {
398 approx_argp_options
, approx_parse_opt
, 0, 0
401 static struct argp_child barvinok_children
[] = {
402 { &approx_argp
, 0, "polynomial approximation", BV_GRP_APPROX
},
406 struct argp barvinok_argp
= {
407 barvinok_argp_options
, barvinok_parse_opt
, 0, 0, barvinok_children