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
);
31 struct barvinok_options
*barvinok_options_new_with_defaults()
33 struct barvinok_options
*options
= ALLOC(struct barvinok_options
);
37 options
->stats
= ALLOC(struct barvinok_stats
);
38 if (!options
->stats
) {
43 barvinok_stats_clear(options
->stats
);
48 options
->MaxRays
= MAXRAYS
;
50 #ifdef USE_INCREMENTAL_BF
51 options
->incremental_specialization
= 2;
52 #elif defined USE_INCREMENTAL_DF
53 options
->incremental_specialization
= 1;
55 options
->incremental_specialization
= 0;
57 options
->max_index
= 1;
60 options
->lookup_table
= 0;
62 options
->lookup_table
= 1;
64 options
->count_sample_infinite
= 1;
65 options
->try_Delaunay_triangulation
= 0;
67 options
->chambers
= BV_CHAMBERS_POLYLIB
;
69 options
->polynomial_approximation
= BV_APPROX_SIGN_NONE
;
70 options
->approximation_method
= BV_APPROX_NONE
;
71 options
->scale_flags
= 0;
72 options
->volume_triangulate
= BV_VOL_VERTEX
;
75 options
->gbr_lp_solver
= BV_GBR_GLPK
;
76 #elif defined HAVE_LIBCDDGMP
77 options
->gbr_lp_solver
= BV_GBR_CDD
;
79 options
->gbr_lp_solver
= BV_GBR_PIP
;
83 options
->lp_solver
= BV_LP_GLPK
;
84 #elif defined HAVE_LIBCDDGMP
85 options
->lp_solver
= BV_LP_CDD
;
87 options
->lp_solver
= BV_LP_POLYLIB
;
90 options
->summation
= BV_SUM_BARVINOK
;
92 options
->bernstein_optimize
= BV_BERNSTEIN_NONE
;
94 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
101 void barvinok_options_free(struct barvinok_options
*options
)
103 free(options
->stats
);
115 const char *scale_opts
[] = {
124 static struct argp_option approx_argp_options
[] = {
125 { "polynomial-approximation", BV_OPT_POLAPPROX
, "lower|upper", 1 },
126 { "approximation-method", BV_OPT_APPROX
, "scale|drop|volume|bernoulli", 0,
127 "method to use in polynomial approximation [default: drop]" },
128 { "scale-options", BV_OPT_SCALE
,
129 "fast|slow,narrow|narrow2,chamber", 0 },
130 { "volume-triangulation", BV_OPT_VOL
, "lift|vertex|barycenter", 0,
131 "type of triangulation to perform in volume computation [default: vertex]" },
135 static struct argp_option barvinok_argp_options
[] = {
136 { "index", BV_OPT_MAXINDEX
, "int", 0,
137 "maximal index of simple cones in decomposition" },
138 { "primal", BV_OPT_PRIMAL
, 0, 0 },
139 { "table", BV_OPT_TABLE
, 0, 0 },
140 { "specialization", BV_OPT_SPECIALIZATION
, "[bf|df|random|todd]" },
141 #ifdef POINTS2TRIANGS_PATH
142 { "chamber-decomposition", BV_OPT_CHAMBERS
, "polylib|topcom", 0,
143 "tool to use for chamber decomposition [default: polylib]" },
146 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
147 "cdd|glpk|pip|pip-dual",
148 #elif defined(HAVE_LIBGLPK)
150 #elif defined(HAVE_LIBCDDGMP)
155 0, "lp solver to use for basis reduction "
158 #elif defined HAVE_LIBCDDGMP
165 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
166 "cdd|cddf|glpk|polylib",
167 #elif defined(HAVE_LIBGLPK)
169 #elif defined(HAVE_LIBCDDGMP)
174 0, "lp solver to use "
175 #if defined(HAVE_LIBGLPK)
177 #elif defined(HAVE_LIBCDDGMP)
180 "[default: polylib]",
183 { "summation", BV_OPT_SUM
, "barvinok|bernoulli|euler", 0,
184 "[default: barvinok]" },
185 { "bernstein-recurse", BV_OPT_RECURSE
, "none|factors|intervals|full", 0,
186 "[default: factors]" },
187 { "recurse", BV_OPT_RECURSE
, "",
188 OPTION_ALIAS
| OPTION_HIDDEN
},
189 { "version", 'V', 0, 0 },
194 static error_t
approx_parse_opt(int key
, char *arg
, struct argp_state
*state
)
196 struct barvinok_options
*options
= state
->input
;
200 case BV_OPT_POLAPPROX
:
202 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
203 if (options
->approximation_method
== BV_APPROX_NONE
)
204 options
->approximation_method
= BV_APPROX_SCALE
;
206 if (!strcmp(arg
, "lower"))
207 options
->polynomial_approximation
= BV_APPROX_SIGN_LOWER
;
208 else if (!strcmp(arg
, "upper"))
209 options
->polynomial_approximation
= BV_APPROX_SIGN_UPPER
;
210 if (options
->approximation_method
== BV_APPROX_NONE
)
211 options
->approximation_method
= BV_APPROX_DROP
;
215 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
)
216 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
217 if (!strcmp(arg
, "scale"))
218 options
->approximation_method
= BV_APPROX_SCALE
;
219 else if (!strcmp(arg
, "drop"))
220 options
->approximation_method
= BV_APPROX_DROP
;
221 else if (!strcmp(arg
, "volume"))
222 options
->approximation_method
= BV_APPROX_VOLUME
;
223 else if (!strcmp(arg
, "bernoulli"))
224 options
->approximation_method
= BV_APPROX_BERNOULLI
;
226 argp_error(state
, "unknown value for --approximation-method option");
229 options
->approximation_method
= BV_APPROX_SCALE
;
231 switch (getsubopt(&arg
, scale_opts
, &subopt
)) {
233 options
->scale_flags
|= BV_APPROX_SCALE_FAST
;
236 options
->scale_flags
&= ~BV_APPROX_SCALE_FAST
;
239 options
->scale_flags
|= BV_APPROX_SCALE_NARROW
;
240 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW2
;
243 options
->scale_flags
|= BV_APPROX_SCALE_NARROW2
;
244 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW
;
247 options
->scale_flags
|= BV_APPROX_SCALE_CHAMBER
;
250 argp_error(state
, "unknown suboption '%s'\n", subopt
);
254 if (!strcmp(arg
, "lift"))
255 options
->volume_triangulate
= BV_VOL_LIFT
;
256 else if (!strcmp(arg
, "vertex"))
257 options
->volume_triangulate
= BV_VOL_VERTEX
;
258 else if (!strcmp(arg
, "barycenter"))
259 options
->volume_triangulate
= BV_VOL_BARYCENTER
;
262 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
&&
263 options
->approximation_method
!= BV_APPROX_NONE
) {
265 "no polynomial approximation selected; reseting approximation method\n");
266 options
->approximation_method
= BV_APPROX_NONE
;
270 return ARGP_ERR_UNKNOWN
;
275 static error_t
barvinok_parse_opt(int key
, char *arg
, struct argp_state
*state
)
277 struct barvinok_options
*options
= state
->input
;
282 state
->child_inputs
[0] = options
;
285 options
->verbose
= 1;
288 printf(barvinok_version());
290 case BV_OPT_SPECIALIZATION
:
291 if (!strcmp(arg
, "bf"))
292 options
->incremental_specialization
= BV_SPECIALIZATION_BF
;
293 else if (!strcmp(arg
, "df"))
294 options
->incremental_specialization
= BV_SPECIALIZATION_DF
;
295 else if (!strcmp(arg
, "random"))
296 options
->incremental_specialization
= BV_SPECIALIZATION_RANDOM
;
297 else if (!strcmp(arg
, "todd"))
298 options
->incremental_specialization
= BV_SPECIALIZATION_TODD
;
304 options
->lookup_table
= 1;
306 case BV_OPT_CHAMBERS
:
307 if (!strcmp(arg
, "polylib"))
308 options
->chambers
= BV_CHAMBERS_POLYLIB
;
309 if (!strcmp(arg
, "topcom"))
310 options
->chambers
= BV_CHAMBERS_TOPCOM
;
313 if (!strcmp(arg
, "cdd"))
314 options
->gbr_lp_solver
= BV_GBR_CDD
;
315 if (!strcmp(arg
, "glpk"))
316 options
->gbr_lp_solver
= BV_GBR_GLPK
;
317 if (!strcmp(arg
, "pip"))
318 options
->gbr_lp_solver
= BV_GBR_PIP
;
319 if (!strcmp(arg
, "pip-dual"))
320 options
->gbr_lp_solver
= BV_GBR_PIP_DUAL
;
323 if (!strcmp(arg
, "cdd"))
324 options
->lp_solver
= BV_LP_CDD
;
325 if (!strcmp(arg
, "cddf"))
326 options
->lp_solver
= BV_LP_CDDF
;
327 if (!strcmp(arg
, "glpk"))
328 options
->lp_solver
= BV_LP_GLPK
;
329 if (!strcmp(arg
, "polylib"))
330 options
->lp_solver
= BV_LP_POLYLIB
;
332 case BV_OPT_MAXINDEX
:
333 options
->max_index
= strtoul(arg
, NULL
, 0);
336 if (!strcmp(arg
, "barvinok"))
337 options
->summation
= BV_SUM_BARVINOK
;
338 if (!strcmp(arg
, "euler"))
339 options
->summation
= BV_SUM_EULER
;
340 if (!strcmp(arg
, "bernoulli"))
341 options
->summation
= BV_SUM_BERNOULLI
;
344 if (!strcmp(arg
, "none"))
345 options
->bernstein_recurse
= 0;
346 else if (!strcmp(arg
, "factors"))
347 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
348 else if (!strcmp(arg
, "intervals"))
349 options
->bernstein_recurse
= BV_BERNSTEIN_INTERVALS
;
350 else if (!strcmp(arg
, "full"))
351 options
->bernstein_recurse
=
352 BV_BERNSTEIN_FACTORS
| BV_BERNSTEIN_INTERVALS
;
355 return ARGP_ERR_UNKNOWN
;
360 static struct argp approx_argp
= {
361 approx_argp_options
, approx_parse_opt
, 0, 0
364 static struct argp_child barvinok_children
[] = {
365 { &approx_argp
, 0, "polynomial approximation", BV_GRP_APPROX
},
369 struct argp barvinok_argp
= {
370 barvinok_argp_options
, barvinok_parse_opt
, 0, 0, barvinok_children