barvinok 0.32.1
[barvinok.git] / polytope_minimize.c
blob5cdff8a5593e488c344363ae57e005e9333cf941
1 #include <assert.h>
2 #include <barvinok/options.h>
3 #include <barvinok/util.h>
4 #include "ilp.h"
5 #include "polysign.h"
7 int main(int argc, char **argv)
9 struct barvinok_options *options = barvinok_options_new_with_defaults();
10 Polyhedron *P;
11 Vector *obj, *affine;
12 Vector *minmax;
13 Vector *opt;
14 enum lp_result res;
15 Value one;
17 argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL);
19 P = Polyhedron_Read(options->MaxRays);
20 obj = Vector_Read();
21 minmax = Vector_Alloc(2);
23 if (obj->Size == P->Dimension) {
24 affine = Vector_Alloc(P->Dimension+1);
25 Vector_Copy(obj->p, affine->p, P->Dimension);
26 value_set_si(affine->p[P->Dimension], 0);
27 } else if (obj->Size == P->Dimension+1)
28 affine = obj;
29 else
30 assert(0);
32 value_init(one);
33 value_set_si(one, 1);
34 res = polyhedron_range(P, affine->p, one, &minmax->p[0], &minmax->p[1],
35 options);
36 assert(res == lp_ok);
37 value_clear(one);
39 opt = Polyhedron_Integer_Minimum(P, obj->p, minmax->p[0], minmax->p[1],
40 NULL, NULL, options);
41 Vector_Print(stdout, P_VALUE_FMT, opt);
42 Vector_Free(opt);
44 if (obj != affine)
45 Vector_Free(affine);
46 Vector_Free(obj);
47 Vector_Free(minmax);
48 Polyhedron_Free(P);
50 barvinok_options_free(options);