isl_basic_set_project_out: drop redundant divs in result
[isl.git] / isl_tab.h
blob0b28f420b263078a37da4b42edcbfe2637544ed2
1 #ifndef ISL_TAB_H
2 #define ISL_TAB_H
4 #include "isl_lp.h"
5 #include "isl_map.h"
6 #include "isl_mat.h"
7 #include "isl_set.h"
9 struct isl_tab_var {
10 int index;
11 unsigned is_row : 1;
12 unsigned is_nonneg : 1;
13 unsigned is_zero : 1;
14 unsigned is_redundant : 1;
15 unsigned marked : 1;
16 unsigned frozen : 1;
17 unsigned negated : 1;
20 enum isl_tab_undo_type {
21 isl_tab_undo_bottom,
22 isl_tab_undo_empty,
23 isl_tab_undo_nonneg,
24 isl_tab_undo_redundant,
25 isl_tab_undo_zero,
26 isl_tab_undo_allocate,
27 isl_tab_undo_relax,
28 isl_tab_undo_bset_ineq,
29 isl_tab_undo_bset_eq,
30 isl_tab_undo_bset_div,
31 isl_tab_undo_saved_basis,
32 isl_tab_undo_drop_sample,
35 union isl_tab_undo_val {
36 int var_index;
37 int *col_var;
40 struct isl_tab_undo {
41 enum isl_tab_undo_type type;
42 union isl_tab_undo_val u;
43 struct isl_tab_undo *next;
46 /* The tableau maintains equality relations.
47 * Each column and each row is associated to a variable or a constraint.
48 * The "value" of an inequality constraint is the value of the corresponding
49 * slack variable.
50 * The "row_var" and "col_var" arrays map column and row indices
51 * to indices in the "var" and "con" arrays. The elements of these
52 * arrays maintain extra information about the variables and the constraints.
53 * Each row expresses the corresponding row variable as an affine expression
54 * of the column variables.
55 * The first two columns in the matrix contain the common denominator of
56 * the row and the numerator of the constant term.
57 * If "M" is set, then the third column represents the "big parameter".
58 * The third (M = 0) or fourth (M = 1) column
59 * in the matrix is called column 0 with respect to the col_var array.
60 * The sample value of the tableau is the value that assigns zero
61 * to all the column variables and the constant term of each affine
62 * expression to the corresponding row variable.
63 * The operations on the tableau maintain the property that the sample
64 * value satisfies the non-negativity constraints (usually on the slack
65 * variables).
67 * The big parameter represents an arbitrarily big (and divisible)
68 * positive number. If present, then the sign of a row is determined
69 * lexicographically, with the sign of the big parameter coefficient
70 * considered first. The big parameter is only used while
71 * solving PILP problems.
73 * The first n_dead column variables have their values fixed to zero.
74 * The corresponding tab_vars are flagged "is_zero".
75 * Some of the rows that have have zero coefficients in all but
76 * the dead columns are also flagged "is_zero".
78 * The first n_redundant rows correspond to inequality constraints
79 * that are always satisfied for any value satisfying the non-redundant
80 * rows. The corresponding tab_vars are flagged "is_redundant".
81 * A row variable that is flagged "is_zero" is also flagged "is_redundant"
82 * since the constraint has been reduced to 0 = 0 and is therefore always
83 * satisfied.
85 * There are "n_var" variables in total. The first "n_param" of these
86 * are called parameters and the last "n_div" of these are called divs.
87 * The basic tableau operations makes no distinction between different
88 * kinds of variables. These special variables are only used while
89 * solving PILP problems.
91 * Dead columns and redundant rows are detected on the fly.
92 * However, the basic operations do not ensure that all dead columns
93 * or all redundant rows are detected.
94 * isl_tab_detect_equalities and isl_tab_detect_redundant can be used
95 * to perform and exhaustive search for dead columns and redundant rows.
97 * The samples matrix contains "n_sample" integer points that have at some
98 * point been elements satisfying the tableau. The first "n_outside"
99 * of them no longer satisfy the tableau. They are kept because they
100 * can be reinstated during rollback when the constraint that cut them
101 * out is removed. These samples are only maintained for the context
102 * tableau while solving PILP problems.
104 enum isl_tab_row_sign {
105 isl_tab_row_unknown = 0,
106 isl_tab_row_pos,
107 isl_tab_row_neg,
108 isl_tab_row_any,
110 struct isl_tab {
111 struct isl_mat *mat;
113 unsigned n_row;
114 unsigned n_col;
115 unsigned n_dead;
116 unsigned n_redundant;
118 unsigned n_var;
119 unsigned n_param;
120 unsigned n_div;
121 unsigned max_var;
122 unsigned n_con;
123 unsigned n_eq;
124 unsigned max_con;
125 struct isl_tab_var *var;
126 struct isl_tab_var *con;
127 int *row_var; /* v >= 0 -> var v; v < 0 -> con ~v */
128 int *col_var; /* v >= 0 -> var v; v < 0 -> con ~v */
129 enum isl_tab_row_sign *row_sign;
131 struct isl_tab_undo bottom;
132 struct isl_tab_undo *top;
134 struct isl_vec *dual;
135 struct isl_basic_set *bset;
137 unsigned n_sample;
138 unsigned n_outside;
139 struct isl_mat *samples;
141 unsigned need_undo : 1;
142 unsigned rational : 1;
143 unsigned empty : 1;
144 unsigned in_undo : 1;
145 unsigned M : 1;
148 struct isl_tab *isl_tab_alloc(struct isl_ctx *ctx,
149 unsigned n_row, unsigned n_var, unsigned M);
150 void isl_tab_free(struct isl_tab *tab);
152 struct isl_tab *isl_tab_from_basic_map(struct isl_basic_map *bmap);
153 struct isl_tab *isl_tab_from_basic_set(struct isl_basic_set *bset);
154 struct isl_tab *isl_tab_from_recession_cone(struct isl_basic_map *bmap);
155 int isl_tab_cone_is_bounded(struct isl_tab *tab);
156 struct isl_basic_map *isl_basic_map_update_from_tab(struct isl_basic_map *bmap,
157 struct isl_tab *tab);
158 struct isl_basic_set *isl_basic_set_update_from_tab(struct isl_basic_set *bset,
159 struct isl_tab *tab);
160 struct isl_tab *isl_tab_detect_equalities(struct isl_tab *tab);
161 struct isl_tab *isl_tab_detect_redundant(struct isl_tab *tab);
162 #define ISL_TAB_SAVE_DUAL (1 << 0)
163 enum isl_lp_result isl_tab_min(struct isl_tab *tab,
164 isl_int *f, isl_int denom, isl_int *opt, isl_int *opt_denom,
165 unsigned flags);
167 struct isl_tab *isl_tab_extend(struct isl_tab *tab, unsigned n_new);
168 struct isl_tab *isl_tab_add_ineq(struct isl_tab *tab, isl_int *ineq);
169 struct isl_tab *isl_tab_add_valid_eq(struct isl_tab *tab, isl_int *eq);
171 int isl_tab_is_equality(struct isl_tab *tab, int con);
172 int isl_tab_is_redundant(struct isl_tab *tab, int con);
174 int isl_tab_sample_is_integer(struct isl_tab *tab);
175 struct isl_vec *isl_tab_get_sample_value(struct isl_tab *tab);
177 enum isl_ineq_type {
178 isl_ineq_error = -1,
179 isl_ineq_redundant,
180 isl_ineq_separate,
181 isl_ineq_cut,
182 isl_ineq_adj_eq,
183 isl_ineq_adj_ineq,
186 enum isl_ineq_type isl_tab_ineq_type(struct isl_tab *tab, isl_int *ineq);
188 struct isl_tab_undo *isl_tab_snap(struct isl_tab *tab);
189 int isl_tab_rollback(struct isl_tab *tab, struct isl_tab_undo *snap);
191 struct isl_tab *isl_tab_relax(struct isl_tab *tab, int con);
192 struct isl_tab *isl_tab_select_facet(struct isl_tab *tab, int con);
194 void isl_tab_dump(struct isl_tab *tab, FILE *out, int indent);
196 struct isl_map *isl_tab_basic_map_partial_lexopt(
197 struct isl_basic_map *bmap, struct isl_basic_set *dom,
198 struct isl_set **empty, int max);
200 /* private */
202 struct isl_tab_var *isl_tab_var_from_row(struct isl_tab *tab, int i);
203 int isl_tab_mark_redundant(struct isl_tab *tab, int row);
204 struct isl_tab *isl_tab_mark_empty(struct isl_tab *tab);
205 struct isl_tab *isl_tab_dup(struct isl_tab *tab);
206 int isl_tab_extend_cons(struct isl_tab *tab, unsigned n_new);
207 int isl_tab_allocate_con(struct isl_tab *tab);
208 int isl_tab_extend_vars(struct isl_tab *tab, unsigned n_new);
209 int isl_tab_allocate_var(struct isl_tab *tab);
210 void isl_tab_pivot(struct isl_tab *tab, int row, int col);
211 int isl_tab_add_row(struct isl_tab *tab, isl_int *line);
212 int isl_tab_row_is_redundant(struct isl_tab *tab, int row);
213 int isl_tab_min_at_most_neg_one(struct isl_tab *tab, struct isl_tab_var *var);
215 void isl_tab_push(struct isl_tab *tab, enum isl_tab_undo_type type);
216 void isl_tab_push_var(struct isl_tab *tab,
217 enum isl_tab_undo_type type, struct isl_tab_var *var);
218 void isl_tab_push_basis(struct isl_tab *tab);
220 #endif