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;
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
);
38 options
->stats
= ALLOC(struct barvinok_stats
);
39 if (!options
->stats
) {
44 barvinok_stats_clear(options
->stats
);
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;
56 options
->incremental_specialization
= 0;
58 options
->max_index
= 1;
61 options
->lookup_table
= 0;
63 options
->lookup_table
= 1;
66 options
->count_sample_infinite
= 1;
68 options
->count_sample_infinite
= 0;
71 options
->polynomial_approximation
= BV_APPROX_SIGN_NONE
;
72 options
->approximation_method
= BV_APPROX_NONE
;
75 options
->gbr_lp_solver
= BV_GBR_GLPK
;
76 #elif defined HAVE_LIBCDDGMP
77 options
->gbr_lp_solver
= BV_GBR_CDD
;
79 options
->gbr_lp_solver
= BV_GBR_NONE
;
82 options
->bernstein_optimize
= BV_BERNSTEIN_NONE
;
84 options
->bernstein_recurse
= BV_BERNSTEIN_FACTORS
;
89 void barvinok_options_free(struct barvinok_options
*options
)
100 const char *scale_opts
[] = {
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 },
122 error_t
barvinok_parse_opt(int key
, char *arg
, struct argp_state
*state
)
124 struct barvinok_options
*options
= state
->input
;
129 printf(barvinok_version());
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
;
143 options
->lookup_table
= 1;
146 if (!strcmp(arg
, "cdd"))
147 options
->gbr_lp_solver
= BV_GBR_CDD
;
149 case BV_OPT_MAXINDEX
:
150 options
->max_index
= strtoul(arg
, NULL
, 0);
152 case BV_OPT_POLAPPROX
:
154 options
->polynomial_approximation
= BV_APPROX_SIGN_APPROX
;
155 if (options
->approximation_method
== BV_APPROX_NONE
)
156 options
->approximation_method
= BV_APPROX_SCALE
;
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
;
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
;
173 options
->approximation_method
= BV_APPROX_SCALE
;
175 switch (getsubopt(&arg
, scale_opts
, &subopt
)) {
177 options
->scale_flags
|= BV_APPROX_SCALE_FAST
;
180 options
->scale_flags
&= ~BV_APPROX_SCALE_FAST
;
183 argp_error(state
, "unknown suboption '%s'\n", subopt
);
187 if (options
->polynomial_approximation
== BV_APPROX_SIGN_APPROX
&&
188 options
->approximation_method
== BV_APPROX_DROP
)
190 "drop method only available for lower and upper bounds");
191 if (options
->polynomial_approximation
== BV_APPROX_SIGN_NONE
&&
192 options
->approximation_method
!= BV_APPROX_NONE
) {
194 "no polynomial approximation selected; reseting approximation method\n");
195 options
->approximation_method
= BV_APPROX_NONE
;
199 return ARGP_ERR_UNKNOWN
;
204 struct argp barvinok_argp
= {
205 barvinok_argp_options
, barvinok_parse_opt
, 0, 0