update isl for isl_pw_qpolynomial_split_periods
[barvinok.git] / options.c
blobc5b7e0a8763b5c9bfff06ce0d96e609ddb72da28
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 #ifdef HAVE_LIBGLPK
151 #define DEFAULT_GBR BV_GBR_GLPK
152 #elif defined HAVE_LIBCDDGMP
153 #define DEFAULT_GBR BV_GBR_CDD
154 #else
155 #define DEFAULT_GBR BV_GBR_PIP
156 #endif
158 static struct isl_arg_choice gbr[] = {
159 #ifdef HAVE_LIBGLPK
160 {"glpk", BV_GBR_GLPK},
161 #endif
162 #ifdef HAVE_LIBCDDGMP
163 {"cdd", BV_GBR_CDD},
164 #endif
165 {"pip", BV_GBR_PIP},
166 {"pip-dual", BV_GBR_PIP_DUAL},
170 #ifdef HAVE_LIBGLPK
171 #define DEFAULT_LP BV_LP_GLPK
172 #elif defined HAVE_LIBCDDGMP
173 #define DEFAULT_LP BV_LP_CDD
174 #else
175 #define DEFAULT_LP BV_LP_PIP
176 #endif
178 static struct isl_arg_choice lp[] = {
179 #ifdef HAVE_LIBGLPK
180 {"glpk", BV_LP_GLPK},
181 #endif
182 #ifdef HAVE_LIBCDDGMP
183 {"cdd", BV_LP_CDD},
184 {"cddf", BV_LP_CDDF},
185 #endif
186 {"pip", BV_LP_PIP},
187 {"polylib", BV_LP_POLYLIB},
191 static struct isl_arg_choice summation[] = {
192 {"box", BV_SUM_BOX},
193 {"euler", BV_SUM_EULER},
194 {"bernoulli", BV_SUM_BERNOULLI},
195 {"laurent", BV_SUM_LAURENT},
196 {"laurent_old", BV_SUM_LAURENT_OLD},
200 static struct isl_arg_choice chambers[] = {
201 {"polylib", BV_CHAMBERS_POLYLIB},
202 #ifdef POINTS2TRIANGS_PATH
203 {"topcom", BV_CHAMBERS_TOPCOM},
204 #endif
205 {"isl", BV_CHAMBERS_ISL},
209 static struct isl_arg_choice hull[] = {
210 {"gbr", BV_HULL_GBR},
211 #ifdef USE_ZSOLVE
212 {"hilbert", BV_HULL_HILBERT},
213 #endif
217 struct isl_arg barvinok_options_arg[] = {
218 ISL_ARG_CHILD(struct barvinok_options, isl, "isl", isl_options_arg, "isl options")
219 ISL_ARG_CHILD(struct barvinok_options, approx, NULL,
220 approx_options_arg, "polynomial approximation")
221 ISL_ARG_USER(struct barvinok_options, stats, &stats_init, &stats_clear)
222 ISL_ARG_USER(struct barvinok_options, MaxRays, &maxrays_init, NULL)
223 ISL_ARG_LONG(struct barvinok_options, LLL_a, 0, "lll-reduction-num", 1,
224 "LLL reduction parameter numerator")
225 ISL_ARG_LONG(struct barvinok_options, LLL_b, 0, "lll-reduction-den", 1,
226 "LLL reduction parameter denominator")
227 ISL_ARG_CHOICE(struct barvinok_options, incremental_specialization,
228 0, "specialization", specialization, DEFAULT_SPECIALIZATION, NULL)
229 ISL_ARG_ULONG(struct barvinok_options, max_index, 0, "index", 1,
230 "maximal index of simple cones in decomposition")
231 ISL_ARG_BOOL(struct barvinok_options, primal, 0, "primal", 0, NULL)
232 ISL_ARG_BOOL(struct barvinok_options, lookup_table, 0, "table", 0, NULL)
233 ISL_ARG_USER(struct barvinok_options, count_sample_infinite, &int_init_one, NULL)
234 ISL_ARG_USER(struct barvinok_options, try_Delaunay_triangulation, &int_init_zero, NULL)
235 ISL_ARG_CHOICE(struct barvinok_options, gbr_lp_solver, 0, "gbr", gbr,
236 DEFAULT_GBR, "lp solver to use for basis reduction")
237 ISL_ARG_CHOICE(struct barvinok_options, lp_solver, 0, "lp", lp,
238 DEFAULT_LP, "lp solver to use")
239 ISL_ARG_CHOICE(struct barvinok_options, summation, 0, "summation", summation,
240 BV_SUM_LAURENT, NULL)
241 ISL_ARG_CHOICE(struct barvinok_options, chambers, 0, "chamber-decomposition",
242 chambers, BV_CHAMBERS_POLYLIB, "tool to use for chamber decomposition")
243 ISL_ARG_CHOICE(struct barvinok_options, integer_hull, 0, "integer-hull",
244 hull, BV_HULL_GBR, NULL)
245 ISL_ARG_USER(struct barvinok_options, gbr_only_first, &int_init_zero, NULL)
246 ISL_ARG_BOOL(struct barvinok_options, print_stats, 0, "print-stats", 0, NULL)
247 ISL_ARG_BOOL(struct barvinok_options, verbose, 0, "verbose", 0, NULL)
248 ISL_ARG_VERSION(print_version)
249 ISL_ARG_END
252 ISL_ARG_DEF(barvinok_options, struct barvinok_options, barvinok_options_arg)
253 ISL_ARG_CTX_DEF(barvinok_options, struct barvinok_options, barvinok_options_arg)