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
);
33 struct barvinok_options
*barvinok_options_new_with_defaults()
35 struct barvinok_options
*options
= ALLOC(struct barvinok_options
);
39 options
->stats
= ALLOC(struct barvinok_stats
);
40 if (!options
->stats
) {
45 barvinok_stats_clear(options
->stats
);
50 options
->MaxRays
= MAXRAYS
;
52 #ifdef USE_INCREMENTAL_BF
53 options
->incremental_specialization
= 2;
54 #elif defined USE_INCREMENTAL_DF
55 options
->incremental_specialization
= 1;
57 options
->incremental_specialization
= 0;
59 options
->max_index
= 1;
62 options
->lookup_table
= 0;
64 options
->lookup_table
= 1;
66 options
->count_sample_infinite
= 1;
67 options
->try_Delaunay_triangulation
= 0;
69 options
->chambers
= BV_CHAMBERS_POLYLIB
;
71 options
->polynomial_approximation
= BV_APPROX_SIGN_NONE
;
72 options
->approximation_method
= BV_APPROX_NONE
;
73 options
->scale_flags
= 0;
74 options
->volume_triangulate
= BV_VOL_VERTEX
;
77 options
->gbr_lp_solver
= BV_GBR_GLPK
;
78 #elif defined HAVE_LIBCDDGMP
79 options
->gbr_lp_solver
= BV_GBR_CDD
;
81 options
->gbr_lp_solver
= BV_GBR_PIP
;
85 options
->lp_solver
= BV_LP_GLPK
;
86 #elif defined HAVE_LIBCDDGMP
87 options
->lp_solver
= BV_LP_CDD
;
89 options
->lp_solver
= BV_LP_PIP
;
92 options
->summation
= BV_SUM_BARVINOK
;
94 options
->bernstein_optimize
= BV_BERNSTEIN_NONE
;
96 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
98 options
->integer_hull
= BV_HULL_GBR
;
100 options
->verbose
= 0;
102 options
->print_stats
= 0;
104 options
->gbr_only_first
= 0;
109 void barvinok_options_free(struct barvinok_options
*options
)
111 free(options
->stats
);
123 const char *scale_opts
[] = {
132 static struct argp_option approx_argp_options
[] = {
133 { "polynomial-approximation", BV_OPT_POLAPPROX
, "lower|upper", 1 },
134 { "approximation-method", BV_OPT_APPROX
, "scale|drop|volume|bernoulli", 0,
135 "method to use in polynomial approximation [default: drop]" },
136 { "scale-options", BV_OPT_SCALE
,
137 "fast|slow,narrow|narrow2,chamber", 0 },
138 { "volume-triangulation", BV_OPT_VOL
, "lift|vertex|barycenter", 0,
139 "type of triangulation to perform in volume computation [default: vertex]" },
143 static struct argp_option barvinok_argp_options
[] = {
144 { "index", BV_OPT_MAXINDEX
, "int", 0,
145 "maximal index of simple cones in decomposition" },
146 { "primal", BV_OPT_PRIMAL
, 0, 0 },
147 { "table", BV_OPT_TABLE
, 0, 0 },
148 { "specialization", BV_OPT_SPECIALIZATION
, "[bf|df|random|todd]" },
149 #ifdef POINTS2TRIANGS_PATH
150 { "chamber-decomposition", BV_OPT_CHAMBERS
, "polylib|topcom", 0,
151 "tool to use for chamber decomposition [default: polylib]" },
154 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
155 "cdd|glpk|pip|pip-dual",
156 #elif defined(HAVE_LIBGLPK)
158 #elif defined(HAVE_LIBCDDGMP)
163 0, "lp solver to use for basis reduction "
166 #elif defined HAVE_LIBCDDGMP
173 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
174 "cdd|cddf|glpk|pip|polylib",
175 #elif defined(HAVE_LIBGLPK)
177 #elif defined(HAVE_LIBCDDGMP)
178 "cdd|cddf|pip|polylib",
182 0, "lp solver to use "
183 #if defined(HAVE_LIBGLPK)
185 #elif defined(HAVE_LIBCDDGMP)
191 { "summation", BV_OPT_SUM
, "barvinok|bernoulli|euler", 0,
192 "[default: barvinok]" },
193 { "bernstein-recurse", BV_OPT_RECURSE
, "none|factors|intervals|full", 0,
194 "[default: factors]" },
195 { "recurse", BV_OPT_RECURSE
, "",
196 OPTION_ALIAS
| OPTION_HIDDEN
},
197 { "integer-hull", BV_OPT_HULL
, "gbr|hilbert", 0,
199 { "version", 'V', 0, 0 },
201 { "print-stats", BV_OPT_PRINT_STATS
, 0, 0 },
205 static error_t
approx_parse_opt(int key
, char *arg
, struct argp_state
*state
)
207 struct barvinok_options
*options
= state
->input
;
211 case BV_OPT_POLAPPROX
:
213 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
214 if (options
->approximation_method
== BV_APPROX_NONE
)
215 options
->approximation_method
= BV_APPROX_SCALE
;
217 if (!strcmp(arg
, "lower"))
218 options
->polynomial_approximation
= BV_APPROX_SIGN_LOWER
;
219 else if (!strcmp(arg
, "upper"))
220 options
->polynomial_approximation
= BV_APPROX_SIGN_UPPER
;
221 if (options
->approximation_method
== BV_APPROX_NONE
)
222 options
->approximation_method
= BV_APPROX_DROP
;
226 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
)
227 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
228 if (!strcmp(arg
, "scale"))
229 options
->approximation_method
= BV_APPROX_SCALE
;
230 else if (!strcmp(arg
, "drop"))
231 options
->approximation_method
= BV_APPROX_DROP
;
232 else if (!strcmp(arg
, "volume"))
233 options
->approximation_method
= BV_APPROX_VOLUME
;
234 else if (!strcmp(arg
, "bernoulli"))
235 options
->approximation_method
= BV_APPROX_BERNOULLI
;
237 argp_error(state
, "unknown value for --approximation-method option");
240 options
->approximation_method
= BV_APPROX_SCALE
;
242 switch (getsubopt(&arg
, scale_opts
, &subopt
)) {
244 options
->scale_flags
|= BV_APPROX_SCALE_FAST
;
247 options
->scale_flags
&= ~BV_APPROX_SCALE_FAST
;
250 options
->scale_flags
|= BV_APPROX_SCALE_NARROW
;
251 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW2
;
254 options
->scale_flags
|= BV_APPROX_SCALE_NARROW2
;
255 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW
;
258 options
->scale_flags
|= BV_APPROX_SCALE_CHAMBER
;
261 argp_error(state
, "unknown suboption '%s'\n", subopt
);
265 if (!strcmp(arg
, "lift"))
266 options
->volume_triangulate
= BV_VOL_LIFT
;
267 else if (!strcmp(arg
, "vertex"))
268 options
->volume_triangulate
= BV_VOL_VERTEX
;
269 else if (!strcmp(arg
, "barycenter"))
270 options
->volume_triangulate
= BV_VOL_BARYCENTER
;
273 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
&&
274 options
->approximation_method
!= BV_APPROX_NONE
) {
276 "no polynomial approximation selected; reseting approximation method\n");
277 options
->approximation_method
= BV_APPROX_NONE
;
281 return ARGP_ERR_UNKNOWN
;
286 static error_t
barvinok_parse_opt(int key
, char *arg
, struct argp_state
*state
)
288 struct barvinok_options
*options
= state
->input
;
293 state
->child_inputs
[0] = options
;
296 options
->verbose
= 1;
299 printf(barvinok_version());
301 case BV_OPT_SPECIALIZATION
:
302 if (!strcmp(arg
, "bf"))
303 options
->incremental_specialization
= BV_SPECIALIZATION_BF
;
304 else if (!strcmp(arg
, "df"))
305 options
->incremental_specialization
= BV_SPECIALIZATION_DF
;
306 else if (!strcmp(arg
, "random"))
307 options
->incremental_specialization
= BV_SPECIALIZATION_RANDOM
;
308 else if (!strcmp(arg
, "todd"))
309 options
->incremental_specialization
= BV_SPECIALIZATION_TODD
;
315 options
->lookup_table
= 1;
317 case BV_OPT_CHAMBERS
:
318 if (!strcmp(arg
, "polylib"))
319 options
->chambers
= BV_CHAMBERS_POLYLIB
;
320 if (!strcmp(arg
, "topcom"))
321 options
->chambers
= BV_CHAMBERS_TOPCOM
;
324 if (!strcmp(arg
, "cdd"))
325 options
->gbr_lp_solver
= BV_GBR_CDD
;
326 if (!strcmp(arg
, "glpk"))
327 options
->gbr_lp_solver
= BV_GBR_GLPK
;
328 if (!strcmp(arg
, "pip"))
329 options
->gbr_lp_solver
= BV_GBR_PIP
;
330 if (!strcmp(arg
, "pip-dual"))
331 options
->gbr_lp_solver
= BV_GBR_PIP_DUAL
;
334 if (!strcmp(arg
, "cdd"))
335 options
->lp_solver
= BV_LP_CDD
;
336 if (!strcmp(arg
, "cddf"))
337 options
->lp_solver
= BV_LP_CDDF
;
338 if (!strcmp(arg
, "glpk"))
339 options
->lp_solver
= BV_LP_GLPK
;
340 if (!strcmp(arg
, "pip"))
341 options
->lp_solver
= BV_LP_PIP
;
342 if (!strcmp(arg
, "polylib"))
343 options
->lp_solver
= BV_LP_POLYLIB
;
345 case BV_OPT_MAXINDEX
:
346 options
->max_index
= strtoul(arg
, NULL
, 0);
349 if (!strcmp(arg
, "barvinok"))
350 options
->summation
= BV_SUM_BARVINOK
;
351 if (!strcmp(arg
, "euler"))
352 options
->summation
= BV_SUM_EULER
;
353 if (!strcmp(arg
, "bernoulli"))
354 options
->summation
= BV_SUM_BERNOULLI
;
357 if (!strcmp(arg
, "none"))
358 options
->bernstein_recurse
= 0;
359 else if (!strcmp(arg
, "factors"))
360 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
361 else if (!strcmp(arg
, "intervals"))
362 options
->bernstein_recurse
= BV_BERNSTEIN_INTERVALS
;
363 else if (!strcmp(arg
, "full"))
364 options
->bernstein_recurse
=
365 BV_BERNSTEIN_FACTORS
| BV_BERNSTEIN_INTERVALS
;
368 if (!strcmp(arg
, "gbr"))
369 options
->integer_hull
= BV_HULL_GBR
;
370 else if (!strcmp(arg
, "hilbert"))
371 options
->integer_hull
= BV_HULL_HILBERT
;
373 case BV_OPT_PRINT_STATS
:
374 options
->print_stats
= 1;
377 return ARGP_ERR_UNKNOWN
;
382 static struct argp approx_argp
= {
383 approx_argp_options
, approx_parse_opt
, 0, 0
386 static struct argp_child barvinok_children
[] = {
387 { &approx_argp
, 0, "polynomial approximation", BV_GRP_APPROX
},
391 struct argp barvinok_argp
= {
392 barvinok_argp_options
, barvinok_parse_opt
, 0, 0, barvinok_children