2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the MIT 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;
68 bset = isl_basic_set_read_from_file(ctx, stdin);
70 obj = isl_vec_read_from_file(ctx, stdin);
72 dim = isl_basic_set_total_dim(bset);
73 assert(obj->size >= dim && obj->size <= dim + 1);
74 if (obj->size != dim + 1)
75 obj = isl_vec_lin_to_aff(obj);
78 res = isl_basic_set_solve_ilp(bset, 0, obj->el, &opt, &sol);
81 fprintf(stderr, "error\n");
84 fprintf(stdout, "empty\n");
86 case isl_lp_unbounded:
87 fprintf(stdout, "unbounded\n");
90 p = isl_printer_to_file(ctx, stdout);
91 p = isl_printer_print_vec(p, sol);
92 p = isl_printer_end_line(p);
93 p = isl_printer_print_isl_int(p, opt);
94 p = isl_printer_end_line(p);
97 isl_basic_set_free(bset);