add isl_basic_set_max_val
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 16 Apr 2013 13:34:13 +0000 (15:34 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 28 May 2013 16:27:13 +0000 (18:27 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/ilp.h
isl_ilp.c

index 13a4530..b009aef 100644 (file)
@@ -2576,6 +2576,9 @@ a singleton subset of the input.  Otherwise, return an empty set.
        enum isl_lp_result isl_basic_set_max(
                __isl_keep isl_basic_set *bset,
                __isl_keep isl_aff *obj, isl_int *opt)
+       __isl_give isl_val *isl_basic_set_max_val(
+               __isl_keep isl_basic_set *bset,
+               __isl_keep isl_aff *obj);
        enum isl_lp_result isl_set_min(__isl_keep isl_set *set,
                __isl_keep isl_aff *obj, isl_int *opt);
        enum isl_lp_result isl_set_max(__isl_keep isl_set *set,
@@ -2584,7 +2587,11 @@ a singleton subset of the input.  Otherwise, return an empty set.
 Compute the minimum or maximum of the integer affine expression C<obj>
 over the points in C<set>, returning the result in C<opt>.
 The return value may be one of C<isl_lp_error>,
-C<isl_lp_ok>, C<isl_lp_unbounded> or C<isl_lp_empty>.
+C<isl_lp_ok>, C<isl_lp_unbounded> or C<isl_lp_empty>, in case of
+an C<isl_lp_result>.  If the result is an C<isl_val> then
+the result is C<NULL> in case of an error, the optimal value in case
+there is one, infinity if the problem is unbounded and
+NaN if the problem is empty.
 
 =item * Parametric optimization
 
index 5b7c3bc..f910b1d 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <isl/aff_type.h>
 #include <isl/lp.h>
+#include <isl/val.h>
 
 #if defined(__cplusplus)
 extern "C" {
@@ -22,6 +23,8 @@ enum isl_lp_result isl_basic_set_solve_ilp(struct isl_basic_set *bset, int max,
                                      struct isl_vec **sol_p);
 enum isl_lp_result isl_basic_set_max(__isl_keep isl_basic_set *bset,
        __isl_keep isl_aff *obj, isl_int *opt);
+__isl_give isl_val *isl_basic_set_max_val(__isl_keep isl_basic_set *bset,
+       __isl_keep isl_aff *obj);
 enum isl_lp_result isl_set_min(__isl_keep isl_set *set,
        __isl_keep isl_aff *obj, isl_int *opt);
 enum isl_lp_result isl_set_max(__isl_keep isl_set *set,
index e6bc624..1f6b70d 100644 (file)
--- a/isl_ilp.c
+++ b/isl_ilp.c
@@ -16,6 +16,7 @@
 #include <isl_aff_private.h>
 #include <isl_local_space_private.h>
 #include <isl_mat_private.h>
+#include <isl_val_private.h>
 
 /* Given a basic set "bset", construct a basic set U such that for
  * each element x in U, the whole unit box positioned at x is inside
@@ -513,3 +514,72 @@ enum isl_lp_result isl_set_min(__isl_keep isl_set *set,
 {
        return isl_set_opt(set, 0, obj, opt);
 }
+
+/* Convert the result of a function that returns an isl_lp_result
+ * to an isl_val.  The numerator of "v" is set to the optimal value
+ * if lp_res is isl_lp_ok.  "max" is set if a maximum was computed.
+ *
+ * Return "v" with denominator set to 1 if lp_res is isl_lp_ok.
+ * Return NULL on error.
+ * Return a NaN if lp_res is isl_lp_empty.
+ * Return infinity or negative infinity if lp_res is isl_lp_unbounded,
+ * depending on "max".
+ */
+static __isl_give isl_val *convert_lp_result(enum isl_lp_result lp_res,
+       __isl_take isl_val *v, int max)
+{
+       isl_ctx *ctx;
+
+       if (lp_res == isl_lp_ok) {
+               isl_int_set_si(v->d, 1);
+               return isl_val_normalize(v);
+       }
+       ctx = isl_val_get_ctx(v);
+       isl_val_free(v);
+       if (lp_res == isl_lp_error)
+               return NULL;
+       if (lp_res == isl_lp_empty)
+               return isl_val_nan(ctx);
+       if (max)
+               return isl_val_infty(ctx);
+       else
+               return isl_val_neginfty(ctx);
+}
+
+/* Return the minimum (maximum if max is set) of the integer affine
+ * expression "obj" over the points in "bset".
+ *
+ * Return infinity or negative infinity if the optimal value is unbounded and
+ * NaN if "bset" is empty.
+ *
+ * Call isl_basic_set_opt and translate the results.
+ */
+__isl_give isl_val *isl_basic_set_opt_val(__isl_keep isl_basic_set *bset,
+       int max, __isl_keep isl_aff *obj)
+{
+       isl_ctx *ctx;
+       isl_val *res;
+       enum isl_lp_result lp_res;
+
+       if (!bset || !obj)
+               return NULL;
+
+       ctx = isl_aff_get_ctx(obj);
+       res = isl_val_alloc(ctx);
+       if (!res)
+               return NULL;
+       lp_res = isl_basic_set_opt(bset, max, obj, &res->n);
+       return convert_lp_result(lp_res, res, max);
+}
+
+/* Return the maximum of the integer affine
+ * expression "obj" over the points in "bset".
+ *
+ * Return infinity or negative infinity if the optimal value is unbounded and
+ * NaN if "bset" is empty.
+ */
+__isl_give isl_val *isl_basic_set_max_val(__isl_keep isl_basic_set *bset,
+       __isl_keep isl_aff *obj)
+{
+       return isl_basic_set_opt_val(bset, 1, obj);
+}