evalue.c: Polyhedron_Insert: add missing return type
[barvinok.git] / vector_partition_chambers.c
blobf55bcd983f58a73db63c121e98a0468bfd6e3e9a
1 #include <barvinok/options.h>
2 #include "argp.h"
3 #include "progname.h"
4 #include "param_util.h"
6 /* This program computes the full-dimensional chambers of the vector
7 * partition function
9 * A \lambda = u
11 * The input is the matrix A in PolyLib notation.
12 * The output consists of the number of chambers, followed by
13 * a constraint description of each chamber in PolyLib notation.
15 * Example run:
17 * $ cat elke
18 * 2 4
20 * 1 1 1 1
21 * 0 1 2 3
23 * $ ./vector_partition_chambers < elke
24 * 3
26 * 3 4
27 * 1 1 -1 0
28 * 1 0 1 0
29 * 1 0 0 1
31 * 3 4
32 * 1 -1 1 0
33 * 1 2 -1 0
34 * 1 0 0 1
36 * 3 4
37 * 1 3 -1 0
38 * 1 -2 1 0
39 * 1 0 0 1
42 static Polyhedron *partition2polyhedron(Matrix *A,
43 struct barvinok_options *options)
45 int i;
46 unsigned nvar, nparam;
47 Matrix *M;
48 Polyhedron *P;
50 nvar = A->NbColumns;
51 nparam = A->NbRows;
53 M = Matrix_Alloc(nvar + nparam, 1 + nvar + nparam + 1);
54 assert(M);
56 for (i = 0; i < nparam; ++i) {
57 Vector_Copy(A->p[i], M->p[i] + 1, nvar);
58 value_set_si(M->p[i][1 + nvar + i], -1);
60 for (i = 0; i < nvar; ++i) {
61 value_set_si(M->p[nparam + i][0], 1);
62 value_set_si(M->p[nparam + i][1 + i], 1);
65 P = Constraints2Polyhedron(M, options->MaxRays);
66 Matrix_Free(M);
68 return P;
71 int main(int argc, char **argv)
73 int nchamber;
74 unsigned nparam;
75 Matrix *A;
76 Polyhedron *P, *C;
77 Param_Polyhedron *PP;
78 Param_Domain *PD;
79 struct barvinok_options *options = barvinok_options_new_with_defaults();
81 set_program_name(argv[0]);
82 argp_parse(&barvinok_argp, argc, argv, 0, 0, options);
84 A = Matrix_Read();
85 assert(A);
87 nparam = A->NbRows;
88 C = Universe_Polyhedron(nparam);
89 P = partition2polyhedron(A, options);
90 Matrix_Free(A);
92 PP = Polyhedron2Param_Polyhedron(P, C, options);
93 Polyhedron_Free(P);
94 Polyhedron_Free(C);
96 nchamber = 0;
97 for (PD = PP->D; PD; PD = PD->next)
98 nchamber++;
100 printf("%d\n", nchamber);
101 for (PD = PP->D; PD; PD = PD->next) {
102 printf("\n");
103 Polyhedron_PrintConstraints(stdout, P_VALUE_FMT, PD->Domain);
105 Param_Polyhedron_Free(PP);
107 barvinok_options_free(options);
108 return 0;