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
;
99 void barvinok_options_free(struct barvinok_options
*options
)
101 free(options
->stats
);
113 const char *scale_opts
[] = {
122 static struct argp_option approx_argp_options
[] = {
123 { "polynomial-approximation", BV_OPT_POLAPPROX
, "lower|upper", 1 },
124 { "approximation-method", BV_OPT_APPROX
, "scale|drop|volume|bernoulli", 0,
125 "method to use in polynomial approximation [default: drop]" },
126 { "scale-options", BV_OPT_SCALE
,
127 "fast|slow,narrow|narrow2,chamber", 0 },
128 { "volume-triangulation", BV_OPT_VOL
, "lift|vertex|barycenter", 0,
129 "type of triangulation to perform in volume computation [default: vertex]" },
133 static struct argp_option barvinok_argp_options
[] = {
134 { "index", BV_OPT_MAXINDEX
, "int", 0,
135 "maximal index of simple cones in decomposition" },
136 { "primal", BV_OPT_PRIMAL
, 0, 0 },
137 { "table", BV_OPT_TABLE
, 0, 0 },
138 { "specialization", BV_OPT_SPECIALIZATION
, "[bf|df|random|todd]" },
139 #ifdef POINTS2TRIANGS_PATH
140 { "chamber-decomposition", BV_OPT_CHAMBERS
, "polylib|topcom", 0,
141 "tool to use for chamber decomposition [default: polylib]" },
144 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
145 "cdd|glpk|pip|pip-dual",
146 #elif defined(HAVE_LIBGLPK)
148 #elif defined(HAVE_LIBCDDGMP)
153 0, "lp solver to use for basis reduction "
156 #elif defined HAVE_LIBCDDGMP
163 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
164 "cdd|cddf|glpk|polylib",
165 #elif defined(HAVE_LIBGLPK)
167 #elif defined(HAVE_LIBCDDGMP)
172 0, "lp solver to use "
173 #if defined(HAVE_LIBGLPK)
175 #elif defined(HAVE_LIBCDDGMP)
178 "[default: polylib]",
181 { "summation", BV_OPT_SUM
, "barvinok|bernoulli|euler", 0,
182 "[default: barvinok]" },
183 { "bernstein-recurse", BV_OPT_RECURSE
, "none|factors|intervals|full", 0,
184 "[default: factors]" },
185 { "recurse", BV_OPT_RECURSE
, "",
186 OPTION_ALIAS
| OPTION_HIDDEN
},
187 { "version", 'V', 0, 0 },
191 static error_t
approx_parse_opt(int key
, char *arg
, struct argp_state
*state
)
193 struct barvinok_options
*options
= state
->input
;
197 case BV_OPT_POLAPPROX
:
199 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
200 if (options
->approximation_method
== BV_APPROX_NONE
)
201 options
->approximation_method
= BV_APPROX_SCALE
;
203 if (!strcmp(arg
, "lower"))
204 options
->polynomial_approximation
= BV_APPROX_SIGN_LOWER
;
205 else if (!strcmp(arg
, "upper"))
206 options
->polynomial_approximation
= BV_APPROX_SIGN_UPPER
;
207 if (options
->approximation_method
== BV_APPROX_NONE
)
208 options
->approximation_method
= BV_APPROX_DROP
;
212 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
)
213 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
214 if (!strcmp(arg
, "scale"))
215 options
->approximation_method
= BV_APPROX_SCALE
;
216 else if (!strcmp(arg
, "drop"))
217 options
->approximation_method
= BV_APPROX_DROP
;
218 else if (!strcmp(arg
, "volume"))
219 options
->approximation_method
= BV_APPROX_VOLUME
;
220 else if (!strcmp(arg
, "bernoulli"))
221 options
->approximation_method
= BV_APPROX_BERNOULLI
;
223 argp_error(state
, "unknown value for --approximation-method option");
226 options
->approximation_method
= BV_APPROX_SCALE
;
228 switch (getsubopt(&arg
, scale_opts
, &subopt
)) {
230 options
->scale_flags
|= BV_APPROX_SCALE_FAST
;
233 options
->scale_flags
&= ~BV_APPROX_SCALE_FAST
;
236 options
->scale_flags
|= BV_APPROX_SCALE_NARROW
;
237 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW2
;
240 options
->scale_flags
|= BV_APPROX_SCALE_NARROW2
;
241 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW
;
244 options
->scale_flags
|= BV_APPROX_SCALE_CHAMBER
;
247 argp_error(state
, "unknown suboption '%s'\n", subopt
);
251 if (!strcmp(arg
, "lift"))
252 options
->volume_triangulate
= BV_VOL_LIFT
;
253 else if (!strcmp(arg
, "vertex"))
254 options
->volume_triangulate
= BV_VOL_VERTEX
;
255 else if (!strcmp(arg
, "barycenter"))
256 options
->volume_triangulate
= BV_VOL_BARYCENTER
;
259 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
&&
260 options
->approximation_method
!= BV_APPROX_NONE
) {
262 "no polynomial approximation selected; reseting approximation method\n");
263 options
->approximation_method
= BV_APPROX_NONE
;
267 return ARGP_ERR_UNKNOWN
;
272 static error_t
barvinok_parse_opt(int key
, char *arg
, struct argp_state
*state
)
274 struct barvinok_options
*options
= state
->input
;
279 state
->child_inputs
[0] = options
;
282 printf(barvinok_version());
284 case BV_OPT_SPECIALIZATION
:
285 if (!strcmp(arg
, "bf"))
286 options
->incremental_specialization
= BV_SPECIALIZATION_BF
;
287 else if (!strcmp(arg
, "df"))
288 options
->incremental_specialization
= BV_SPECIALIZATION_DF
;
289 else if (!strcmp(arg
, "random"))
290 options
->incremental_specialization
= BV_SPECIALIZATION_RANDOM
;
291 else if (!strcmp(arg
, "todd"))
292 options
->incremental_specialization
= BV_SPECIALIZATION_TODD
;
298 options
->lookup_table
= 1;
300 case BV_OPT_CHAMBERS
:
301 if (!strcmp(arg
, "polylib"))
302 options
->chambers
= BV_CHAMBERS_POLYLIB
;
303 if (!strcmp(arg
, "topcom"))
304 options
->chambers
= BV_CHAMBERS_TOPCOM
;
307 if (!strcmp(arg
, "cdd"))
308 options
->gbr_lp_solver
= BV_GBR_CDD
;
309 if (!strcmp(arg
, "glpk"))
310 options
->gbr_lp_solver
= BV_GBR_GLPK
;
311 if (!strcmp(arg
, "pip"))
312 options
->gbr_lp_solver
= BV_GBR_PIP
;
313 if (!strcmp(arg
, "pip-dual"))
314 options
->gbr_lp_solver
= BV_GBR_PIP_DUAL
;
317 if (!strcmp(arg
, "cdd"))
318 options
->lp_solver
= BV_LP_CDD
;
319 if (!strcmp(arg
, "cddf"))
320 options
->lp_solver
= BV_LP_CDDF
;
321 if (!strcmp(arg
, "glpk"))
322 options
->lp_solver
= BV_LP_GLPK
;
323 if (!strcmp(arg
, "polylib"))
324 options
->lp_solver
= BV_LP_POLYLIB
;
326 case BV_OPT_MAXINDEX
:
327 options
->max_index
= strtoul(arg
, NULL
, 0);
330 if (!strcmp(arg
, "barvinok"))
331 options
->summation
= BV_SUM_BARVINOK
;
332 if (!strcmp(arg
, "euler"))
333 options
->summation
= BV_SUM_EULER
;
334 if (!strcmp(arg
, "bernoulli"))
335 options
->summation
= BV_SUM_BERNOULLI
;
338 if (!strcmp(arg
, "none"))
339 options
->bernstein_recurse
= 0;
340 else if (!strcmp(arg
, "factors"))
341 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
342 else if (!strcmp(arg
, "intervals"))
343 options
->bernstein_recurse
= BV_BERNSTEIN_INTERVALS
;
344 else if (!strcmp(arg
, "full"))
345 options
->bernstein_recurse
=
346 BV_BERNSTEIN_FACTORS
| BV_BERNSTEIN_INTERVALS
;
349 return ARGP_ERR_UNKNOWN
;
354 static struct argp approx_argp
= {
355 approx_argp_options
, approx_parse_opt
, 0, 0
358 static struct argp_child barvinok_children
[] = {
359 { &approx_argp
, 0, "polynomial approximation", BV_GRP_APPROX
},
363 struct argp barvinok_argp
= {
364 barvinok_argp_options
, barvinok_parse_opt
, 0, 0, barvinok_children