isl_tab: optionally save dual solution
[isl.git] / isl_tab.h
blob1df42e15612343cbb269b4cf6e1d7b1555c1c2ae
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,
28 struct isl_tab_undo {
29 enum isl_tab_undo_type type;
30 struct isl_tab_var *var;
31 struct isl_tab_undo *next;
34 /* The tableau maintains equality relations.
35 * Each column and each row is associated to a variable or a constraint.
36 * The "value" of an inequality constraint is the value of the corresponding
37 * slack variable.
38 * The "row_var" and "col_var" arrays map column and row indices
39 * to indices in the "var" and "con" arrays. The elements of these
40 * arrays maintain extra information about the variables and the constraints.
41 * Each row expresses the corresponding row variable as an affine expression
42 * of the column variables.
43 * The first two columns in the matrix contain the common denominator of
44 * the row and the numerator of the constant term. The third column
45 * in the matrix is called column 0 with respect to the col_var array.
46 * The sample value of the tableau is the value that assigns zero
47 * to all the column variables and the constant term of each affine
48 * expression to the corresponding row variable.
49 * The operations on the tableau maintain the property that the sample
50 * value satisfies the non-negativity constraints (usually on the slack
51 * variables).
53 * The first n_dead column variables have their values fixed to zero.
54 * The corresponding tab_vars are flagged "is_zero".
55 * Some of the rows that have have zero coefficients in all but
56 * the dead columns are also flagged "is_zero".
58 * The first n_redundant rows correspond to inequality constraints
59 * that are always satisfied for any value satisfying the non-redundant
60 * rows. The corresponding tab_vars are flagged "is_redundant".
61 * A row variable that is flagged "is_zero" is also flagged "is_redundant"
62 * since the constraint has been reduced to 0 = 0 and is therefore always
63 * satisfied.
65 * Dead columns and redundant rows are detected on the fly.
66 * However, the basic operations do not ensure that all dead columns
67 * or all redundant rows are detected.
68 * isl_tab_detect_equalities and isl_tab_detect_redundant can be used
69 * to peform and exhaustive search for dead columns and redundant rows.
71 struct isl_tab {
72 struct isl_mat *mat;
74 unsigned n_row;
75 unsigned n_col;
76 unsigned n_dead;
77 unsigned n_redundant;
79 unsigned n_var;
80 unsigned n_con;
81 unsigned n_eq;
82 unsigned max_con;
83 struct isl_tab_var *var;
84 struct isl_tab_var *con;
85 int *row_var; /* v >= 0 -> var v; v < 0 -> con ~v */
86 int *col_var; /* v >= 0 -> var v; v < 0 -> con ~v */
88 struct isl_tab_undo bottom;
89 struct isl_tab_undo *top;
91 struct isl_vec *dual;
93 unsigned need_undo : 1;
94 unsigned rational : 1;
95 unsigned empty : 1;
98 struct isl_tab *isl_tab_alloc(struct isl_ctx *ctx,
99 unsigned n_row, unsigned n_var);
100 void isl_tab_free(struct isl_ctx *ctx, struct isl_tab *tab);
102 struct isl_tab *isl_tab_from_basic_map(struct isl_basic_map *bmap);
103 struct isl_tab *isl_tab_from_basic_set(struct isl_basic_set *bset);
104 struct isl_tab *isl_tab_from_recession_cone(struct isl_basic_map *bmap);
105 int isl_tab_cone_is_bounded(struct isl_ctx *ctx, struct isl_tab *tab);
106 struct isl_basic_map *isl_basic_map_update_from_tab(struct isl_basic_map *bmap,
107 struct isl_tab *tab);
108 struct isl_basic_set *isl_basic_set_update_from_tab(struct isl_basic_set *bset,
109 struct isl_tab *tab);
110 struct isl_tab *isl_tab_detect_equalities(struct isl_ctx *ctx,
111 struct isl_tab *tab);
112 struct isl_tab *isl_tab_detect_redundant(struct isl_ctx *ctx,
113 struct isl_tab *tab);
114 #define ISL_TAB_SAVE_DUAL (1 << 0)
115 enum isl_lp_result isl_tab_min(struct isl_ctx *ctx, struct isl_tab *tab,
116 isl_int *f, isl_int denom, isl_int *opt, isl_int *opt_denom,
117 unsigned flags);
119 struct isl_tab *isl_tab_extend(struct isl_ctx *ctx, struct isl_tab *tab,
120 unsigned n_new);
121 struct isl_tab *isl_tab_add_ineq(struct isl_ctx *ctx,
122 struct isl_tab *tab, isl_int *ineq);
123 struct isl_tab *isl_tab_add_valid_eq(struct isl_ctx *ctx,
124 struct isl_tab *tab, isl_int *eq);
126 int isl_tab_is_equality(struct isl_ctx *ctx, struct isl_tab *tab, int con);
127 int isl_tab_is_redundant(struct isl_ctx *ctx, struct isl_tab *tab, int con);
129 struct isl_vec *isl_tab_get_sample_value(struct isl_ctx *ctx,
130 struct isl_tab *tab);
132 enum isl_ineq_type {
133 isl_ineq_error = -1,
134 isl_ineq_redundant,
135 isl_ineq_separate,
136 isl_ineq_cut,
137 isl_ineq_adj_eq,
138 isl_ineq_adj_ineq,
141 enum isl_ineq_type isl_tab_ineq_type(struct isl_ctx *ctx, struct isl_tab *tab,
142 isl_int *ineq);
144 struct isl_tab_undo *isl_tab_snap(struct isl_ctx *ctx, struct isl_tab *tab);
145 int isl_tab_rollback(struct isl_ctx *ctx, struct isl_tab *tab,
146 struct isl_tab_undo *snap);
148 struct isl_tab *isl_tab_relax(struct isl_ctx *ctx,
149 struct isl_tab *tab, int con);
150 struct isl_tab *isl_tab_select_facet(struct isl_ctx *ctx,
151 struct isl_tab *tab, int con);
153 void isl_tab_dump(struct isl_ctx *ctx, struct isl_tab *tab,
154 FILE *out, int indent);
156 #endif