Param_Polyhedron_Volume: perform lifting triangulation by default
[barvinok.git] / options.c
blobddf432388e375d1024b4440d726db0a82bf41950
1 #include <unistd.h>
2 #include <barvinok/options.h>
3 #include <barvinok/util.h>
4 #include "argp.h"
5 #include "config.h"
7 #ifdef HAVE_GROWING_CHERNIKOVA
8 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
9 #else
10 #define MAXRAYS 600
11 #endif
13 #ifndef HAVE_LIBGLPK
14 Vector *Polyhedron_Sample(Polyhedron *P, struct barvinok_options *options)
16 assert(0);
18 #endif
20 #define ALLOC(type) (type*)malloc(sizeof(type))
22 void barvinok_stats_clear(struct barvinok_stats *stats)
24 stats->base_cones = 0;
27 void barvinok_stats_print(struct barvinok_stats *stats, FILE *out)
29 fprintf(out, "Base cones: %d\n", stats->base_cones);
32 struct barvinok_options *barvinok_options_new_with_defaults()
34 struct barvinok_options *options = ALLOC(struct barvinok_options);
35 if (!options)
36 return NULL;
38 options->stats = ALLOC(struct barvinok_stats);
39 if (!options->stats) {
40 free(options);
41 return NULL;
44 barvinok_stats_clear(options->stats);
46 options->LLL_a = 1;
47 options->LLL_b = 1;
49 options->MaxRays = MAXRAYS;
51 #ifdef USE_INCREMENTAL_BF
52 options->incremental_specialization = 2;
53 #elif defined USE_INCREMENTAL_DF
54 options->incremental_specialization = 1;
55 #else
56 options->incremental_specialization = 0;
57 #endif
58 options->max_index = 1;
59 options->primal = 0;
60 #ifdef USE_MODULO
61 options->lookup_table = 0;
62 #else
63 options->lookup_table = 1;
64 #endif
65 #ifdef HAVE_LIBGLPK
66 options->count_sample_infinite = 1;
67 #else
68 options->count_sample_infinite = 0;
69 #endif
70 options->try_Delaunay_triangulation = 0;
72 options->polynomial_approximation = BV_APPROX_SIGN_NONE;
73 options->approximation_method = BV_APPROX_NONE;
74 options->scale_flags = 0;
75 options->volume_triangulate_lift = 1;
77 #ifdef HAVE_LIBGLPK
78 options->gbr_lp_solver = BV_GBR_GLPK;
79 #elif defined HAVE_LIBCDDGMP
80 options->gbr_lp_solver = BV_GBR_CDD;
81 #else
82 options->gbr_lp_solver = BV_GBR_NONE;
83 #endif
85 options->bernstein_optimize = BV_BERNSTEIN_NONE;
87 options->bernstein_recurse = BV_BERNSTEIN_FACTORS;
89 return options;
92 void barvinok_options_free(struct barvinok_options *options)
94 free(options->stats);
95 free(options);
98 enum {
99 SCALE_FAST,
100 SCALE_SLOW,
101 SCALE_NARROW,
102 SCALE_NARROW2
105 const char *scale_opts[] = {
106 "fast",
107 "slow",
108 "narrow",
109 "narrow2",
110 NULL
113 static struct argp_option approx_argp_options[] = {
114 { "polynomial-approximation", BV_OPT_POLAPPROX, "lower|upper", 1 },
115 { "approximation-method", BV_OPT_APPROX, "scale|drop|volume", 0,
116 "method to use in polynomial approximation [default: drop]" },
117 { "scale-options", BV_OPT_SCALE, "fast|slow,narrow|narrow2", 0 },
118 { "no-lift", BV_OPT_NO_LIFT, NULL, 0,
119 "don't perform lifting triangulation in volume computation" },
120 { 0 }
123 static struct argp_option barvinok_argp_options[] = {
124 { "index", BV_OPT_MAXINDEX, "int", 0,
125 "maximal index of simple cones in decomposition" },
126 { "primal", BV_OPT_PRIMAL, 0, 0 },
127 { "table", BV_OPT_TABLE, 0, 0 },
128 { "specialization", BV_OPT_SPECIALIZATION, "[bf|df|random]", 0 },
129 { "gbr", BV_OPT_GBR, "[cdd]", 0,
130 "solver to use for basis reduction" },
131 { "version", 'V', 0, 0 },
132 { 0 }
135 static error_t approx_parse_opt(int key, char *arg, struct argp_state *state)
137 struct barvinok_options *options = state->input;
138 char *subopt;
140 switch (key) {
141 case BV_OPT_POLAPPROX:
142 if (!arg) {
143 options->polynomial_approximation = BV_APPROX_SIGN_APPROX;
144 if (options->approximation_method == BV_APPROX_NONE)
145 options->approximation_method = BV_APPROX_SCALE;
146 } else {
147 if (!strcmp(arg, "lower"))
148 options->polynomial_approximation = BV_APPROX_SIGN_LOWER;
149 else if (!strcmp(arg, "upper"))
150 options->polynomial_approximation = BV_APPROX_SIGN_UPPER;
151 if (options->approximation_method == BV_APPROX_NONE)
152 options->approximation_method = BV_APPROX_DROP;
154 break;
155 case BV_OPT_APPROX:
156 if (!strcmp(arg, "scale"))
157 options->approximation_method = BV_APPROX_SCALE;
158 else if (!strcmp(arg, "drop"))
159 options->approximation_method = BV_APPROX_DROP;
160 else if (!strcmp(arg, "volume"))
161 options->approximation_method = BV_APPROX_VOLUME;
162 else
163 argp_error(state, "unknown value for --approximation-method option");
164 break;
165 case BV_OPT_SCALE:
166 options->approximation_method = BV_APPROX_SCALE;
167 while (*arg != '\0')
168 switch (getsubopt(&arg, scale_opts, &subopt)) {
169 case SCALE_FAST:
170 options->scale_flags |= BV_APPROX_SCALE_FAST;
171 break;
172 case SCALE_SLOW:
173 options->scale_flags &= ~BV_APPROX_SCALE_FAST;
174 break;
175 case SCALE_NARROW:
176 options->scale_flags |= BV_APPROX_SCALE_NARROW;
177 options->scale_flags &= ~BV_APPROX_SCALE_NARROW2;
178 break;
179 case SCALE_NARROW2:
180 options->scale_flags |= BV_APPROX_SCALE_NARROW2;
181 options->scale_flags &= ~BV_APPROX_SCALE_NARROW;
182 break;
183 default:
184 argp_error(state, "unknown suboption '%s'\n", subopt);
186 break;
187 case BV_OPT_NO_LIFT:
188 options->volume_triangulate_lift = 0;
189 break;
190 case ARGP_KEY_END:
191 if (options->polynomial_approximation == BV_APPROX_SIGN_NONE &&
192 options->approximation_method != BV_APPROX_NONE) {
193 fprintf(stderr,
194 "no polynomial approximation selected; reseting approximation method\n");
195 options->approximation_method = BV_APPROX_NONE;
197 break;
198 default:
199 return ARGP_ERR_UNKNOWN;
201 return 0;
204 static error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state)
206 struct barvinok_options *options = state->input;
207 char *subopt;
209 switch (key) {
210 case ARGP_KEY_INIT:
211 state->child_inputs[0] = options;
212 break;
213 case 'V':
214 printf(barvinok_version());
215 exit(0);
216 case BV_OPT_SPECIALIZATION:
217 if (!strcmp(arg, "bf"))
218 options->incremental_specialization = BV_SPECIALIZATION_BF;
219 else if (!strcmp(arg, "df"))
220 options->incremental_specialization = BV_SPECIALIZATION_DF;
221 else if (!strcmp(arg, "random"))
222 options->incremental_specialization = BV_SPECIALIZATION_RANDOM;
223 break;
224 case BV_OPT_PRIMAL:
225 options->primal = 1;
226 break;
227 case BV_OPT_TABLE:
228 options->lookup_table = 1;
229 break;
230 case BV_OPT_GBR:
231 if (!strcmp(arg, "cdd"))
232 options->gbr_lp_solver = BV_GBR_CDD;
233 break;
234 case BV_OPT_MAXINDEX:
235 options->max_index = strtoul(arg, NULL, 0);
236 break;
237 default:
238 return ARGP_ERR_UNKNOWN;
240 return 0;
243 static struct argp approx_argp = {
244 approx_argp_options, approx_parse_opt, 0, 0
247 static struct argp_child barvinok_children[] = {
248 { &approx_argp, 0, "polynomial approximation", BV_GRP_APPROX },
249 { 0 }
252 struct argp barvinok_argp = {
253 barvinok_argp_options, barvinok_parse_opt, 0, 0, barvinok_children