update isl for support for recent clangs
[barvinok.git] / options.c
blob392f817348263685e48366014e25787cbbb27de5
1 #include <assert.h>
2 #include <unistd.h>
3 #include <isl/options.h>
4 #include <barvinok/options.h>
5 #include <barvinok/util.h>
6 #include "config.h"
8 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
10 void barvinok_stats_clear(struct barvinok_stats *stats)
12 memset(stats, 0, sizeof(*stats));
15 void barvinok_stats_print(struct barvinok_stats *stats, FILE *out)
17 fprintf(out, "Base cones: %ld\n", stats->base_cones);
18 if (stats->volume_simplices)
19 fprintf(out, "Volume simplices: %ld\n", stats->volume_simplices);
20 if (stats->topcom_chambers) {
21 fprintf(out, "TOPCOM empty chambers: %ld\n",
22 stats->topcom_empty_chambers);
23 fprintf(out, "TOPCOM chambers: %ld\n", stats->topcom_chambers);
24 fprintf(out, "TOPCOM distinct chambers: %ld\n",
25 stats->topcom_distinct_chambers);
27 if (stats->gbr_solved_lps)
28 fprintf(out, "LPs solved during GBR: %ld\n", stats->gbr_solved_lps);
29 if (stats->bernoulli_sums)
30 fprintf(out, "Bernoulli sums: %ld\n", stats->bernoulli_sums);
33 static struct isl_arg_choice approx[] = {
34 {"lower", BV_APPROX_SIGN_LOWER},
35 {"upper", BV_APPROX_SIGN_UPPER},
36 {0}
39 static struct isl_arg_choice approx_method[] = {
40 {"drop", BV_APPROX_DROP},
41 {"scale", BV_APPROX_SCALE},
42 {"volume", BV_APPROX_VOLUME},
43 {"bernoulli", BV_APPROX_BERNOULLI},
44 {0}
47 static struct isl_arg_flags scale_flags[] = {
48 {"fast", BV_APPROX_SCALE_FAST, BV_APPROX_SCALE_FAST},
49 {"slow", BV_APPROX_SCALE_FAST, 0},
50 {"narrow", BV_APPROX_SCALE_NARROW | BV_APPROX_SCALE_NARROW2,
51 BV_APPROX_SCALE_NARROW},
52 {"narrow2", BV_APPROX_SCALE_NARROW | BV_APPROX_SCALE_NARROW2,
53 BV_APPROX_SCALE_NARROW2},
54 {"chamber", BV_APPROX_SCALE_CHAMBER, BV_APPROX_SCALE_CHAMBER},
55 {0}
58 static struct isl_arg_choice triangulation[] = {
59 {"lift", BV_VOL_LIFT},
60 {"vertex", BV_VOL_VERTEX},
61 {"barycenter", BV_VOL_BARYCENTER},
62 {0}
65 static int set_approx(void *opt, unsigned val)
67 struct barvinok_approximation_options *options;
68 options = (struct barvinok_approximation_options *)opt;
69 options->approximation = val;
70 if (options->method == BV_APPROX_NONE)
71 options->method = BV_APPROX_SCALE;
72 return 0;
75 static int set_method(void *opt, unsigned val)
77 struct barvinok_approximation_options *options;
78 options = (struct barvinok_approximation_options *)opt;
79 options->method = val;
80 if (options->approximation == BV_APPROX_SIGN_NONE)
81 options->approximation = BV_APPROX_SIGN_APPROX;
82 return 0;
85 ISL_ARGS_START(struct barvinok_approximation_options, approx_options_args)
86 ISL_ARG_USER_OPT_CHOICE(struct barvinok_approximation_options, approximation, 0,
87 "polynomial-approximation", approx, &set_approx,
88 BV_APPROX_SIGN_NONE, BV_APPROX_SIGN_APPROX, NULL)
89 ISL_ARG_USER_OPT_CHOICE(struct barvinok_approximation_options, method, 0,
90 "approximation-method", approx_method, &set_method,
91 BV_APPROX_NONE, BV_APPROX_DROP,
92 "method to use in polynomial approximation")
93 ISL_ARG_FLAGS(struct barvinok_approximation_options, scale_flags, 0,
94 "scale-options", scale_flags, 0, NULL)
95 ISL_ARG_CHOICE(struct barvinok_approximation_options, volume_triangulate, 0,
96 "volume-triangulation", triangulation, BV_VOL_VERTEX,
97 "type of triangulation to perform in volume computation")
98 ISL_ARGS_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 {"isl", BV_GBR_ISL},
161 static struct isl_arg_choice lp[] = {
162 #ifdef HAVE_LIBGLPK
163 {"glpk", BV_LP_GLPK},
164 #endif
165 #ifdef HAVE_LIBCDDGMP
166 {"cdd", BV_LP_CDD},
167 {"cddf", BV_LP_CDDF},
168 #endif
169 {"polylib", BV_LP_POLYLIB},
170 {"isl", BV_LP_ISL},
174 static struct isl_arg_choice summation[] = {
175 {"box", BV_SUM_BOX},
176 {"euler", BV_SUM_EULER},
177 {"bernoulli", BV_SUM_BERNOULLI},
178 {"laurent", BV_SUM_LAURENT},
179 {"laurent_old", BV_SUM_LAURENT_OLD},
183 static struct isl_arg_choice chambers[] = {
184 {"polylib", BV_CHAMBERS_POLYLIB},
185 #ifdef POINTS2TRIANGS_PATH
186 {"topcom", BV_CHAMBERS_TOPCOM},
187 #endif
188 {"isl", BV_CHAMBERS_ISL},
192 static struct isl_arg_choice hull[] = {
193 {"gbr", BV_HULL_GBR},
194 #ifdef USE_ZSOLVE
195 {"hilbert", BV_HULL_HILBERT},
196 #endif
200 ISL_ARGS_START(struct barvinok_options, barvinok_options_args)
201 ISL_ARG_CHILD(struct barvinok_options, isl, "isl", &isl_options_args,
202 "isl options")
203 ISL_ARG_CHILD(struct barvinok_options, approx, NULL,
204 &approx_options_args, "polynomial approximation")
205 ISL_ARG_USER(struct barvinok_options, stats, &stats_init, &stats_clear)
206 ISL_ARG_USER(struct barvinok_options, MaxRays, &maxrays_init, NULL)
207 ISL_ARG_LONG(struct barvinok_options, LLL_a, 0, "lll-reduction-num", 1,
208 "LLL reduction parameter numerator")
209 ISL_ARG_LONG(struct barvinok_options, LLL_b, 0, "lll-reduction-den", 1,
210 "LLL reduction parameter denominator")
211 ISL_ARG_CHOICE(struct barvinok_options, incremental_specialization,
212 0, "specialization", specialization, DEFAULT_SPECIALIZATION, NULL)
213 ISL_ARG_ULONG(struct barvinok_options, max_index, 0, "index", 1,
214 "maximal index of simple cones in decomposition")
215 ISL_ARG_BOOL(struct barvinok_options, primal, 0, "primal", 0, NULL)
216 ISL_ARG_BOOL(struct barvinok_options, lookup_table, 0, "table", 0, NULL)
217 ISL_ARG_USER(struct barvinok_options, count_sample_infinite, &int_init_one, NULL)
218 ISL_ARG_USER(struct barvinok_options, try_Delaunay_triangulation, &int_init_zero, NULL)
219 ISL_ARG_CHOICE(struct barvinok_options, gbr_lp_solver, 0, "gbr", gbr,
220 BV_GBR_ISL, "lp solver to use for basis reduction")
221 ISL_ARG_CHOICE(struct barvinok_options, lp_solver, 0, "lp", lp,
222 BV_LP_ISL, "lp solver to use")
223 ISL_ARG_CHOICE(struct barvinok_options, summation, 0, "summation", summation,
224 BV_SUM_LAURENT, NULL)
225 ISL_ARG_CHOICE(struct barvinok_options, chambers, 0, "chamber-decomposition",
226 chambers, BV_CHAMBERS_POLYLIB, "tool to use for chamber decomposition")
227 ISL_ARG_CHOICE(struct barvinok_options, integer_hull, 0, "integer-hull",
228 hull, BV_HULL_GBR, NULL)
229 ISL_ARG_USER(struct barvinok_options, gbr_only_first, &int_init_zero, NULL)
230 ISL_ARG_BOOL(struct barvinok_options, print_stats, 0, "print-stats", 0, NULL)
231 ISL_ARG_BOOL(struct barvinok_options, verbose, 0, "verbose", 0, NULL)
232 ISL_ARG_VERSION(print_version)
233 ISL_ARGS_END
235 ISL_ARG_DEF(barvinok_options, struct barvinok_options, barvinok_options_args)
236 ISL_ARG_CTX_DEF(barvinok_options, struct barvinok_options,
237 barvinok_options_args)