add some memory management annotations
[isl.git] / pip.c
blob52e3dfa8ec85d0e2a8f6e90e19895d949527cb8b
1 #include <assert.h>
2 #include <string.h>
3 #include "isl_set.h"
4 #include "isl_tab.h"
5 #include "isl_map_private.h"
7 /* The input of this program is the same as that of the "example" program
8 * from the PipLib distribution, except that the "big parameter column"
9 * should always be -1.
11 * Context constraints in PolyLib format
12 * -1
13 * Problem constraints in PolyLib format
14 * Optional list of options
16 * The options are
17 * Maximize compute maximum instead of minimum
18 * Rational compute rational optimum instead of integer optimum
19 * Urs_parms don't assume parameters are non-negative
20 * Urs_unknowns don't assume unknowns are non-negative
23 static struct isl_basic_set *to_parameter_domain(struct isl_basic_set *context)
25 struct isl_dim *param_dim;
26 struct isl_basic_set *model;
28 param_dim = isl_dim_set_alloc(context->ctx,
29 isl_basic_set_n_dim(context), 0);
30 model = isl_basic_set_empty(param_dim);
31 context = isl_basic_set_from_underlying_set(context, model);
33 return context;
36 int main(int argc, char **argv)
38 struct isl_ctx *ctx = isl_ctx_alloc();
39 struct isl_basic_set *context, *bset;
40 struct isl_set *set;
41 struct isl_set *empty;
42 int neg_one;
43 char s[1024];
44 int urs_parms = 0;
45 int urs_unknowns = 0;
46 int max = 0;
47 int n;
49 context = isl_basic_set_read_from_file(ctx, stdin, 0, ISL_FORMAT_POLYLIB);
50 assert(context);
51 n = fscanf(stdin, "%d", &neg_one);
52 assert(n == 1);
53 assert(neg_one == -1);
54 bset = isl_basic_set_read_from_file(ctx, stdin,
55 isl_basic_set_dim(context, isl_dim_set), ISL_FORMAT_POLYLIB);
57 while (fgets(s, sizeof(s), stdin)) {
58 if (strncasecmp(s, "Maximize", 8) == 0)
59 max = 1;
60 if (strncasecmp(s, "Rational", 8) == 0)
61 bset = isl_basic_set_set_rational(bset);
62 if (strncasecmp(s, "Urs_parms", 9) == 0)
63 urs_parms = 1;
64 if (strncasecmp(s, "Urs_unknowns", 12) == 0)
65 urs_unknowns = 1;
67 if (!urs_parms)
68 context = isl_basic_set_intersect(context,
69 isl_basic_set_positive_orthant(isl_basic_set_get_dim(context)));
70 context = to_parameter_domain(context);
71 if (!urs_unknowns)
72 bset = isl_basic_set_intersect(bset,
73 isl_basic_set_positive_orthant(isl_basic_set_get_dim(bset)));
75 if (max)
76 set = isl_basic_set_partial_lexmax(bset, context, &empty);
77 else
78 set = isl_basic_set_partial_lexmin(bset, context, &empty);
80 isl_set_dump(set, stdout, 0);
81 fprintf(stdout, "no solution:\n");
82 isl_set_dump(empty, stdout, 4);
84 isl_set_free(set);
85 isl_set_free(empty);
86 isl_ctx_free(ctx);
88 return 0;