12 unsigned is_nonneg : 1;
14 unsigned is_redundant : 1;
20 enum isl_tab_undo_type {
24 isl_tab_undo_redundant,
26 isl_tab_undo_allocate,
28 isl_tab_undo_bset_ineq,
30 isl_tab_undo_bset_div,
31 isl_tab_undo_saved_basis,
32 isl_tab_undo_drop_sample,
33 isl_tab_undo_saved_samples,
36 union isl_tab_undo_val {
43 enum isl_tab_undo_type type;
44 union isl_tab_undo_val u;
45 struct isl_tab_undo *next;
48 /* The tableau maintains equality relations.
49 * Each column and each row is associated to a variable or a constraint.
50 * The "value" of an inequality constraint is the value of the corresponding
52 * The "row_var" and "col_var" arrays map column and row indices
53 * to indices in the "var" and "con" arrays. The elements of these
54 * arrays maintain extra information about the variables and the constraints.
55 * Each row expresses the corresponding row variable as an affine expression
56 * of the column variables.
57 * The first two columns in the matrix contain the common denominator of
58 * the row and the numerator of the constant term.
59 * If "M" is set, then the third column represents the "big parameter".
60 * The third (M = 0) or fourth (M = 1) column
61 * in the matrix is called column 0 with respect to the col_var array.
62 * The sample value of the tableau is the value that assigns zero
63 * to all the column variables and the constant term of each affine
64 * expression to the corresponding row variable.
65 * The operations on the tableau maintain the property that the sample
66 * value satisfies the non-negativity constraints (usually on the slack
69 * The big parameter represents an arbitrarily big (and divisible)
70 * positive number. If present, then the sign of a row is determined
71 * lexicographically, with the sign of the big parameter coefficient
72 * considered first. The big parameter is only used while
73 * solving PILP problems.
75 * The first n_dead column variables have their values fixed to zero.
76 * The corresponding tab_vars are flagged "is_zero".
77 * Some of the rows that have have zero coefficients in all but
78 * the dead columns are also flagged "is_zero".
80 * The first n_redundant rows correspond to inequality constraints
81 * that are always satisfied for any value satisfying the non-redundant
82 * rows. The corresponding tab_vars are flagged "is_redundant".
83 * A row variable that is flagged "is_zero" is also flagged "is_redundant"
84 * since the constraint has been reduced to 0 = 0 and is therefore always
87 * There are "n_var" variables in total. The first "n_param" of these
88 * are called parameters and the last "n_div" of these are called divs.
89 * The basic tableau operations makes no distinction between different
90 * kinds of variables. These special variables are only used while
91 * solving PILP problems.
93 * Dead columns and redundant rows are detected on the fly.
94 * However, the basic operations do not ensure that all dead columns
95 * or all redundant rows are detected.
96 * isl_tab_detect_implicit_equalities and isl_tab_detect_redundant can be used
97 * to perform and exhaustive search for dead columns and redundant rows.
99 * The samples matrix contains "n_sample" integer points that have at some
100 * point been elements satisfying the tableau. The first "n_outside"
101 * of them no longer satisfy the tableau. They are kept because they
102 * can be reinstated during rollback when the constraint that cut them
103 * out is removed. These samples are only maintained for the context
104 * tableau while solving PILP problems.
106 enum isl_tab_row_sign {
107 isl_tab_row_unknown = 0,
118 unsigned n_redundant;
127 struct isl_tab_var *var;
128 struct isl_tab_var *con;
129 int *row_var; /* v >= 0 -> var v; v < 0 -> con ~v */
130 int *col_var; /* v >= 0 -> var v; v < 0 -> con ~v */
131 enum isl_tab_row_sign *row_sign;
133 struct isl_tab_undo bottom;
134 struct isl_tab_undo *top;
136 struct isl_vec *dual;
137 struct isl_basic_set *bset;
142 struct isl_mat *samples;
146 struct isl_mat *basis;
148 unsigned need_undo : 1;
149 unsigned rational : 1;
151 unsigned in_undo : 1;
156 struct isl_tab *isl_tab_alloc(struct isl_ctx *ctx,
157 unsigned n_row, unsigned n_var, unsigned M);
158 void isl_tab_free(struct isl_tab *tab);
160 struct isl_tab *isl_tab_from_basic_map(struct isl_basic_map *bmap);
161 struct isl_tab *isl_tab_from_basic_set(struct isl_basic_set *bset);
162 struct isl_tab *isl_tab_from_recession_cone(struct isl_basic_set *bset);
163 int isl_tab_cone_is_bounded(struct isl_tab *tab);
164 struct isl_basic_map *isl_basic_map_update_from_tab(struct isl_basic_map *bmap,
165 struct isl_tab *tab);
166 struct isl_basic_set *isl_basic_set_update_from_tab(struct isl_basic_set *bset,
167 struct isl_tab *tab);
168 struct isl_tab *isl_tab_detect_implicit_equalities(struct isl_tab *tab);
169 struct isl_tab *isl_tab_detect_redundant(struct isl_tab *tab);
170 #define ISL_TAB_SAVE_DUAL (1 << 0)
171 enum isl_lp_result isl_tab_min(struct isl_tab *tab,
172 isl_int *f, isl_int denom, isl_int *opt, isl_int *opt_denom,
175 struct isl_tab *isl_tab_extend(struct isl_tab *tab, unsigned n_new);
176 struct isl_tab *isl_tab_add_ineq(struct isl_tab *tab, isl_int *ineq);
177 struct isl_tab *isl_tab_add_eq(struct isl_tab *tab, isl_int *eq);
178 struct isl_tab *isl_tab_add_valid_eq(struct isl_tab *tab, isl_int *eq);
180 int isl_tab_is_equality(struct isl_tab *tab, int con);
181 int isl_tab_is_redundant(struct isl_tab *tab, int con);
183 int isl_tab_sample_is_integer(struct isl_tab *tab);
184 struct isl_vec *isl_tab_get_sample_value(struct isl_tab *tab);
195 enum isl_ineq_type isl_tab_ineq_type(struct isl_tab *tab, isl_int *ineq);
197 struct isl_tab_undo *isl_tab_snap(struct isl_tab *tab);
198 int isl_tab_rollback(struct isl_tab *tab, struct isl_tab_undo *snap);
200 struct isl_tab *isl_tab_relax(struct isl_tab *tab, int con);
201 struct isl_tab *isl_tab_select_facet(struct isl_tab *tab, int con);
203 void isl_tab_dump(struct isl_tab *tab, FILE *out, int indent);
205 struct isl_map *isl_tab_basic_map_partial_lexopt(
206 struct isl_basic_map *bmap, struct isl_basic_set *dom,
207 struct isl_set **empty, int max);
211 struct isl_tab_var *isl_tab_var_from_row(struct isl_tab *tab, int i);
212 int isl_tab_mark_redundant(struct isl_tab *tab, int row);
213 struct isl_tab *isl_tab_mark_empty(struct isl_tab *tab);
214 struct isl_tab *isl_tab_dup(struct isl_tab *tab);
215 struct isl_tab *isl_tab_product(struct isl_tab *tab1, struct isl_tab *tab2);
216 int isl_tab_extend_cons(struct isl_tab *tab, unsigned n_new);
217 int isl_tab_allocate_con(struct isl_tab *tab);
218 int isl_tab_extend_vars(struct isl_tab *tab, unsigned n_new);
219 int isl_tab_allocate_var(struct isl_tab *tab);
220 void isl_tab_pivot(struct isl_tab *tab, int row, int col);
221 int isl_tab_add_row(struct isl_tab *tab, isl_int *line);
222 int isl_tab_row_is_redundant(struct isl_tab *tab, int row);
223 int isl_tab_min_at_most_neg_one(struct isl_tab *tab, struct isl_tab_var *var);
224 int isl_tab_kill_col(struct isl_tab *tab, int col);
226 void isl_tab_push(struct isl_tab *tab, enum isl_tab_undo_type type);
227 void isl_tab_push_var(struct isl_tab *tab,
228 enum isl_tab_undo_type type, struct isl_tab_var *var);
229 void isl_tab_push_basis(struct isl_tab *tab);
231 struct isl_tab *isl_tab_init_samples(struct isl_tab *tab);
232 struct isl_tab *isl_tab_add_sample(struct isl_tab *tab,
233 __isl_take isl_vec *sample);
234 struct isl_tab *isl_tab_drop_sample(struct isl_tab *tab, int s);
235 void isl_tab_save_samples(struct isl_tab *tab);
237 struct isl_tab *isl_tab_detect_equalities(struct isl_tab *tab,
238 struct isl_tab *tab_cone);