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