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
13 #include <isl_ilp_private.h>
15 #include <isl_vec_private.h>
17 /* The input of this program is the same as that of the "polytope_minimize"
18 * program from the barvinok distribution.
20 * Constraints of set is PolyLib format.
21 * Linear or affine objective function in PolyLib format.
24 static struct isl_vec
*isl_vec_lin_to_aff(struct isl_vec
*vec
)
30 aff
= isl_vec_alloc(vec
->ctx
, 1 + vec
->size
);
33 isl_int_set_si(aff
->el
[0], 0);
34 isl_seq_cpy(aff
->el
+ 1, vec
->el
, vec
->size
);
42 /* Rotate elements of vector right.
43 * In particular, move the constant term from the end of the
44 * vector to the start of the vector.
46 static struct isl_vec
*vec_ror(struct isl_vec
*vec
)
52 for (i
= vec
->size
- 2; i
>= 0; --i
)
53 isl_int_swap(vec
->el
[i
], vec
->el
[i
+ 1]);
57 int main(int argc
, char **argv
)
59 struct isl_ctx
*ctx
= isl_ctx_alloc();
60 struct isl_basic_set
*bset
;
65 enum isl_lp_result res
;
69 bset
= isl_basic_set_read_from_file(ctx
, stdin
);
71 obj
= isl_vec_read_from_file(ctx
, stdin
);
73 dim
= isl_basic_set_total_dim(bset
);
74 assert(obj
->size
>= dim
&& obj
->size
<= dim
+ 1);
75 if (obj
->size
!= dim
+ 1)
76 obj
= isl_vec_lin_to_aff(obj
);
79 res
= isl_basic_set_solve_ilp(bset
, 0, obj
->el
, &opt
, &sol
);
82 fprintf(stderr
, "error\n");
85 fprintf(stdout
, "empty\n");
87 case isl_lp_unbounded
:
88 fprintf(stdout
, "unbounded\n");
91 p
= isl_printer_to_file(ctx
, stdout
);
92 p
= isl_printer_print_vec(p
, sol
);
93 p
= isl_printer_end_line(p
);
94 p
= isl_printer_print_isl_int(p
, opt
);
95 p
= isl_printer_end_line(p
);
98 isl_basic_set_free(bset
);