test_approx: test chamber based scaling
[barvinok.git] / options.c
blob9fd6b1ffe17109fd29d5e736aea9488089f1dde2
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,
103 SCALE_CHAMBER,
106 const char *scale_opts[] = {
107 "fast",
108 "slow",
109 "narrow",
110 "narrow2",
111 "chamber",
112 NULL
115 static struct argp_option approx_argp_options[] = {
116 { "polynomial-approximation", BV_OPT_POLAPPROX, "lower|upper", 1 },
117 { "approximation-method", BV_OPT_APPROX, "scale|drop|volume", 0,
118 "method to use in polynomial approximation [default: drop]" },
119 { "scale-options", BV_OPT_SCALE,
120 "fast|slow,narrow|narrow2,chamber", 0 },
121 { "no-lift", BV_OPT_NO_LIFT, NULL, 0,
122 "don't perform lifting triangulation in volume computation" },
123 { 0 }
126 static struct argp_option barvinok_argp_options[] = {
127 { "index", BV_OPT_MAXINDEX, "int", 0,
128 "maximal index of simple cones in decomposition" },
129 { "primal", BV_OPT_PRIMAL, 0, 0 },
130 { "table", BV_OPT_TABLE, 0, 0 },
131 { "specialization", BV_OPT_SPECIALIZATION, "[bf|df|random]", 0 },
132 { "gbr", BV_OPT_GBR, "[cdd]", 0,
133 "solver to use for basis reduction" },
134 { "version", 'V', 0, 0 },
135 { 0 }
138 static error_t approx_parse_opt(int key, char *arg, struct argp_state *state)
140 struct barvinok_options *options = state->input;
141 char *subopt;
143 switch (key) {
144 case BV_OPT_POLAPPROX:
145 if (!arg) {
146 options->polynomial_approximation = BV_APPROX_SIGN_APPROX;
147 if (options->approximation_method == BV_APPROX_NONE)
148 options->approximation_method = BV_APPROX_SCALE;
149 } else {
150 if (!strcmp(arg, "lower"))
151 options->polynomial_approximation = BV_APPROX_SIGN_LOWER;
152 else if (!strcmp(arg, "upper"))
153 options->polynomial_approximation = BV_APPROX_SIGN_UPPER;
154 if (options->approximation_method == BV_APPROX_NONE)
155 options->approximation_method = BV_APPROX_DROP;
157 break;
158 case BV_OPT_APPROX:
159 if (!strcmp(arg, "scale"))
160 options->approximation_method = BV_APPROX_SCALE;
161 else if (!strcmp(arg, "drop"))
162 options->approximation_method = BV_APPROX_DROP;
163 else if (!strcmp(arg, "volume"))
164 options->approximation_method = BV_APPROX_VOLUME;
165 else
166 argp_error(state, "unknown value for --approximation-method option");
167 break;
168 case BV_OPT_SCALE:
169 options->approximation_method = BV_APPROX_SCALE;
170 while (*arg != '\0')
171 switch (getsubopt(&arg, scale_opts, &subopt)) {
172 case SCALE_FAST:
173 options->scale_flags |= BV_APPROX_SCALE_FAST;
174 break;
175 case SCALE_SLOW:
176 options->scale_flags &= ~BV_APPROX_SCALE_FAST;
177 break;
178 case SCALE_NARROW:
179 options->scale_flags |= BV_APPROX_SCALE_NARROW;
180 options->scale_flags &= ~BV_APPROX_SCALE_NARROW2;
181 break;
182 case SCALE_NARROW2:
183 options->scale_flags |= BV_APPROX_SCALE_NARROW2;
184 options->scale_flags &= ~BV_APPROX_SCALE_NARROW;
185 break;
186 case SCALE_CHAMBER:
187 options->scale_flags |= BV_APPROX_SCALE_CHAMBER;
188 break;
189 default:
190 argp_error(state, "unknown suboption '%s'\n", subopt);
192 break;
193 case BV_OPT_NO_LIFT:
194 options->volume_triangulate_lift = 0;
195 break;
196 case ARGP_KEY_END:
197 if (options->polynomial_approximation == BV_APPROX_SIGN_NONE &&
198 options->approximation_method != BV_APPROX_NONE) {
199 fprintf(stderr,
200 "no polynomial approximation selected; reseting approximation method\n");
201 options->approximation_method = BV_APPROX_NONE;
203 break;
204 default:
205 return ARGP_ERR_UNKNOWN;
207 return 0;
210 static error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state)
212 struct barvinok_options *options = state->input;
213 char *subopt;
215 switch (key) {
216 case ARGP_KEY_INIT:
217 state->child_inputs[0] = options;
218 break;
219 case 'V':
220 printf(barvinok_version());
221 exit(0);
222 case BV_OPT_SPECIALIZATION:
223 if (!strcmp(arg, "bf"))
224 options->incremental_specialization = BV_SPECIALIZATION_BF;
225 else if (!strcmp(arg, "df"))
226 options->incremental_specialization = BV_SPECIALIZATION_DF;
227 else if (!strcmp(arg, "random"))
228 options->incremental_specialization = BV_SPECIALIZATION_RANDOM;
229 break;
230 case BV_OPT_PRIMAL:
231 options->primal = 1;
232 break;
233 case BV_OPT_TABLE:
234 options->lookup_table = 1;
235 break;
236 case BV_OPT_GBR:
237 if (!strcmp(arg, "cdd"))
238 options->gbr_lp_solver = BV_GBR_CDD;
239 break;
240 case BV_OPT_MAXINDEX:
241 options->max_index = strtoul(arg, NULL, 0);
242 break;
243 default:
244 return ARGP_ERR_UNKNOWN;
246 return 0;
249 static struct argp approx_argp = {
250 approx_argp_options, approx_parse_opt, 0, 0
253 static struct argp_child barvinok_children[] = {
254 { &approx_argp, 0, "polynomial approximation", BV_GRP_APPROX },
255 { 0 }
258 struct argp barvinok_argp = {
259 barvinok_argp_options, barvinok_parse_opt, 0, 0, barvinok_children