isl_tab: introduce support for "big parameters"
[isl.git] / isl_tab.h
blob17de6ed28344fad4778ab699a8812808b6569a57
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"
8 struct isl_tab_var {
9 int index;
10 unsigned is_row : 1;
11 unsigned is_nonneg : 1;
12 unsigned is_zero : 1;
13 unsigned is_redundant : 1;
14 unsigned marked : 1;
15 unsigned frozen : 1;
18 enum isl_tab_undo_type {
19 isl_tab_undo_bottom,
20 isl_tab_undo_empty,
21 isl_tab_undo_nonneg,
22 isl_tab_undo_redundant,
23 isl_tab_undo_zero,
24 isl_tab_undo_allocate,
25 isl_tab_undo_relax,
26 isl_tab_undo_saved_basis,
29 union isl_tab_undo_val {
30 int var_index;
31 int *col_var;
34 struct isl_tab_undo {
35 enum isl_tab_undo_type type;
36 union isl_tab_undo_val u;
37 struct isl_tab_undo *next;
40 /* The tableau maintains equality relations.
41 * Each column and each row is associated to a variable or a constraint.
42 * The "value" of an inequality constraint is the value of the corresponding
43 * slack variable.
44 * The "row_var" and "col_var" arrays map column and row indices
45 * to indices in the "var" and "con" arrays. The elements of these
46 * arrays maintain extra information about the variables and the constraints.
47 * Each row expresses the corresponding row variable as an affine expression
48 * of the column variables.
49 * The first two columns in the matrix contain the common denominator of
50 * the row and the numerator of the constant term.
51 * If "M" is set, then the third column represents the "big parameter".
52 * The third (M = 0) or fourth (M = 1) column
53 * in the matrix is called column 0 with respect to the col_var array.
54 * The sample value of the tableau is the value that assigns zero
55 * to all the column variables and the constant term of each affine
56 * expression to the corresponding row variable.
57 * The operations on the tableau maintain the property that the sample
58 * value satisfies the non-negativity constraints (usually on the slack
59 * variables).
61 * The big parameter represents an arbitrarily big (and divisible)
62 * positive number. If present, then the sign of a row is determined
63 * lexicographically, with the sign of the big parameter coefficient
64 * considered first. The big parameter will only be used while
65 * solving PILP problems.
67 * The first n_dead column variables have their values fixed to zero.
68 * The corresponding tab_vars are flagged "is_zero".
69 * Some of the rows that have have zero coefficients in all but
70 * the dead columns are also flagged "is_zero".
72 * The first n_redundant rows correspond to inequality constraints
73 * that are always satisfied for any value satisfying the non-redundant
74 * rows. The corresponding tab_vars are flagged "is_redundant".
75 * A row variable that is flagged "is_zero" is also flagged "is_redundant"
76 * since the constraint has been reduced to 0 = 0 and is therefore always
77 * satisfied.
79 * There are "n_var" variables in total. The first "n_param" of these
80 * are called parameters and the last "n_div" of these are called divs.
81 * The basic tableau operations makes no distinction between different
82 * kinds of variables.
84 * Dead columns and redundant rows are detected on the fly.
85 * However, the basic operations do not ensure that all dead columns
86 * or all redundant rows are detected.
87 * isl_tab_detect_equalities and isl_tab_detect_redundant can be used
88 * to perform and exhaustive search for dead columns and redundant rows.
90 struct isl_tab {
91 struct isl_mat *mat;
93 unsigned n_row;
94 unsigned n_col;
95 unsigned n_dead;
96 unsigned n_redundant;
98 unsigned n_var;
99 unsigned n_param;
100 unsigned n_div;
101 unsigned max_var;
102 unsigned n_con;
103 unsigned n_eq;
104 unsigned max_con;
105 struct isl_tab_var *var;
106 struct isl_tab_var *con;
107 int *row_var; /* v >= 0 -> var v; v < 0 -> con ~v */
108 int *col_var; /* v >= 0 -> var v; v < 0 -> con ~v */
110 struct isl_tab_undo bottom;
111 struct isl_tab_undo *top;
113 struct isl_vec *dual;
115 unsigned need_undo : 1;
116 unsigned rational : 1;
117 unsigned empty : 1;
118 unsigned in_undo : 1;
119 unsigned M : 1;
122 struct isl_tab *isl_tab_alloc(struct isl_ctx *ctx,
123 unsigned n_row, unsigned n_var, unsigned M);
124 void isl_tab_free(struct isl_tab *tab);
126 struct isl_tab *isl_tab_from_basic_map(struct isl_basic_map *bmap);
127 struct isl_tab *isl_tab_from_basic_set(struct isl_basic_set *bset);
128 struct isl_tab *isl_tab_from_recession_cone(struct isl_basic_map *bmap);
129 int isl_tab_cone_is_bounded(struct isl_tab *tab);
130 struct isl_basic_map *isl_basic_map_update_from_tab(struct isl_basic_map *bmap,
131 struct isl_tab *tab);
132 struct isl_basic_set *isl_basic_set_update_from_tab(struct isl_basic_set *bset,
133 struct isl_tab *tab);
134 struct isl_tab *isl_tab_detect_equalities(struct isl_tab *tab);
135 struct isl_tab *isl_tab_detect_redundant(struct isl_tab *tab);
136 #define ISL_TAB_SAVE_DUAL (1 << 0)
137 enum isl_lp_result isl_tab_min(struct isl_tab *tab,
138 isl_int *f, isl_int denom, isl_int *opt, isl_int *opt_denom,
139 unsigned flags);
141 struct isl_tab *isl_tab_extend(struct isl_tab *tab, unsigned n_new);
142 struct isl_tab *isl_tab_add_ineq(struct isl_tab *tab, isl_int *ineq);
143 struct isl_tab *isl_tab_add_valid_eq(struct isl_tab *tab, isl_int *eq);
145 int isl_tab_is_equality(struct isl_tab *tab, int con);
146 int isl_tab_is_redundant(struct isl_tab *tab, int con);
148 int isl_tab_sample_is_integer(struct isl_tab *tab);
149 struct isl_vec *isl_tab_get_sample_value(struct isl_tab *tab);
151 enum isl_ineq_type {
152 isl_ineq_error = -1,
153 isl_ineq_redundant,
154 isl_ineq_separate,
155 isl_ineq_cut,
156 isl_ineq_adj_eq,
157 isl_ineq_adj_ineq,
160 enum isl_ineq_type isl_tab_ineq_type(struct isl_tab *tab, isl_int *ineq);
162 struct isl_tab_undo *isl_tab_snap(struct isl_tab *tab);
163 int isl_tab_rollback(struct isl_tab *tab, struct isl_tab_undo *snap);
165 struct isl_tab *isl_tab_relax(struct isl_tab *tab, int con);
166 struct isl_tab *isl_tab_select_facet(struct isl_tab *tab, int con);
168 void isl_tab_dump(struct isl_tab *tab, FILE *out, int indent);
170 /* private */
172 struct isl_tab_var *isl_tab_var_from_row(struct isl_tab *tab, int i);
173 int isl_tab_mark_redundant(struct isl_tab *tab, int row);
174 struct isl_tab *isl_tab_mark_empty(struct isl_tab *tab);
175 struct isl_tab *isl_tab_dup(struct isl_tab *tab);
176 int isl_tab_extend_cons(struct isl_tab *tab, unsigned n_new);
177 int isl_tab_allocate_con(struct isl_tab *tab);
178 int isl_tab_extend_vars(struct isl_tab *tab, unsigned n_new);
179 int isl_tab_allocate_var(struct isl_tab *tab);
180 void isl_tab_pivot(struct isl_tab *tab, int row, int col);
181 int isl_tab_add_row(struct isl_tab *tab, isl_int *line);
182 int isl_tab_row_is_redundant(struct isl_tab *tab, int row);
183 int isl_tab_min_at_most_neg_one(struct isl_tab *tab, struct isl_tab_var *var);
185 void isl_tab_push(struct isl_tab *tab, enum isl_tab_undo_type type);
186 void isl_tab_push_var(struct isl_tab *tab,
187 enum isl_tab_undo_type type, struct isl_tab_var *var);
188 void isl_tab_push_basis(struct isl_tab *tab);
190 #endif