polyhedron_sample.c: remove redundant MAXRAYS define
[barvinok.git] / options.c
blob96606fef30cee3ee0fcd57d57724bb3fd572c340
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
100 const char *scale_opts[] = {
101 "fast",
102 "slow",
103 NULL
106 struct argp_option barvinok_argp_options[] = {
107 { "index", BV_OPT_MAXINDEX, "int", 0,
108 "maximal index of simple cones in decomposition" },
109 { "primal", BV_OPT_PRIMAL, 0, 0 },
110 { "table", BV_OPT_TABLE, 0, 0 },
111 { "specialization", BV_OPT_SPECIALIZATION, "[bf|df|random]", 0 },
112 { "polynomial-approximation", BV_OPT_POLAPPROX, "lower|upper", 1 },
113 { "approximation-method", BV_OPT_APPROX, "scale|drop", 0,
114 "method to use in polynomial approximation [default: drop]" },
115 { "scale-options", BV_OPT_SCALE, "fast|slow", 0 },
116 { "gbr", BV_OPT_GBR, "[cdd]", 0,
117 "solver to use for basis reduction" },
118 { "version", 'V', 0, 0 },
119 { 0 }
122 error_t barvinok_parse_opt(int key, char *arg, struct argp_state *state)
124 struct barvinok_options *options = state->input;
125 char *subopt;
127 switch (key) {
128 case 'V':
129 printf(barvinok_version());
130 exit(0);
131 case BV_OPT_SPECIALIZATION:
132 if (!strcmp(arg, "bf"))
133 options->incremental_specialization = BV_SPECIALIZATION_BF;
134 else if (!strcmp(arg, "df"))
135 options->incremental_specialization = BV_SPECIALIZATION_DF;
136 else if (!strcmp(arg, "random"))
137 options->incremental_specialization = BV_SPECIALIZATION_RANDOM;
138 break;
139 case BV_OPT_PRIMAL:
140 options->primal = 1;
141 break;
142 case BV_OPT_TABLE:
143 options->lookup_table = 1;
144 break;
145 case BV_OPT_GBR:
146 if (!strcmp(arg, "cdd"))
147 options->gbr_lp_solver = BV_GBR_CDD;
148 break;
149 case BV_OPT_MAXINDEX:
150 options->max_index = strtoul(arg, NULL, 0);
151 break;
152 case BV_OPT_POLAPPROX:
153 if (!arg) {
154 options->polynomial_approximation = BV_APPROX_SIGN_APPROX;
155 if (options->approximation_method == BV_APPROX_NONE)
156 options->approximation_method = BV_APPROX_SCALE;
157 } else {
158 if (!strcmp(arg, "lower"))
159 options->polynomial_approximation = BV_APPROX_SIGN_LOWER;
160 else if (!strcmp(arg, "upper"))
161 options->polynomial_approximation = BV_APPROX_SIGN_UPPER;
162 if (options->approximation_method == BV_APPROX_NONE)
163 options->approximation_method = BV_APPROX_DROP;
165 break;
166 case BV_OPT_APPROX:
167 if (!strcmp(arg, "scale"))
168 options->approximation_method = BV_APPROX_SCALE;
169 else if (!strcmp(arg, "drop"))
170 options->approximation_method = BV_APPROX_DROP;
171 break;
172 case BV_OPT_SCALE:
173 options->approximation_method = BV_APPROX_SCALE;
174 while (*arg != '\0')
175 switch (getsubopt(&arg, scale_opts, &subopt)) {
176 case SCALE_FAST:
177 options->scale_flags |= BV_APPROX_SCALE_FAST;
178 break;
179 case SCALE_SLOW:
180 options->scale_flags &= ~BV_APPROX_SCALE_FAST;
181 break;
182 default:
183 argp_error(state, "unknown suboption '%s'\n", subopt);
185 break;
186 case ARGP_KEY_END:
187 if (options->polynomial_approximation == BV_APPROX_SIGN_NONE &&
188 options->approximation_method != BV_APPROX_NONE) {
189 fprintf(stderr,
190 "no polynomial approximation selected; reseting approximation method\n");
191 options->approximation_method = BV_APPROX_NONE;
193 break;
194 default:
195 return ARGP_ERR_UNKNOWN;
197 return 0;
200 struct argp barvinok_argp = {
201 barvinok_argp_options, barvinok_parse_opt, 0, 0