barvinok_options_new_with_defaults: initialize scale_flags
[barvinok.git] / options.c
blob37abd9f523c8e53a8bdfbb1213d3c984a8e17c57
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;
76 #ifdef HAVE_LIBGLPK
77 options->gbr_lp_solver = BV_GBR_GLPK;
78 #elif defined HAVE_LIBCDDGMP
79 options->gbr_lp_solver = BV_GBR_CDD;
80 #else
81 options->gbr_lp_solver = BV_GBR_NONE;
82 #endif
84 options->bernstein_optimize = BV_BERNSTEIN_NONE;
86 options->bernstein_recurse = BV_BERNSTEIN_FACTORS;
88 return options;
91 void barvinok_options_free(struct barvinok_options *options)
93 free(options->stats);
94 free(options);
97 enum {
98 SCALE_FAST,
99 SCALE_SLOW,
100 SCALE_NARROW,
101 SCALE_NARROW2
104 const char *scale_opts[] = {
105 "fast",
106 "slow",
107 "narrow",
108 "narrow2",
109 NULL
112 struct argp_option barvinok_argp_options[] = {
113 { "index", BV_OPT_MAXINDEX, "int", 0,
114 "maximal index of simple cones in decomposition" },
115 { "primal", BV_OPT_PRIMAL, 0, 0 },
116 { "table", BV_OPT_TABLE, 0, 0 },
117 { "specialization", BV_OPT_SPECIALIZATION, "[bf|df|random]", 0 },
118 { "polynomial-approximation", BV_OPT_POLAPPROX, "lower|upper", 1 },
119 { "approximation-method", BV_OPT_APPROX, "scale|drop|volume", 0,
120 "method to use in polynomial approximation [default: drop]" },
121 { "scale-options", BV_OPT_SCALE, "fast|slow,narrow|narrow2", 0 },
122 { "gbr", BV_OPT_GBR, "[cdd]", 0,
123 "solver to use for basis reduction" },
124 { "version", 'V', 0, 0 },
125 { 0 }
128 error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state)
130 struct barvinok_options *options = state->input;
131 char *subopt;
133 switch (key) {
134 case 'V':
135 printf(barvinok_version());
136 exit(0);
137 case BV_OPT_SPECIALIZATION:
138 if (!strcmp(arg, "bf"))
139 options->incremental_specialization = BV_SPECIALIZATION_BF;
140 else if (!strcmp(arg, "df"))
141 options->incremental_specialization = BV_SPECIALIZATION_DF;
142 else if (!strcmp(arg, "random"))
143 options->incremental_specialization = BV_SPECIALIZATION_RANDOM;
144 break;
145 case BV_OPT_PRIMAL:
146 options->primal = 1;
147 break;
148 case BV_OPT_TABLE:
149 options->lookup_table = 1;
150 break;
151 case BV_OPT_GBR:
152 if (!strcmp(arg, "cdd"))
153 options->gbr_lp_solver = BV_GBR_CDD;
154 break;
155 case BV_OPT_MAXINDEX:
156 options->max_index = strtoul(arg, NULL, 0);
157 break;
158 case BV_OPT_POLAPPROX:
159 if (!arg) {
160 options->polynomial_approximation = BV_APPROX_SIGN_APPROX;
161 if (options->approximation_method == BV_APPROX_NONE)
162 options->approximation_method = BV_APPROX_SCALE;
163 } else {
164 if (!strcmp(arg, "lower"))
165 options->polynomial_approximation = BV_APPROX_SIGN_LOWER;
166 else if (!strcmp(arg, "upper"))
167 options->polynomial_approximation = BV_APPROX_SIGN_UPPER;
168 if (options->approximation_method == BV_APPROX_NONE)
169 options->approximation_method = BV_APPROX_DROP;
171 break;
172 case BV_OPT_APPROX:
173 if (!strcmp(arg, "scale"))
174 options->approximation_method = BV_APPROX_SCALE;
175 else if (!strcmp(arg, "drop"))
176 options->approximation_method = BV_APPROX_DROP;
177 else if (!strcmp(arg, "volume"))
178 options->approximation_method = BV_APPROX_VOLUME;
179 else
180 argp_error(state, "unknown value for --approximation-method option");
181 break;
182 case BV_OPT_SCALE:
183 options->approximation_method = BV_APPROX_SCALE;
184 while (*arg != '\0')
185 switch (getsubopt(&arg, scale_opts, &subopt)) {
186 case SCALE_FAST:
187 options->scale_flags |= BV_APPROX_SCALE_FAST;
188 break;
189 case SCALE_SLOW:
190 options->scale_flags &= ~BV_APPROX_SCALE_FAST;
191 break;
192 case SCALE_NARROW:
193 options->scale_flags |= BV_APPROX_SCALE_NARROW;
194 options->scale_flags &= ~BV_APPROX_SCALE_NARROW2;
195 break;
196 case SCALE_NARROW2:
197 options->scale_flags |= BV_APPROX_SCALE_NARROW2;
198 options->scale_flags &= ~BV_APPROX_SCALE_NARROW;
199 break;
200 default:
201 argp_error(state, "unknown suboption '%s'\n", subopt);
203 break;
204 case ARGP_KEY_END:
205 if (options->polynomial_approximation == BV_APPROX_SIGN_NONE &&
206 options->approximation_method != BV_APPROX_NONE) {
207 fprintf(stderr,
208 "no polynomial approximation selected; reseting approximation method\n");
209 options->approximation_method = BV_APPROX_NONE;
211 break;
212 default:
213 return ARGP_ERR_UNKNOWN;
215 return 0;
218 struct argp barvinok_argp = {
219 barvinok_argp_options, barvinok_parse_opt, 0, 0