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;
72 options
->bound
= BV_BOUND_BERNSTEIN
;
74 options
->bound
= BV_BOUND_RANGE
;
76 options
->chambers
= BV_CHAMBERS_POLYLIB
;
78 options
->polynomial_approximation
= BV_APPROX_SIGN_NONE
;
79 options
->approximation_method
= BV_APPROX_NONE
;
80 options
->scale_flags
= 0;
81 options
->volume_triangulate
= BV_VOL_VERTEX
;
84 options
->gbr_lp_solver
= BV_GBR_GLPK
;
85 #elif defined HAVE_LIBCDDGMP
86 options
->gbr_lp_solver
= BV_GBR_CDD
;
88 options
->gbr_lp_solver
= BV_GBR_PIP
;
92 options
->lp_solver
= BV_LP_GLPK
;
93 #elif defined HAVE_LIBCDDGMP
94 options
->lp_solver
= BV_LP_CDD
;
96 options
->lp_solver
= BV_LP_PIP
;
99 options
->summation
= BV_SUM_LAURENT
;
101 options
->bernstein_optimize
= BV_BERNSTEIN_NONE
;
103 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
105 options
->integer_hull
= BV_HULL_GBR
;
107 options
->verbose
= 0;
109 options
->print_stats
= 0;
111 options
->gbr_only_first
= 0;
116 void barvinok_options_free(struct barvinok_options
*options
)
118 free(options
->stats
);
130 const char *scale_opts
[] = {
139 static struct argp_option approx_argp_options
[] = {
140 { "polynomial-approximation", BV_OPT_POLAPPROX
, "lower|upper", 1 },
141 { "approximation-method", BV_OPT_APPROX
, "scale|drop|volume|bernoulli", 0,
142 "method to use in polynomial approximation [default: drop]" },
143 { "scale-options", BV_OPT_SCALE
,
144 "fast|slow,narrow|narrow2,chamber", 0 },
145 { "volume-triangulation", BV_OPT_VOL
, "lift|vertex|barycenter", 0,
146 "type of triangulation to perform in volume computation [default: vertex]" },
150 static struct argp_option barvinok_argp_options
[] = {
151 { "index", BV_OPT_MAXINDEX
, "int", 0,
152 "maximal index of simple cones in decomposition" },
153 { "primal", BV_OPT_PRIMAL
, 0, 0 },
154 { "table", BV_OPT_TABLE
, 0, 0 },
155 { "specialization", BV_OPT_SPECIALIZATION
, "[bf|df|random|todd]" },
157 { "bound", BV_OPT_BOUND
, "bernstein|range", 0,
158 "algorithm to use for computing bounds [default: bernstein]" },
160 #ifdef POINTS2TRIANGS_PATH
161 { "chamber-decomposition", BV_OPT_CHAMBERS
, "polylib|topcom", 0,
162 "tool to use for chamber decomposition [default: polylib]" },
165 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
166 "cdd|glpk|pip|pip-dual",
167 #elif defined(HAVE_LIBGLPK)
169 #elif defined(HAVE_LIBCDDGMP)
174 0, "lp solver to use for basis reduction "
177 #elif defined HAVE_LIBCDDGMP
184 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
185 "cdd|cddf|glpk|pip|polylib",
186 #elif defined(HAVE_LIBGLPK)
188 #elif defined(HAVE_LIBCDDGMP)
189 "cdd|cddf|pip|polylib",
193 0, "lp solver to use "
194 #if defined(HAVE_LIBGLPK)
196 #elif defined(HAVE_LIBCDDGMP)
202 { "summation", BV_OPT_SUM
, "box|bernoulli|euler|laurent", 0,
203 "[default: laurent]" },
204 { "bernstein-recurse", BV_OPT_RECURSE
, "none|factors|intervals|full", 0,
205 "[default: factors]" },
206 { "recurse", BV_OPT_RECURSE
, "",
207 OPTION_ALIAS
| OPTION_HIDDEN
},
208 { "integer-hull", BV_OPT_HULL
,
214 0, "[default: gbr]" },
215 { "version", 'V', 0, 0 },
217 { "print-stats", BV_OPT_PRINT_STATS
, 0, 0 },
221 static error_t
approx_parse_opt(int key
, char *arg
, struct argp_state
*state
)
223 struct barvinok_options
*options
= state
->input
;
227 case BV_OPT_POLAPPROX
:
229 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
230 if (options
->approximation_method
== BV_APPROX_NONE
)
231 options
->approximation_method
= BV_APPROX_SCALE
;
233 if (!strcmp(arg
, "lower"))
234 options
->polynomial_approximation
= BV_APPROX_SIGN_LOWER
;
235 else if (!strcmp(arg
, "upper"))
236 options
->polynomial_approximation
= BV_APPROX_SIGN_UPPER
;
237 if (options
->approximation_method
== BV_APPROX_NONE
)
238 options
->approximation_method
= BV_APPROX_DROP
;
242 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
)
243 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
244 if (!strcmp(arg
, "scale"))
245 options
->approximation_method
= BV_APPROX_SCALE
;
246 else if (!strcmp(arg
, "drop"))
247 options
->approximation_method
= BV_APPROX_DROP
;
248 else if (!strcmp(arg
, "volume"))
249 options
->approximation_method
= BV_APPROX_VOLUME
;
250 else if (!strcmp(arg
, "bernoulli"))
251 options
->approximation_method
= BV_APPROX_BERNOULLI
;
253 argp_error(state
, "unknown value for --approximation-method option");
256 options
->approximation_method
= BV_APPROX_SCALE
;
258 switch (getsubopt(&arg
, scale_opts
, &subopt
)) {
260 options
->scale_flags
|= BV_APPROX_SCALE_FAST
;
263 options
->scale_flags
&= ~BV_APPROX_SCALE_FAST
;
266 options
->scale_flags
|= BV_APPROX_SCALE_NARROW
;
267 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW2
;
270 options
->scale_flags
|= BV_APPROX_SCALE_NARROW2
;
271 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW
;
274 options
->scale_flags
|= BV_APPROX_SCALE_CHAMBER
;
277 argp_error(state
, "unknown suboption '%s'\n", subopt
);
281 if (!strcmp(arg
, "lift"))
282 options
->volume_triangulate
= BV_VOL_LIFT
;
283 else if (!strcmp(arg
, "vertex"))
284 options
->volume_triangulate
= BV_VOL_VERTEX
;
285 else if (!strcmp(arg
, "barycenter"))
286 options
->volume_triangulate
= BV_VOL_BARYCENTER
;
289 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
&&
290 options
->approximation_method
!= BV_APPROX_NONE
) {
292 "no polynomial approximation selected; reseting approximation method\n");
293 options
->approximation_method
= BV_APPROX_NONE
;
297 return ARGP_ERR_UNKNOWN
;
302 static error_t
barvinok_parse_opt(int key
, char *arg
, struct argp_state
*state
)
304 struct barvinok_options
*options
= state
->input
;
309 state
->child_inputs
[0] = options
;
315 printf(barvinok_version());
317 case BV_OPT_SPECIALIZATION
:
318 if (!strcmp(arg
, "bf"))
319 options
->incremental_specialization
= BV_SPECIALIZATION_BF
;
320 else if (!strcmp(arg
, "df"))
321 options
->incremental_specialization
= BV_SPECIALIZATION_DF
;
322 else if (!strcmp(arg
, "random"))
323 options
->incremental_specialization
= BV_SPECIALIZATION_RANDOM
;
324 else if (!strcmp(arg
, "todd"))
325 options
->incremental_specialization
= BV_SPECIALIZATION_TODD
;
331 options
->lookup_table
= 1;
334 if (!strcmp(arg
, "bernstein"))
335 options
->bound
= BV_BOUND_BERNSTEIN
;
336 if (!strcmp(arg
, "range"))
337 options
->bound
= BV_BOUND_RANGE
;
339 case BV_OPT_CHAMBERS
:
340 if (!strcmp(arg
, "polylib"))
341 options
->chambers
= BV_CHAMBERS_POLYLIB
;
342 if (!strcmp(arg
, "topcom"))
343 options
->chambers
= BV_CHAMBERS_TOPCOM
;
346 if (!strcmp(arg
, "cdd"))
347 options
->gbr_lp_solver
= BV_GBR_CDD
;
348 if (!strcmp(arg
, "glpk"))
349 options
->gbr_lp_solver
= BV_GBR_GLPK
;
350 if (!strcmp(arg
, "pip"))
351 options
->gbr_lp_solver
= BV_GBR_PIP
;
352 if (!strcmp(arg
, "pip-dual"))
353 options
->gbr_lp_solver
= BV_GBR_PIP_DUAL
;
356 if (!strcmp(arg
, "cdd"))
357 options
->lp_solver
= BV_LP_CDD
;
358 if (!strcmp(arg
, "cddf"))
359 options
->lp_solver
= BV_LP_CDDF
;
360 if (!strcmp(arg
, "glpk"))
361 options
->lp_solver
= BV_LP_GLPK
;
362 if (!strcmp(arg
, "pip"))
363 options
->lp_solver
= BV_LP_PIP
;
364 if (!strcmp(arg
, "polylib"))
365 options
->lp_solver
= BV_LP_POLYLIB
;
367 case BV_OPT_MAXINDEX
:
368 options
->max_index
= strtoul(arg
, NULL
, 0);
371 if (!strcmp(arg
, "box"))
372 options
->summation
= BV_SUM_BOX
;
373 else if (!strcmp(arg
, "barvinok"))
374 options
->summation
= BV_SUM_BOX
;
375 else if (!strcmp(arg
, "euler"))
376 options
->summation
= BV_SUM_EULER
;
377 else if (!strcmp(arg
, "bernoulli"))
378 options
->summation
= BV_SUM_BERNOULLI
;
379 else if (!strcmp(arg
, "laurent"))
380 options
->summation
= BV_SUM_LAURENT
;
381 else if (!strcmp(arg
, "laurent_old"))
382 options
->summation
= BV_SUM_LAURENT_OLD
;
384 argp_error(state
, "unknown summation method '%s'\n", arg
);
387 if (!strcmp(arg
, "none"))
388 options
->bernstein_recurse
= 0;
389 else if (!strcmp(arg
, "factors"))
390 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
391 else if (!strcmp(arg
, "intervals"))
392 options
->bernstein_recurse
= BV_BERNSTEIN_INTERVALS
;
393 else if (!strcmp(arg
, "full"))
394 options
->bernstein_recurse
=
395 BV_BERNSTEIN_FACTORS
| BV_BERNSTEIN_INTERVALS
;
398 if (!strcmp(arg
, "gbr"))
399 options
->integer_hull
= BV_HULL_GBR
;
400 else if (!strcmp(arg
, "hilbert"))
401 options
->integer_hull
= BV_HULL_HILBERT
;
403 case BV_OPT_PRINT_STATS
:
404 options
->print_stats
= 1;
407 return ARGP_ERR_UNKNOWN
;
412 static struct argp approx_argp
= {
413 approx_argp_options
, approx_parse_opt
, 0, 0
416 static struct argp_child barvinok_children
[] = {
417 { &approx_argp
, 0, "polynomial approximation", BV_GRP_APPROX
},
421 struct argp barvinok_argp
= {
422 barvinok_argp_options
, barvinok_parse_opt
, 0, 0, barvinok_children