update isl-polylib for fix in header file
[barvinok.git] / options.c
blob796ba9c434a215d118b53f4dc9425a3148cf8f10
1 #include <assert.h>
2 #include <unistd.h>
3 #include <barvinok/options.h>
4 #include <barvinok/util.h>
5 #include "config.h"
7 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
9 void barvinok_stats_clear(struct barvinok_stats *stats)
11 memset(stats, 0, sizeof(*stats));
14 void barvinok_stats_print(struct barvinok_stats *stats, FILE *out)
16 fprintf(out, "Base cones: %ld\n", stats->base_cones);
17 if (stats->volume_simplices)
18 fprintf(out, "Volume simplices: %ld\n", stats->volume_simplices);
19 if (stats->topcom_chambers) {
20 fprintf(out, "TOPCOM empty chambers: %ld\n",
21 stats->topcom_empty_chambers);
22 fprintf(out, "TOPCOM chambers: %ld\n", stats->topcom_chambers);
23 fprintf(out, "TOPCOM distinct chambers: %ld\n",
24 stats->topcom_distinct_chambers);
26 if (stats->gbr_solved_lps)
27 fprintf(out, "LPs solved during GBR: %ld\n", stats->gbr_solved_lps);
28 if (stats->bernoulli_sums)
29 fprintf(out, "Bernoulli sums: %ld\n", stats->bernoulli_sums);
32 static struct isl_arg_choice approx[] = {
33 {"lower", BV_APPROX_SIGN_LOWER},
34 {"upper", BV_APPROX_SIGN_UPPER},
35 {0}
38 static struct isl_arg_choice approx_method[] = {
39 {"drop", BV_APPROX_DROP},
40 {"scale", BV_APPROX_SCALE},
41 {"volume", BV_APPROX_VOLUME},
42 {"bernoulli", BV_APPROX_BERNOULLI},
43 {0}
46 static struct isl_arg_flags scale_flags[] = {
47 {"fast", BV_APPROX_SCALE_FAST, BV_APPROX_SCALE_FAST},
48 {"slow", BV_APPROX_SCALE_FAST, 0},
49 {"narrow", BV_APPROX_SCALE_NARROW | BV_APPROX_SCALE_NARROW2,
50 BV_APPROX_SCALE_NARROW},
51 {"narrow2", BV_APPROX_SCALE_NARROW | BV_APPROX_SCALE_NARROW2,
52 BV_APPROX_SCALE_NARROW2},
53 {"chamber", BV_APPROX_SCALE_CHAMBER, BV_APPROX_SCALE_CHAMBER},
54 {0}
57 static struct isl_arg_choice triangulation[] = {
58 {"lift", BV_VOL_LIFT},
59 {"vertex", BV_VOL_VERTEX},
60 {"barycenter", BV_VOL_BARYCENTER},
61 {0}
64 static int set_approx(void *opt, unsigned val)
66 struct barvinok_approximation_options *options;
67 options = (struct barvinok_approximation_options *)opt;
68 options->approximation = val;
69 if (options->method == BV_APPROX_NONE)
70 options->method = BV_APPROX_SCALE;
71 return 0;
74 static int set_method(void *opt, unsigned val)
76 struct barvinok_approximation_options *options;
77 options = (struct barvinok_approximation_options *)opt;
78 options->method = val;
79 if (options->approximation == BV_APPROX_SIGN_NONE)
80 options->approximation = BV_APPROX_SIGN_APPROX;
81 return 0;
84 static struct isl_arg approx_options_arg[] = {
85 ISL_ARG_USER_OPT_CHOICE(struct barvinok_approximation_options, approximation, 0,
86 "polynomial-approximation", approx, &set_approx,
87 BV_APPROX_SIGN_NONE, BV_APPROX_SIGN_APPROX, NULL)
88 ISL_ARG_USER_OPT_CHOICE(struct barvinok_approximation_options, method, 0,
89 "approximation-method", approx_method, &set_method,
90 BV_APPROX_NONE, BV_APPROX_DROP,
91 "method to use in polynomial approximation")
92 ISL_ARG_FLAGS(struct barvinok_approximation_options, scale_flags, 0,
93 "scale-options", scale_flags, 0, NULL)
94 ISL_ARG_CHOICE(struct barvinok_approximation_options, volume_triangulate, 0,
95 "volume-triangulation", triangulation, BV_VOL_VERTEX,
96 "type of triangulation to perform in volume computation")
97 ISL_ARG_END
100 static int stats_init(void *user)
102 struct barvinok_stats **stats = (struct barvinok_stats **)user;
103 *stats = isl_alloc_type(NULL, struct barvinok_stats);
104 if (*stats)
105 barvinok_stats_clear(*stats);
106 return *stats ? 0 : -1;
108 static void stats_clear(void *user)
110 struct barvinok_stats **stats = (struct barvinok_stats **)user;
111 free(*stats);
113 static int maxrays_init(void *user)
115 unsigned *MaxRays = (unsigned *)user;
116 *MaxRays = MAXRAYS;
117 return 0;
119 static int int_init_one(void *user)
121 *((int *)user) = 1;
122 return 0;
124 static int int_init_zero(void *user)
126 *((int *)user) = 0;
127 return 0;
129 static void print_version(void)
131 printf("%s", barvinok_version());
134 #ifdef USE_INCREMENTAL_BF
135 #define DEFAULT_SPECIALIZATION BV_SPECIALIZATION_BF
136 #elif defined USE_INCREMENTAL_DF
137 #define DEFAULT_SPECIALIZATION BV_SPECIALIZATION_DF
138 #else
139 #define DEFAULT_SPECIALIZATION BV_SPECIALIZATION_RANDOM
140 #endif
142 static struct isl_arg_choice specialization[] = {
143 {"bf", BV_SPECIALIZATION_BF},
144 {"df", BV_SPECIALIZATION_DF},
145 {"random", BV_SPECIALIZATION_RANDOM},
146 {"todd", BV_SPECIALIZATION_TODD},
150 static struct isl_arg_choice gbr[] = {
151 #ifdef HAVE_LIBGLPK
152 {"glpk", BV_GBR_GLPK},
153 #endif
154 #ifdef HAVE_LIBCDDGMP
155 {"cdd", BV_GBR_CDD},
156 #endif
157 #ifdef HAVE_PIPLIB
158 {"pip", BV_GBR_PIP},
159 {"pip-dual", BV_GBR_PIP_DUAL},
160 #endif
161 {"isl", BV_GBR_ISL},
165 #ifdef HAVE_LIBGLPK
166 #define DEFAULT_LP BV_LP_GLPK
167 #elif defined HAVE_LIBCDDGMP
168 #define DEFAULT_LP BV_LP_CDD
169 #elif defined HAVE_PIPLIB
170 #define DEFAULT_LP BV_LP_PIP
171 #else
172 #define DEFAULT_LP BV_LP_POLYLIB
173 #endif
175 static struct isl_arg_choice lp[] = {
176 #ifdef HAVE_LIBGLPK
177 {"glpk", BV_LP_GLPK},
178 #endif
179 #ifdef HAVE_LIBCDDGMP
180 {"cdd", BV_LP_CDD},
181 {"cddf", BV_LP_CDDF},
182 #endif
183 #ifdef HAVE_PIPLIB
184 {"pip", BV_LP_PIP},
185 #endif
186 {"polylib", BV_LP_POLYLIB},
190 static struct isl_arg_choice summation[] = {
191 {"box", BV_SUM_BOX},
192 {"euler", BV_SUM_EULER},
193 {"bernoulli", BV_SUM_BERNOULLI},
194 {"laurent", BV_SUM_LAURENT},
195 {"laurent_old", BV_SUM_LAURENT_OLD},
199 static struct isl_arg_choice chambers[] = {
200 {"polylib", BV_CHAMBERS_POLYLIB},
201 #ifdef POINTS2TRIANGS_PATH
202 {"topcom", BV_CHAMBERS_TOPCOM},
203 #endif
204 {"isl", BV_CHAMBERS_ISL},
208 static struct isl_arg_choice hull[] = {
209 {"gbr", BV_HULL_GBR},
210 #ifdef USE_ZSOLVE
211 {"hilbert", BV_HULL_HILBERT},
212 #endif
216 struct isl_arg barvinok_options_arg[] = {
217 ISL_ARG_CHILD(struct barvinok_options, isl, "isl", isl_options_arg, "isl options")
218 ISL_ARG_CHILD(struct barvinok_options, approx, NULL,
219 approx_options_arg, "polynomial approximation")
220 ISL_ARG_USER(struct barvinok_options, stats, &stats_init, &stats_clear)
221 ISL_ARG_USER(struct barvinok_options, MaxRays, &maxrays_init, NULL)
222 ISL_ARG_LONG(struct barvinok_options, LLL_a, 0, "lll-reduction-num", 1,
223 "LLL reduction parameter numerator")
224 ISL_ARG_LONG(struct barvinok_options, LLL_b, 0, "lll-reduction-den", 1,
225 "LLL reduction parameter denominator")
226 ISL_ARG_CHOICE(struct barvinok_options, incremental_specialization,
227 0, "specialization", specialization, DEFAULT_SPECIALIZATION, NULL)
228 ISL_ARG_ULONG(struct barvinok_options, max_index, 0, "index", 1,
229 "maximal index of simple cones in decomposition")
230 ISL_ARG_BOOL(struct barvinok_options, primal, 0, "primal", 0, NULL)
231 ISL_ARG_BOOL(struct barvinok_options, lookup_table, 0, "table", 0, NULL)
232 ISL_ARG_USER(struct barvinok_options, count_sample_infinite, &int_init_one, NULL)
233 ISL_ARG_USER(struct barvinok_options, try_Delaunay_triangulation, &int_init_zero, NULL)
234 ISL_ARG_CHOICE(struct barvinok_options, gbr_lp_solver, 0, "gbr", gbr,
235 BV_GBR_ISL, "lp solver to use for basis reduction")
236 ISL_ARG_CHOICE(struct barvinok_options, lp_solver, 0, "lp", lp,
237 DEFAULT_LP, "lp solver to use")
238 ISL_ARG_CHOICE(struct barvinok_options, summation, 0, "summation", summation,
239 BV_SUM_LAURENT, NULL)
240 ISL_ARG_CHOICE(struct barvinok_options, chambers, 0, "chamber-decomposition",
241 chambers, BV_CHAMBERS_POLYLIB, "tool to use for chamber decomposition")
242 ISL_ARG_CHOICE(struct barvinok_options, integer_hull, 0, "integer-hull",
243 hull, BV_HULL_GBR, NULL)
244 ISL_ARG_USER(struct barvinok_options, gbr_only_first, &int_init_zero, NULL)
245 ISL_ARG_BOOL(struct barvinok_options, print_stats, 0, "print-stats", 0, NULL)
246 ISL_ARG_BOOL(struct barvinok_options, verbose, 0, "verbose", 0, NULL)
247 ISL_ARG_VERSION(print_version)
248 ISL_ARG_END
251 ISL_ARG_DEF(barvinok_options, struct barvinok_options, barvinok_options_arg)
252 ISL_ARG_CTX_DEF(barvinok_options, struct barvinok_options, barvinok_options_arg)