2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
16 /* The input of this program is the same as that of the "polytope_minimize"
17 * program from the barvinok distribution.
19 * Constraints of set is PolyLib format.
20 * Linear or affine objective function in PolyLib format.
23 static struct isl_vec
*isl_vec_lin_to_aff(struct isl_vec
*vec
)
29 aff
= isl_vec_alloc(vec
->ctx
, 1 + vec
->size
);
32 isl_int_set_si(aff
->el
[0], 0);
33 isl_seq_cpy(aff
->el
+ 1, vec
->el
, vec
->size
);
41 /* Rotate elements of vector right.
42 * In particular, move the constant term from the end of the
43 * vector to the start of the vector.
45 static struct isl_vec
*vec_ror(struct isl_vec
*vec
)
51 for (i
= vec
->size
- 2; i
>= 0; --i
)
52 isl_int_swap(vec
->el
[i
], vec
->el
[i
+ 1]);
56 int main(int argc
, char **argv
)
58 struct isl_ctx
*ctx
= isl_ctx_alloc();
59 struct isl_basic_set
*bset
;
64 enum isl_lp_result res
;
67 bset
= isl_basic_set_read_from_file(ctx
, stdin
, 0, ISL_FORMAT_POLYLIB
);
69 obj
= isl_vec_read_from_file(ctx
, stdin
, ISL_FORMAT_POLYLIB
);
71 dim
= isl_basic_set_total_dim(bset
);
72 assert(obj
->size
>= dim
&& obj
->size
<= dim
+ 1);
73 if (obj
->size
!= dim
+ 1)
74 obj
= isl_vec_lin_to_aff(obj
);
77 res
= isl_basic_set_solve_ilp(bset
, 0, obj
->el
, &opt
, &sol
);
80 fprintf(stderr
, "error\n");
83 fprintf(stdout
, "empty\n");
85 case isl_lp_unbounded
:
86 fprintf(stdout
, "unbounded\n");
89 isl_vec_dump(sol
, stdout
, 0);
90 isl_int_print(stdout
, opt
, 0);
91 fprintf(stdout
, "\n");
93 isl_basic_set_free(bset
);