2 #include <barvinok/options.h>
3 #include <barvinok/util.h>
7 #ifdef HAVE_GROWING_CHERNIKOVA
8 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
14 Vector
*Polyhedron_Sample(Polyhedron
*P
, struct barvinok_options
*options
)
20 #define ALLOC(type) (type*)malloc(sizeof(type))
22 void barvinok_stats_clear(struct barvinok_stats
*stats
)
24 stats
->base_cones
= 0;
25 stats
->volume_simplices
= 0;
28 void barvinok_stats_print(struct barvinok_stats
*stats
, FILE *out
)
30 fprintf(out
, "Base cones: %d\n", stats
->base_cones
);
31 if (stats
->volume_simplices
)
32 fprintf(out
, "Volume simplices: %d\n", stats
->volume_simplices
);
35 struct barvinok_options
*barvinok_options_new_with_defaults()
37 struct barvinok_options
*options
= ALLOC(struct barvinok_options
);
41 options
->stats
= ALLOC(struct barvinok_stats
);
42 if (!options
->stats
) {
47 barvinok_stats_clear(options
->stats
);
52 options
->MaxRays
= MAXRAYS
;
54 #ifdef USE_INCREMENTAL_BF
55 options
->incremental_specialization
= 2;
56 #elif defined USE_INCREMENTAL_DF
57 options
->incremental_specialization
= 1;
59 options
->incremental_specialization
= 0;
61 options
->max_index
= 1;
64 options
->lookup_table
= 0;
66 options
->lookup_table
= 1;
69 options
->count_sample_infinite
= 1;
71 options
->count_sample_infinite
= 0;
73 options
->try_Delaunay_triangulation
= 0;
75 options
->polynomial_approximation
= BV_APPROX_SIGN_NONE
;
76 options
->approximation_method
= BV_APPROX_NONE
;
77 options
->scale_flags
= 0;
78 options
->volume_triangulate
= BV_VOL_VERTEX
;
81 options
->gbr_lp_solver
= BV_GBR_GLPK
;
82 #elif defined HAVE_LIBCDDGMP
83 options
->gbr_lp_solver
= BV_GBR_CDD
;
85 options
->gbr_lp_solver
= BV_GBR_NONE
;
88 options
->bernstein_optimize
= BV_BERNSTEIN_NONE
;
90 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
95 void barvinok_options_free(struct barvinok_options
*options
)
109 const char *scale_opts
[] = {
118 static struct argp_option approx_argp_options
[] = {
119 { "polynomial-approximation", BV_OPT_POLAPPROX
, "lower|upper", 1 },
120 { "approximation-method", BV_OPT_APPROX
, "scale|drop|volume|bernouilli", 0,
121 "method to use in polynomial approximation [default: drop]" },
122 { "scale-options", BV_OPT_SCALE
,
123 "fast|slow,narrow|narrow2,chamber", 0 },
124 { "volume-triangulation", BV_OPT_VOL
, "lift|vertex|barycenter", 0,
125 "type of triangulation to perform in volume computation [default: vertex]" },
129 static struct argp_option barvinok_argp_options
[] = {
130 { "index", BV_OPT_MAXINDEX
, "int", 0,
131 "maximal index of simple cones in decomposition" },
132 { "primal", BV_OPT_PRIMAL
, 0, 0 },
133 { "table", BV_OPT_TABLE
, 0, 0 },
134 { "specialization", BV_OPT_SPECIALIZATION
, "[bf|df|random|todd]" },
135 #if defined(HAVE_LIBGLPK) || defined(HAVE_LIBCDDGMP)
137 #if defined(HAVE_LIBGLPK) && defined(HAVE_LIBCDDGMP)
139 #elif defined(HAVE_LIBGLPK)
141 #elif defined(HAVE_LIBCDDGMP)
144 0, "solver to use for basis reduction "
147 #elif defined HAVE_LIBCDDGMP
152 { "bernstein-recurse", BV_OPT_RECURSE
, "none|factors|intervals|full", 0,
153 "[default: factors]" },
154 { "recurse", BV_OPT_RECURSE
, "",
155 OPTION_ALIAS
| OPTION_HIDDEN
},
156 { "version", 'V', 0, 0 },
160 static error_t
approx_parse_opt(int key
, char *arg
, struct argp_state
*state
)
162 struct barvinok_options
*options
= state
->input
;
166 case BV_OPT_POLAPPROX
:
168 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
169 if (options
->approximation_method
== BV_APPROX_NONE
)
170 options
->approximation_method
= BV_APPROX_SCALE
;
172 if (!strcmp(arg
, "lower"))
173 options
->polynomial_approximation
= BV_APPROX_SIGN_LOWER
;
174 else if (!strcmp(arg
, "upper"))
175 options
->polynomial_approximation
= BV_APPROX_SIGN_UPPER
;
176 if (options
->approximation_method
== BV_APPROX_NONE
)
177 options
->approximation_method
= BV_APPROX_DROP
;
181 if (!strcmp(arg
, "scale"))
182 options
->approximation_method
= BV_APPROX_SCALE
;
183 else if (!strcmp(arg
, "drop"))
184 options
->approximation_method
= BV_APPROX_DROP
;
185 else if (!strcmp(arg
, "volume"))
186 options
->approximation_method
= BV_APPROX_VOLUME
;
187 else if (!strcmp(arg
, "bernoulli"))
188 options
->approximation_method
= BV_APPROX_BERNOULLI
;
190 argp_error(state
, "unknown value for --approximation-method option");
193 options
->approximation_method
= BV_APPROX_SCALE
;
195 switch (getsubopt(&arg
, scale_opts
, &subopt
)) {
197 options
->scale_flags
|= BV_APPROX_SCALE_FAST
;
200 options
->scale_flags
&= ~BV_APPROX_SCALE_FAST
;
203 options
->scale_flags
|= BV_APPROX_SCALE_NARROW
;
204 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW2
;
207 options
->scale_flags
|= BV_APPROX_SCALE_NARROW2
;
208 options
->scale_flags
&= ~BV_APPROX_SCALE_NARROW
;
211 options
->scale_flags
|= BV_APPROX_SCALE_CHAMBER
;
214 argp_error(state
, "unknown suboption '%s'\n", subopt
);
218 if (!strcmp(arg
, "lift"))
219 options
->volume_triangulate
= BV_VOL_LIFT
;
220 else if (!strcmp(arg
, "vertex"))
221 options
->volume_triangulate
= BV_VOL_VERTEX
;
222 else if (!strcmp(arg
, "barycenter"))
223 options
->volume_triangulate
= BV_VOL_BARYCENTER
;
226 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
&&
227 options
->approximation_method
!= BV_APPROX_NONE
) {
229 "no polynomial approximation selected; reseting approximation method\n");
230 options
->approximation_method
= BV_APPROX_NONE
;
234 return ARGP_ERR_UNKNOWN
;
239 static error_t
barvinok_parse_opt(int key
, char *arg
, struct argp_state
*state
)
241 struct barvinok_options
*options
= state
->input
;
246 state
->child_inputs
[0] = options
;
249 printf(barvinok_version());
251 case BV_OPT_SPECIALIZATION
:
252 if (!strcmp(arg
, "bf"))
253 options
->incremental_specialization
= BV_SPECIALIZATION_BF
;
254 else if (!strcmp(arg
, "df"))
255 options
->incremental_specialization
= BV_SPECIALIZATION_DF
;
256 else if (!strcmp(arg
, "random"))
257 options
->incremental_specialization
= BV_SPECIALIZATION_RANDOM
;
258 else if (!strcmp(arg
, "todd"))
259 options
->incremental_specialization
= BV_SPECIALIZATION_TODD
;
265 options
->lookup_table
= 1;
268 if (!strcmp(arg
, "cdd"))
269 options
->gbr_lp_solver
= BV_GBR_CDD
;
270 if (!strcmp(arg
, "glpk"))
271 options
->gbr_lp_solver
= BV_GBR_GLPK
;
273 case BV_OPT_MAXINDEX
:
274 options
->max_index
= strtoul(arg
, NULL
, 0);
277 if (!strcmp(arg
, "none"))
278 options
->bernstein_recurse
= 0;
279 else if (!strcmp(arg
, "factors"))
280 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
281 else if (!strcmp(arg
, "intervals"))
282 options
->bernstein_recurse
= BV_BERNSTEIN_INTERVALS
;
283 else if (!strcmp(arg
, "full"))
284 options
->bernstein_recurse
=
285 BV_BERNSTEIN_FACTORS
| BV_BERNSTEIN_INTERVALS
;
288 return ARGP_ERR_UNKNOWN
;
293 static struct argp approx_argp
= {
294 approx_argp_options
, approx_parse_opt
, 0, 0
297 static struct argp_child barvinok_children
[] = {
298 { &approx_argp
, 0, "polynomial approximation", BV_GRP_APPROX
},
302 struct argp barvinok_argp
= {
303 barvinok_argp_options
, barvinok_parse_opt
, 0, 0, barvinok_children