document isl_union_set_apply_union_pw_qpolynomial
[barvinok.git] / vector_partition_chambers.c
blob8b9957bdb459c9bfd34c689413b5359fafde633d
1 #include <barvinok/options.h>
2 #include "param_util.h"
4 /* This program computes the full-dimensional chambers of the vector
5 * partition function
7 * A \lambda = u
9 * The input is the matrix A in PolyLib notation.
10 * The output consists of the number of chambers, followed by
11 * a constraint description of each chamber in PolyLib notation.
13 * Example run:
15 * $ cat elke
16 * 2 4
18 * 1 1 1 1
19 * 0 1 2 3
21 * $ ./vector_partition_chambers < elke
22 * 3
24 * 3 4
25 * 1 1 -1 0
26 * 1 0 1 0
27 * 1 0 0 1
29 * 3 4
30 * 1 -1 1 0
31 * 1 2 -1 0
32 * 1 0 0 1
34 * 3 4
35 * 1 3 -1 0
36 * 1 -2 1 0
37 * 1 0 0 1
40 static Polyhedron *partition2polyhedron(Matrix *A,
41 struct barvinok_options *options)
43 int i;
44 unsigned nvar, nparam;
45 Matrix *M;
46 Polyhedron *P;
48 nvar = A->NbColumns;
49 nparam = A->NbRows;
51 M = Matrix_Alloc(nvar + nparam, 1 + nvar + nparam + 1);
52 assert(M);
54 for (i = 0; i < nparam; ++i) {
55 Vector_Copy(A->p[i], M->p[i] + 1, nvar);
56 value_set_si(M->p[i][1 + nvar + i], -1);
58 for (i = 0; i < nvar; ++i) {
59 value_set_si(M->p[nparam + i][0], 1);
60 value_set_si(M->p[nparam + i][1 + i], 1);
63 P = Constraints2Polyhedron(M, options->MaxRays);
64 Matrix_Free(M);
66 return P;
69 int main(int argc, char **argv)
71 int nchamber;
72 unsigned nparam;
73 Matrix *A;
74 Polyhedron *P, *C;
75 Param_Polyhedron *PP;
76 Param_Domain *PD;
77 struct barvinok_options *options = barvinok_options_new_with_defaults();
79 argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL);
81 A = Matrix_Read();
82 assert(A);
84 nparam = A->NbRows;
85 C = Universe_Polyhedron(nparam);
86 P = partition2polyhedron(A, options);
87 Matrix_Free(A);
89 PP = Polyhedron2Param_Polyhedron(P, C, options);
90 Polyhedron_Free(P);
91 Polyhedron_Free(C);
93 nchamber = 0;
94 for (PD = PP->D; PD; PD = PD->next)
95 nchamber++;
97 printf("%d\n", nchamber);
98 for (PD = PP->D; PD; PD = PD->next) {
99 printf("\n");
100 Polyhedron_PrintConstraints(stdout, P_VALUE_FMT, PD->Domain);
102 Param_Polyhedron_Free(PP);
104 barvinok_options_free(options);
105 return 0;