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: %ld\n", stats
->base_cones
);
20 if (stats
->volume_simplices
)
21 fprintf(out
, "Volume simplices: %ld\n", stats
->volume_simplices
);
22 if (stats
->topcom_chambers
) {
23 fprintf(out
, "TOPCOM empty chambers: %ld\n",
24 stats
->topcom_empty_chambers
);
25 fprintf(out
, "TOPCOM chambers: %ld\n", stats
->topcom_chambers
);
26 fprintf(out
, "TOPCOM distinct chambers: %ld\n",
27 stats
->topcom_distinct_chambers
);
29 if (stats
->gbr_solved_lps
)
30 fprintf(out
, "LPs solved during GBR: %ld\n", stats
->gbr_solved_lps
);
31 if (stats
->bernoulli_sums
)
32 fprintf(out
, "Bernoulli sums: %ld\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
->bound
= BV_BOUND_BERNSTEIN
;
72 options
->chambers
= BV_CHAMBERS_POLYLIB
;
74 options
->polynomial_approximation
= BV_APPROX_SIGN_NONE
;
75 options
->approximation_method
= BV_APPROX_NONE
;
76 options
->scale_flags
= 0;
77 options
->volume_triangulate
= BV_VOL_VERTEX
;
80 options
->gbr_lp_solver
= BV_GBR_GLPK
;
81 #elif defined HAVE_LIBCDDGMP
82 options
->gbr_lp_solver
= BV_GBR_CDD
;
84 options
->gbr_lp_solver
= BV_GBR_PIP
;
88 options
->lp_solver
= BV_LP_GLPK
;
89 #elif defined HAVE_LIBCDDGMP
90 options
->lp_solver
= BV_LP_CDD
;
92 options
->lp_solver
= BV_LP_PIP
;
95 options
->summation
= BV_SUM_LAURENT
;
97 options
->bernstein_optimize
= BV_BERNSTEIN_NONE
;
99 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
101 options
->integer_hull
= BV_HULL_GBR
;
103 options
->verbose
= 0;
105 options
->print_stats
= 0;
107 options
->gbr_only_first
= 0;
112 void barvinok_options_free(struct barvinok_options
*options
)
114 free(options
->stats
);
126 const char *scale_opts
[] = {
135 static struct argp_option approx_argp_options
[] = {
136 { "polynomial-approximation", BV_OPT_POLAPPROX
, "lower|upper", 1 },
137 { "approximation-method", BV_OPT_APPROX
, "scale|drop|volume|bernoulli", 0,
138 "method to use in polynomial approximation [default: drop]" },
139 { "scale-options", BV_OPT_SCALE
,
140 "fast|slow,narrow|narrow2,chamber", 0 },
141 { "volume-triangulation", BV_OPT_VOL
, "lift|vertex|barycenter", 0,
142 "type of triangulation to perform in volume computation [default: vertex]" },
146 static struct argp_option barvinok_argp_options
[] = {
147 { "index", BV_OPT_MAXINDEX
, "int", 0,
148 "maximal index of simple cones in decomposition" },
149 { "primal", BV_OPT_PRIMAL
, 0, 0 },
150 { "table", BV_OPT_TABLE
, 0, 0 },
151 { "specialization", BV_OPT_SPECIALIZATION
, "[bf|df|random|todd]" },
153 { "bound", BV_OPT_BOUND
, "bernstein|range", 0,
154 "algorithm to use for computing bounds [default: bernstein]" },
156 #ifdef POINTS2TRIANGS_PATH
157 { "chamber-decomposition", BV_OPT_CHAMBERS
, "polylib|topcom", 0,
158 "tool to use for chamber decomposition [default: polylib]" },
161 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
162 "cdd|glpk|pip|pip-dual",
163 #elif defined(HAVE_LIBGLPK)
165 #elif defined(HAVE_LIBCDDGMP)
170 0, "lp solver to use for basis reduction "
173 #elif defined HAVE_LIBCDDGMP
180 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
181 "cdd|cddf|glpk|pip|polylib",
182 #elif defined(HAVE_LIBGLPK)
184 #elif defined(HAVE_LIBCDDGMP)
185 "cdd|cddf|pip|polylib",
189 0, "lp solver to use "
190 #if defined(HAVE_LIBGLPK)
192 #elif defined(HAVE_LIBCDDGMP)
198 { "summation", BV_OPT_SUM
, "box|bernoulli|euler|laurent", 0,
199 "[default: laurent]" },
200 { "bernstein-recurse", BV_OPT_RECURSE
, "none|factors|intervals|full", 0,
201 "[default: factors]" },
202 { "recurse", BV_OPT_RECURSE
, "",
203 OPTION_ALIAS
| OPTION_HIDDEN
},
204 { "integer-hull", BV_OPT_HULL
,
210 0, "[default: gbr]" },
211 { "version", 'V', 0, 0 },
213 { "print-stats", BV_OPT_PRINT_STATS
, 0, 0 },
217 static error_t
approx_parse_opt(int key
, char *arg
, struct argp_state
*state
)
219 struct barvinok_options
*options
= state
->input
;
223 case BV_OPT_POLAPPROX
:
225 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
226 if (options
->approximation_method
== BV_APPROX_NONE
)
227 options
->approximation_method
= BV_APPROX_SCALE
;
229 if (!strcmp(arg
, "lower"))
230 options
->polynomial_approximation
= BV_APPROX_SIGN_LOWER
;
231 else if (!strcmp(arg
, "upper"))
232 options
->polynomial_approximation
= BV_APPROX_SIGN_UPPER
;
233 if (options
->approximation_method
== BV_APPROX_NONE
)
234 options
->approximation_method
= BV_APPROX_DROP
;
238 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
)
239 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
240 if (!strcmp(arg
, "scale"))
241 options
->approximation_method
= BV_APPROX_SCALE
;
242 else if (!strcmp(arg
, "drop"))
243 options
->approximation_method
= BV_APPROX_DROP
;
244 else if (!strcmp(arg
, "volume"))
245 options
->approximation_method
= BV_APPROX_VOLUME
;
246 else if (!strcmp(arg
, "bernoulli"))
247 options
->approximation_method
= BV_APPROX_BERNOULLI
;
249 argp_error(state
, "unknown value for --approximation-method option");
252 options
->approximation_method
= BV_APPROX_SCALE
;
254 switch (getsubopt(&arg
, scale_opts
, &subopt
)) {
256 options
->scale_flags
|= BV_APPROX_SCALE_FAST
;
259 options
->scale_flags
&= ~BV_APPROX_SCALE_FAST
;
262 options
->scale_flags
|= BV_APPROX_SCALE_NARROW
;
263 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW2
;
266 options
->scale_flags
|= BV_APPROX_SCALE_NARROW2
;
267 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW
;
270 options
->scale_flags
|= BV_APPROX_SCALE_CHAMBER
;
273 argp_error(state
, "unknown suboption '%s'\n", subopt
);
277 if (!strcmp(arg
, "lift"))
278 options
->volume_triangulate
= BV_VOL_LIFT
;
279 else if (!strcmp(arg
, "vertex"))
280 options
->volume_triangulate
= BV_VOL_VERTEX
;
281 else if (!strcmp(arg
, "barycenter"))
282 options
->volume_triangulate
= BV_VOL_BARYCENTER
;
285 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
&&
286 options
->approximation_method
!= BV_APPROX_NONE
) {
288 "no polynomial approximation selected; reseting approximation method\n");
289 options
->approximation_method
= BV_APPROX_NONE
;
293 return ARGP_ERR_UNKNOWN
;
298 static error_t
barvinok_parse_opt(int key
, char *arg
, struct argp_state
*state
)
300 struct barvinok_options
*options
= state
->input
;
305 state
->child_inputs
[0] = options
;
311 printf(barvinok_version());
313 case BV_OPT_SPECIALIZATION
:
314 if (!strcmp(arg
, "bf"))
315 options
->incremental_specialization
= BV_SPECIALIZATION_BF
;
316 else if (!strcmp(arg
, "df"))
317 options
->incremental_specialization
= BV_SPECIALIZATION_DF
;
318 else if (!strcmp(arg
, "random"))
319 options
->incremental_specialization
= BV_SPECIALIZATION_RANDOM
;
320 else if (!strcmp(arg
, "todd"))
321 options
->incremental_specialization
= BV_SPECIALIZATION_TODD
;
327 options
->lookup_table
= 1;
330 if (!strcmp(arg
, "bernstein"))
331 options
->bound
= BV_BOUND_BERNSTEIN
;
332 if (!strcmp(arg
, "range"))
333 options
->bound
= BV_BOUND_RANGE
;
335 case BV_OPT_CHAMBERS
:
336 if (!strcmp(arg
, "polylib"))
337 options
->chambers
= BV_CHAMBERS_POLYLIB
;
338 if (!strcmp(arg
, "topcom"))
339 options
->chambers
= BV_CHAMBERS_TOPCOM
;
342 if (!strcmp(arg
, "cdd"))
343 options
->gbr_lp_solver
= BV_GBR_CDD
;
344 if (!strcmp(arg
, "glpk"))
345 options
->gbr_lp_solver
= BV_GBR_GLPK
;
346 if (!strcmp(arg
, "pip"))
347 options
->gbr_lp_solver
= BV_GBR_PIP
;
348 if (!strcmp(arg
, "pip-dual"))
349 options
->gbr_lp_solver
= BV_GBR_PIP_DUAL
;
352 if (!strcmp(arg
, "cdd"))
353 options
->lp_solver
= BV_LP_CDD
;
354 if (!strcmp(arg
, "cddf"))
355 options
->lp_solver
= BV_LP_CDDF
;
356 if (!strcmp(arg
, "glpk"))
357 options
->lp_solver
= BV_LP_GLPK
;
358 if (!strcmp(arg
, "pip"))
359 options
->lp_solver
= BV_LP_PIP
;
360 if (!strcmp(arg
, "polylib"))
361 options
->lp_solver
= BV_LP_POLYLIB
;
363 case BV_OPT_MAXINDEX
:
364 options
->max_index
= strtoul(arg
, NULL
, 0);
367 if (!strcmp(arg
, "box"))
368 options
->summation
= BV_SUM_BOX
;
369 else if (!strcmp(arg
, "barvinok"))
370 options
->summation
= BV_SUM_BOX
;
371 else if (!strcmp(arg
, "euler"))
372 options
->summation
= BV_SUM_EULER
;
373 else if (!strcmp(arg
, "bernoulli"))
374 options
->summation
= BV_SUM_BERNOULLI
;
375 else if (!strcmp(arg
, "laurent"))
376 options
->summation
= BV_SUM_LAURENT
;
377 else if (!strcmp(arg
, "laurent_old"))
378 options
->summation
= BV_SUM_LAURENT_OLD
;
380 argp_error(state
, "unknown summation method '%s'\n", arg
);
383 if (!strcmp(arg
, "none"))
384 options
->bernstein_recurse
= 0;
385 else if (!strcmp(arg
, "factors"))
386 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
387 else if (!strcmp(arg
, "intervals"))
388 options
->bernstein_recurse
= BV_BERNSTEIN_INTERVALS
;
389 else if (!strcmp(arg
, "full"))
390 options
->bernstein_recurse
=
391 BV_BERNSTEIN_FACTORS
| BV_BERNSTEIN_INTERVALS
;
394 if (!strcmp(arg
, "gbr"))
395 options
->integer_hull
= BV_HULL_GBR
;
396 else if (!strcmp(arg
, "hilbert"))
397 options
->integer_hull
= BV_HULL_HILBERT
;
399 case BV_OPT_PRINT_STATS
:
400 options
->print_stats
= 1;
403 return ARGP_ERR_UNKNOWN
;
408 static struct argp approx_argp
= {
409 approx_argp_options
, approx_parse_opt
, 0, 0
412 static struct argp_child barvinok_children
[] = {
413 { &approx_argp
, 0, "polynomial approximation", BV_GRP_APPROX
},
417 struct argp barvinok_argp
= {
418 barvinok_argp_options
, barvinok_parse_opt
, 0, 0, barvinok_children