3 #include <barvinok/options.h>
4 #include <barvinok/util.h>
8 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
11 Vector
*Polyhedron_Sample(Polyhedron
*P
, struct barvinok_options
*options
)
17 #define ALLOC(type) (type*)malloc(sizeof(type))
19 void barvinok_stats_clear(struct barvinok_stats
*stats
)
21 memset(stats
, 0, sizeof(*stats
));
24 void barvinok_stats_print(struct barvinok_stats
*stats
, FILE *out
)
26 fprintf(out
, "Base cones: %d\n", stats
->base_cones
);
27 if (stats
->volume_simplices
)
28 fprintf(out
, "Volume simplices: %d\n", stats
->volume_simplices
);
29 if (stats
->topcom_chambers
) {
30 fprintf(out
, "TOPCOM empty chambers: %d\n",
31 stats
->topcom_empty_chambers
);
32 fprintf(out
, "TOPCOM chambers: %d\n", stats
->topcom_chambers
);
33 fprintf(out
, "TOPCOM distinct chambers: %d\n",
34 stats
->topcom_distinct_chambers
);
38 struct barvinok_options
*barvinok_options_new_with_defaults()
40 struct barvinok_options
*options
= ALLOC(struct barvinok_options
);
44 options
->stats
= ALLOC(struct barvinok_stats
);
45 if (!options
->stats
) {
50 barvinok_stats_clear(options
->stats
);
55 options
->MaxRays
= MAXRAYS
;
57 #ifdef USE_INCREMENTAL_BF
58 options
->incremental_specialization
= 2;
59 #elif defined USE_INCREMENTAL_DF
60 options
->incremental_specialization
= 1;
62 options
->incremental_specialization
= 0;
64 options
->max_index
= 1;
67 options
->lookup_table
= 0;
69 options
->lookup_table
= 1;
72 options
->count_sample_infinite
= 1;
74 options
->count_sample_infinite
= 0;
76 options
->try_Delaunay_triangulation
= 0;
78 options
->chambers
= BV_CHAMBERS_POLYLIB
;
80 options
->polynomial_approximation
= BV_APPROX_SIGN_NONE
;
81 options
->approximation_method
= BV_APPROX_NONE
;
82 options
->scale_flags
= 0;
83 options
->volume_triangulate
= BV_VOL_VERTEX
;
86 options
->gbr_lp_solver
= BV_GBR_GLPK
;
87 #elif defined HAVE_LIBCDDGMP
88 options
->gbr_lp_solver
= BV_GBR_CDD
;
90 options
->gbr_lp_solver
= BV_GBR_PIP
;
94 options
->lp_solver
= BV_LP_GLPK
;
95 #elif defined HAVE_LIBCDDGMP
96 options
->lp_solver
= BV_LP_CDD
;
98 options
->lp_solver
= BV_LP_POLYLIB
;
101 options
->summation
= BV_SUM_BARVINOK
;
103 options
->bernstein_optimize
= BV_BERNSTEIN_NONE
;
105 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
110 void barvinok_options_free(struct barvinok_options
*options
)
112 free(options
->stats
);
124 const char *scale_opts
[] = {
133 static struct argp_option approx_argp_options
[] = {
134 { "polynomial-approximation", BV_OPT_POLAPPROX
, "lower|upper", 1 },
135 { "approximation-method", BV_OPT_APPROX
, "scale|drop|volume|bernoulli", 0,
136 "method to use in polynomial approximation [default: drop]" },
137 { "scale-options", BV_OPT_SCALE
,
138 "fast|slow,narrow|narrow2,chamber", 0 },
139 { "volume-triangulation", BV_OPT_VOL
, "lift|vertex|barycenter", 0,
140 "type of triangulation to perform in volume computation [default: vertex]" },
144 static struct argp_option barvinok_argp_options
[] = {
145 { "index", BV_OPT_MAXINDEX
, "int", 0,
146 "maximal index of simple cones in decomposition" },
147 { "primal", BV_OPT_PRIMAL
, 0, 0 },
148 { "table", BV_OPT_TABLE
, 0, 0 },
149 { "specialization", BV_OPT_SPECIALIZATION
, "[bf|df|random|todd]" },
150 #ifdef POINTS2TRIANGS_PATH
151 { "chamber-decomposition", BV_OPT_CHAMBERS
, "polylib|topcom", 0,
152 "tool to use for chamber decomposition [default: polylib]" },
155 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
156 "cdd|glpk|pip|pip-dual",
157 #elif defined(HAVE_LIBGLPK)
159 #elif defined(HAVE_LIBCDDGMP)
164 0, "lp solver to use for basis reduction "
167 #elif defined HAVE_LIBCDDGMP
174 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
175 "cdd|cddf|glpk|polylib",
176 #elif defined(HAVE_LIBGLPK)
178 #elif defined(HAVE_LIBCDDGMP)
183 0, "lp solver to use "
184 #if defined(HAVE_LIBGLPK)
186 #elif defined(HAVE_LIBCDDGMP)
189 "[default: polylib]",
192 { "summation", BV_OPT_SUM
, "barvinok|euler", 0,
193 "[default: barvinok]" },
194 { "bernstein-recurse", BV_OPT_RECURSE
, "none|factors|intervals|full", 0,
195 "[default: factors]" },
196 { "recurse", BV_OPT_RECURSE
, "",
197 OPTION_ALIAS
| OPTION_HIDDEN
},
198 { "version", 'V', 0, 0 },
202 static error_t
approx_parse_opt(int key
, char *arg
, struct argp_state
*state
)
204 struct barvinok_options
*options
= state
->input
;
208 case BV_OPT_POLAPPROX
:
210 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
211 if (options
->approximation_method
== BV_APPROX_NONE
)
212 options
->approximation_method
= BV_APPROX_SCALE
;
214 if (!strcmp(arg
, "lower"))
215 options
->polynomial_approximation
= BV_APPROX_SIGN_LOWER
;
216 else if (!strcmp(arg
, "upper"))
217 options
->polynomial_approximation
= BV_APPROX_SIGN_UPPER
;
218 if (options
->approximation_method
== BV_APPROX_NONE
)
219 options
->approximation_method
= BV_APPROX_DROP
;
223 if (!strcmp(arg
, "scale"))
224 options
->approximation_method
= BV_APPROX_SCALE
;
225 else if (!strcmp(arg
, "drop"))
226 options
->approximation_method
= BV_APPROX_DROP
;
227 else if (!strcmp(arg
, "volume"))
228 options
->approximation_method
= BV_APPROX_VOLUME
;
229 else if (!strcmp(arg
, "bernoulli"))
230 options
->approximation_method
= BV_APPROX_BERNOULLI
;
232 argp_error(state
, "unknown value for --approximation-method option");
235 options
->approximation_method
= BV_APPROX_SCALE
;
237 switch (getsubopt(&arg
, scale_opts
, &subopt
)) {
239 options
->scale_flags
|= BV_APPROX_SCALE_FAST
;
242 options
->scale_flags
&= ~BV_APPROX_SCALE_FAST
;
245 options
->scale_flags
|= BV_APPROX_SCALE_NARROW
;
246 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW2
;
249 options
->scale_flags
|= BV_APPROX_SCALE_NARROW2
;
250 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW
;
253 options
->scale_flags
|= BV_APPROX_SCALE_CHAMBER
;
256 argp_error(state
, "unknown suboption '%s'\n", subopt
);
260 if (!strcmp(arg
, "lift"))
261 options
->volume_triangulate
= BV_VOL_LIFT
;
262 else if (!strcmp(arg
, "vertex"))
263 options
->volume_triangulate
= BV_VOL_VERTEX
;
264 else if (!strcmp(arg
, "barycenter"))
265 options
->volume_triangulate
= BV_VOL_BARYCENTER
;
268 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
&&
269 options
->approximation_method
!= BV_APPROX_NONE
) {
271 "no polynomial approximation selected; reseting approximation method\n");
272 options
->approximation_method
= BV_APPROX_NONE
;
276 return ARGP_ERR_UNKNOWN
;
281 static error_t
barvinok_parse_opt(int key
, char *arg
, struct argp_state
*state
)
283 struct barvinok_options
*options
= state
->input
;
288 state
->child_inputs
[0] = options
;
291 printf(barvinok_version());
293 case BV_OPT_SPECIALIZATION
:
294 if (!strcmp(arg
, "bf"))
295 options
->incremental_specialization
= BV_SPECIALIZATION_BF
;
296 else if (!strcmp(arg
, "df"))
297 options
->incremental_specialization
= BV_SPECIALIZATION_DF
;
298 else if (!strcmp(arg
, "random"))
299 options
->incremental_specialization
= BV_SPECIALIZATION_RANDOM
;
300 else if (!strcmp(arg
, "todd"))
301 options
->incremental_specialization
= BV_SPECIALIZATION_TODD
;
307 options
->lookup_table
= 1;
309 case BV_OPT_CHAMBERS
:
310 if (!strcmp(arg
, "polylib"))
311 options
->chambers
= BV_CHAMBERS_POLYLIB
;
312 if (!strcmp(arg
, "topcom"))
313 options
->chambers
= BV_CHAMBERS_TOPCOM
;
316 if (!strcmp(arg
, "cdd"))
317 options
->gbr_lp_solver
= BV_GBR_CDD
;
318 if (!strcmp(arg
, "glpk"))
319 options
->gbr_lp_solver
= BV_GBR_GLPK
;
320 if (!strcmp(arg
, "pip"))
321 options
->gbr_lp_solver
= BV_GBR_PIP
;
322 if (!strcmp(arg
, "pip-dual"))
323 options
->gbr_lp_solver
= BV_GBR_PIP_DUAL
;
326 if (!strcmp(arg
, "cdd"))
327 options
->lp_solver
= BV_LP_CDD
;
328 if (!strcmp(arg
, "cddf"))
329 options
->lp_solver
= BV_LP_CDDF
;
330 if (!strcmp(arg
, "glpk"))
331 options
->lp_solver
= BV_LP_GLPK
;
332 if (!strcmp(arg
, "polylib"))
333 options
->lp_solver
= BV_LP_POLYLIB
;
335 case BV_OPT_MAXINDEX
:
336 options
->max_index
= strtoul(arg
, NULL
, 0);
339 if (!strcmp(arg
, "barvinok"))
340 options
->summation
= BV_SUM_BARVINOK
;
341 if (!strcmp(arg
, "euler"))
342 options
->summation
= BV_SUM_EULER
;
345 if (!strcmp(arg
, "none"))
346 options
->bernstein_recurse
= 0;
347 else if (!strcmp(arg
, "factors"))
348 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
349 else if (!strcmp(arg
, "intervals"))
350 options
->bernstein_recurse
= BV_BERNSTEIN_INTERVALS
;
351 else if (!strcmp(arg
, "full"))
352 options
->bernstein_recurse
=
353 BV_BERNSTEIN_FACTORS
| BV_BERNSTEIN_INTERVALS
;
356 return ARGP_ERR_UNKNOWN
;
361 static struct argp approx_argp
= {
362 approx_argp_options
, approx_parse_opt
, 0, 0
365 static struct argp_child barvinok_children
[] = {
366 { &approx_argp
, 0, "polynomial approximation", BV_GRP_APPROX
},
370 struct argp barvinok_argp
= {
371 barvinok_argp_options
, barvinok_parse_opt
, 0, 0, barvinok_children