isl_sample.c: initial_basis: set n_unbounded and n_zero
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 10 Apr 2010 13:44:03 +0000 (15:44 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 10 Apr 2010 14:20:51 +0000 (16:20 +0200)
n_unbounded and n_zero are initialized to zero, but they can
be set to non-zero values in isl_tab_set_initial_basis_with_cone.
If isl_tab_sample is later called on an updated tab, but with
the old basis removed, then these values, in particular n_unbounded,
may not be valid anymore.
In particular, this happens in isl_tab_pip.c's gbr_get_sample.
Arguably, gbr_get_sample should reset the values of n_zero and n_unbounded
when it drops the basis, but it doens't hurt for initial_basis
to reset those values too.

isl_sample.c
isl_tab_pip.c
isl_test.c

index f7c1c87..13faa3b 100644 (file)
@@ -325,7 +325,8 @@ static struct isl_mat *initial_basis(struct isl_tab *tab)
        struct isl_mat *eq;
        struct isl_mat *Q;
 
-       n_eq = tab->n_var - tab->n_col + tab->n_dead;
+       tab->n_unbounded = 0;
+       tab->n_zero = n_eq = tab->n_var - tab->n_col + tab->n_dead;
        if (tab->empty || n_eq == 0 || n_eq == tab->n_var)
                return isl_mat_identity(tab->mat->ctx, 1 + tab->n_var);
 
index a15015e..36c3d02 100644 (file)
@@ -2620,10 +2620,9 @@ static struct isl_vec *gbr_get_sample(struct isl_context_gbr *cgbr)
                        if (cgbr->tab->basis->n_col != 1 + cgbr->tab->n_var) {
                                isl_mat_free(cgbr->tab->basis);
                                cgbr->tab->basis = NULL;
-                       } else {
-                               cgbr->tab->n_zero = 0;
-                               cgbr->tab->n_unbounded = 0;
                        }
+                       cgbr->tab->n_zero = 0;
+                       cgbr->tab->n_unbounded = 0;
                }
 
                snap = isl_tab_snap(cgbr->tab);
index 708d61b..384a973 100644 (file)
@@ -933,6 +933,28 @@ void test_closure(struct isl_ctx *ctx)
        isl_map_free(map2);
 }
 
+void test_lexmin(struct isl_ctx *ctx)
+{
+       const char *str;
+       isl_map *map;
+
+       str = "[p0, p1] -> { [] -> [] : "
+           "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
+           "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
+           "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
+           "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
+           "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
+           "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
+           "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
+           "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
+           "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
+           "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
+           "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
+       map = isl_map_read_from_str(ctx, str, -1);
+       map = isl_map_lexmin(map);
+       isl_map_free(map);
+}
+
 int main()
 {
        struct isl_ctx *ctx;
@@ -951,6 +973,7 @@ int main()
        test_gist(ctx);
        test_coalesce(ctx);
        test_closure(ctx);
+       test_lexmin(ctx);
        isl_ctx_free(ctx);
        return 0;
 }