use test scripts for performing tests
[barvinok.git] / options.c
blobdce38138c84dd3949fdea39ad8f906ab9dfeeaa0
1 #include <string.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 ALLOC(type) (type*)malloc(sizeof(type))
9 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
11 void barvinok_stats_clear(struct barvinok_stats *stats)
13 memset(stats, 0, sizeof(*stats));
16 void barvinok_stats_print(struct barvinok_stats *stats, FILE *out)
18 fprintf(out, "Base cones: %ld\n", stats->base_cones);
19 if (stats->volume_simplices)
20 fprintf(out, "Volume simplices: %ld\n", stats->volume_simplices);
21 if (stats->topcom_chambers) {
22 fprintf(out, "TOPCOM empty chambers: %ld\n",
23 stats->topcom_empty_chambers);
24 fprintf(out, "TOPCOM chambers: %ld\n", stats->topcom_chambers);
25 fprintf(out, "TOPCOM distinct chambers: %ld\n",
26 stats->topcom_distinct_chambers);
28 if (stats->gbr_solved_lps)
29 fprintf(out, "LPs solved during GBR: %ld\n", stats->gbr_solved_lps);
30 if (stats->bernoulli_sums)
31 fprintf(out, "Bernoulli sums: %ld\n", stats->bernoulli_sums);
34 static struct isl_arg_choice approx[] = {
35 {"lower", BV_APPROX_SIGN_LOWER},
36 {"upper", BV_APPROX_SIGN_UPPER},
37 {0}
40 static struct isl_arg_choice approx_method[] = {
41 {"drop", BV_APPROX_DROP},
42 {"scale", BV_APPROX_SCALE},
43 {"volume", BV_APPROX_VOLUME},
44 {"bernoulli", BV_APPROX_BERNOULLI},
45 {0}
48 static struct isl_arg_flags scale_flags[] = {
49 {"fast", BV_APPROX_SCALE_FAST, BV_APPROX_SCALE_FAST},
50 {"slow", BV_APPROX_SCALE_FAST, 0},
51 {"narrow", BV_APPROX_SCALE_NARROW | BV_APPROX_SCALE_NARROW2,
52 BV_APPROX_SCALE_NARROW},
53 {"narrow2", BV_APPROX_SCALE_NARROW | BV_APPROX_SCALE_NARROW2,
54 BV_APPROX_SCALE_NARROW2},
55 {"chamber", BV_APPROX_SCALE_CHAMBER, BV_APPROX_SCALE_CHAMBER},
56 {0}
59 static struct isl_arg_choice triangulation[] = {
60 {"lift", BV_VOL_LIFT},
61 {"vertex", BV_VOL_VERTEX},
62 {"barycenter", BV_VOL_BARYCENTER},
63 {0}
66 static int set_approx(void *opt, unsigned val)
68 struct barvinok_approximation_options *options;
69 options = (struct barvinok_approximation_options *)opt;
70 options->approximation = val;
71 if (options->method == BV_APPROX_NONE)
72 options->method = BV_APPROX_SCALE;
73 return 0;
76 static int set_method(void *opt, unsigned val)
78 struct barvinok_approximation_options *options;
79 options = (struct barvinok_approximation_options *)opt;
80 options->method = val;
81 if (options->approximation == BV_APPROX_SIGN_NONE)
82 options->approximation = BV_APPROX_SIGN_APPROX;
83 return 0;
86 ISL_ARGS_START(struct barvinok_approximation_options, approx_options_args)
87 ISL_ARG_USER_OPT_CHOICE(struct barvinok_approximation_options, approximation, 0,
88 "polynomial-approximation", approx, &set_approx,
89 BV_APPROX_SIGN_NONE, BV_APPROX_SIGN_APPROX, NULL)
90 ISL_ARG_USER_OPT_CHOICE(struct barvinok_approximation_options, method, 0,
91 "approximation-method", approx_method, &set_method,
92 BV_APPROX_NONE, BV_APPROX_DROP,
93 "method to use in polynomial approximation")
94 ISL_ARG_FLAGS(struct barvinok_approximation_options, scale_flags, 0,
95 "scale-options", scale_flags, 0, NULL)
96 ISL_ARG_CHOICE(struct barvinok_approximation_options, volume_triangulate, 0,
97 "volume-triangulation", triangulation, BV_VOL_VERTEX,
98 "type of triangulation to perform in volume computation")
99 ISL_ARGS_END
101 static int stats_init(void *user)
103 struct barvinok_stats **stats = (struct barvinok_stats **)user;
104 *stats = ALLOC(struct barvinok_stats);
105 if (*stats)
106 barvinok_stats_clear(*stats);
107 return *stats ? 0 : -1;
109 static void stats_clear(void *user)
111 struct barvinok_stats **stats = (struct barvinok_stats **)user;
112 free(*stats);
114 static int maxrays_init(void *user)
116 unsigned *MaxRays = (unsigned *)user;
117 *MaxRays = MAXRAYS;
118 return 0;
120 static int int_init_one(void *user)
122 *((int *)user) = 1;
123 return 0;
125 static int int_init_zero(void *user)
127 *((int *)user) = 0;
128 return 0;
130 static void print_version(void)
132 printf("%s", barvinok_version());
135 static struct isl_arg_choice specialization[] = {
136 {"bf", BV_SPECIALIZATION_BF},
137 {"df", BV_SPECIALIZATION_DF},
138 {"random", BV_SPECIALIZATION_RANDOM},
139 {"todd", BV_SPECIALIZATION_TODD},
143 static struct isl_arg_choice gbr[] = {
144 #ifdef HAVE_LIBGLPK
145 {"glpk", BV_GBR_GLPK},
146 #endif
147 #ifdef HAVE_LIBCDDGMP
148 {"cdd", BV_GBR_CDD},
149 #endif
150 {"isl", BV_GBR_ISL},
154 static struct isl_arg_choice lp[] = {
155 #ifdef HAVE_LIBGLPK
156 {"glpk", BV_LP_GLPK},
157 #endif
158 #ifdef HAVE_LIBCDDGMP
159 {"cdd", BV_LP_CDD},
160 {"cddf", BV_LP_CDDF},
161 #endif
162 {"polylib", BV_LP_POLYLIB},
163 {"isl", BV_LP_ISL},
167 static struct isl_arg_choice summation[] = {
168 {"box", BV_SUM_BOX},
169 {"euler", BV_SUM_EULER},
170 {"bernoulli", BV_SUM_BERNOULLI},
171 {"laurent", BV_SUM_LAURENT},
172 {"laurent_old", BV_SUM_LAURENT_OLD},
176 static struct isl_arg_choice chambers[] = {
177 {"polylib", BV_CHAMBERS_POLYLIB},
178 #ifdef POINTS2TRIANGS_PATH
179 {"topcom", BV_CHAMBERS_TOPCOM},
180 #endif
181 {"isl", BV_CHAMBERS_ISL},
185 static struct isl_arg_choice hull[] = {
186 {"gbr", BV_HULL_GBR},
187 #ifdef USE_ZSOLVE
188 {"hilbert", BV_HULL_HILBERT},
189 #endif
193 ISL_ARGS_START(struct barvinok_options, barvinok_options_args)
194 ISL_ARG_CHILD(struct barvinok_options, isl, "isl", &isl_options_args,
195 "isl options")
196 ISL_ARG_CHILD(struct barvinok_options, approx, NULL,
197 &approx_options_args, "polynomial approximation")
198 ISL_ARG_USER(struct barvinok_options, stats, &stats_init, &stats_clear)
199 ISL_ARG_USER(struct barvinok_options, MaxRays, &maxrays_init, NULL)
200 ISL_ARG_LONG(struct barvinok_options, LLL_a, 0, "lll-reduction-num", 1,
201 "LLL reduction parameter numerator")
202 ISL_ARG_LONG(struct barvinok_options, LLL_b, 0, "lll-reduction-den", 1,
203 "LLL reduction parameter denominator")
204 ISL_ARG_CHOICE(struct barvinok_options, incremental_specialization,
205 0, "specialization", specialization, BV_SPECIALIZATION_RANDOM, NULL)
206 ISL_ARG_ULONG(struct barvinok_options, max_index, 0, "index", 1,
207 "maximal index of simple cones in decomposition")
208 ISL_ARG_BOOL(struct barvinok_options, primal, 0, "primal", 0, NULL)
209 ISL_ARG_BOOL(struct barvinok_options, lookup_table, 0, "table", 0, NULL)
210 ISL_ARG_USER(struct barvinok_options, count_sample_infinite, &int_init_one, NULL)
211 ISL_ARG_USER(struct barvinok_options, try_Delaunay_triangulation, &int_init_zero, NULL)
212 ISL_ARG_CHOICE(struct barvinok_options, gbr_lp_solver, 0, "gbr", gbr,
213 BV_GBR_ISL, "lp solver to use for basis reduction")
214 ISL_ARG_CHOICE(struct barvinok_options, lp_solver, 0, "lp", lp,
215 BV_LP_ISL, "lp solver to use")
216 ISL_ARG_CHOICE(struct barvinok_options, summation, 0, "summation", summation,
217 BV_SUM_LAURENT, NULL)
218 ISL_ARG_CHOICE(struct barvinok_options, chambers, 0, "chamber-decomposition",
219 chambers, BV_CHAMBERS_POLYLIB, "tool to use for chamber decomposition")
220 ISL_ARG_CHOICE(struct barvinok_options, integer_hull, 0, "integer-hull",
221 hull, BV_HULL_GBR, NULL)
222 ISL_ARG_USER(struct barvinok_options, gbr_only_first, &int_init_zero, NULL)
223 ISL_ARG_BOOL(struct barvinok_options, print_stats, 0, "print-stats", 0, NULL)
224 ISL_ARG_BOOL(struct barvinok_options, verbose, 0, "verbose", 0, NULL)
225 ISL_ARG_VERSION(print_version)
226 ISL_ARGS_END
228 ISL_ARG_DEF(barvinok_options, struct barvinok_options, barvinok_options_args)
229 ISL_ARG_CTX_DEF(barvinok_options, struct barvinok_options,
230 barvinok_options_args)