2 * Copyright 2010 INRIA Saclay
3 * Copyright 2012 Ecole Normale Superieure
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege,
8 * INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
9 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
10 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
13 /* Function for computing the lexicographic optimum of a map
14 * in the form of either an isl_map or an isl_pw_multi_aff.
17 #define xSF(TYPE,SUFFIX) TYPE ## SUFFIX
18 #define SF(TYPE,SUFFIX) xSF(TYPE,SUFFIX)
20 /* Given a basic map "bmap", compute the lexicographically minimal
21 * (or maximal) image element for each domain element in dom.
22 * If empty is not NULL, then set *empty to those elements in dom
23 * that do not have an image element.
25 * We first make sure the basic sets in dom are disjoint and then
26 * simply collect the results over each of the basic sets separately.
27 * We could probably improve the efficiency a bit by moving the union
28 * domain down into the parametric integer programming.
30 static __isl_give TYPE
*SF(basic_map_partial_lexopt
,SUFFIX
)(
31 __isl_take isl_basic_map
*bmap
, __isl_take isl_set
*dom
,
32 __isl_give isl_set
**empty
, int max
)
38 dom
= isl_set_make_disjoint(dom
);
42 if (isl_set_plain_is_empty(dom
)) {
43 isl_space
*space
= isl_basic_map_get_space(bmap
);
48 isl_basic_map_free(bmap
);
52 res
= SF(isl_basic_map_partial_lexopt
,SUFFIX
)(isl_basic_map_copy(bmap
),
53 isl_basic_set_copy(dom
->p
[0]), empty
, max
);
57 for (i
= 1; i
< dom
->n
; ++i
) {
60 res_i
= SF(isl_basic_map_partial_lexopt
,SUFFIX
)(
61 isl_basic_map_copy(bmap
),
62 isl_basic_set_copy(dom
->p
[i
]), empty
, max
);
64 res
= ADD(res
, res_i
);
66 all_empty
= isl_set_union_disjoint(all_empty
, *empty
);
72 isl_basic_map_free(bmap
);
78 isl_basic_map_free(bmap
);
82 static __isl_give TYPE
*SF(isl_map_partial_lexopt_aligned
,SUFFIX
)(
83 __isl_take isl_map
*map
, __isl_take isl_set
*dom
,
84 __isl_give isl_set
**empty
, int max
);
86 /* Given a map "map", compute the lexicographically minimal
87 * (or maximal) image element for each domain element in dom.
88 * Set *empty to those elements in dom that do not have an image element.
90 * Align parameters if needed and then call isl_map_partial_lexopt_aligned.
92 static __isl_give TYPE
*SF(isl_map_partial_lexopt
,SUFFIX
)(
93 __isl_take isl_map
*map
, __isl_take isl_set
*dom
,
94 __isl_give isl_set
**empty
, int max
)
98 if (isl_space_match(map
->dim
, isl_dim_param
, dom
->dim
, isl_dim_param
))
99 return SF(isl_map_partial_lexopt_aligned
,SUFFIX
)(map
, dom
,
101 if (!isl_space_has_named_params(map
->dim
) ||
102 !isl_space_has_named_params(dom
->dim
))
103 isl_die(map
->ctx
, isl_error_invalid
,
104 "unaligned unnamed parameters", goto error
);
105 map
= isl_map_align_params(map
, isl_map_get_space(dom
));
106 dom
= isl_map_align_params(dom
, isl_map_get_space(map
));
107 return SF(isl_map_partial_lexopt_aligned
,SUFFIX
)(map
, dom
, empty
, max
);
116 __isl_give TYPE
*SF(isl_map_lexopt
,SUFFIX
)(__isl_take isl_map
*map
, int max
)
119 isl_space
*dom_space
;
123 dom_space
= isl_space_domain(isl_space_copy(map
->dim
));
124 dom
= isl_set_universe(dom_space
);
125 return SF(isl_map_partial_lexopt
,SUFFIX
)(map
, dom
, NULL
, max
);
131 __isl_give TYPE
*SF(isl_map_lexmin
,SUFFIX
)(__isl_take isl_map
*map
)
133 return SF(isl_map_lexopt
,SUFFIX
)(map
, 0);
136 __isl_give TYPE
*SF(isl_map_lexmax
,SUFFIX
)(__isl_take isl_map
*map
)
138 return SF(isl_map_lexopt
,SUFFIX
)(map
, 1);
141 __isl_give TYPE
*SF(isl_set_lexmin
,SUFFIX
)(__isl_take isl_set
*set
)
143 return SF(isl_map_lexmin
,SUFFIX
)(set
);
146 __isl_give TYPE
*SF(isl_set_lexmax
,SUFFIX
)(__isl_take isl_set
*set
)
148 return SF(isl_map_lexmax
,SUFFIX
)(set
);