Document TOPCOM based chamber decomposition
[barvinok.git] / param_util.c
blob01ea51a914dafaeb0f26a50c61ea98325ea24809
1 #include <barvinok/options.h>
2 #include "param_util.h"
3 #include "topcom.h"
4 #include "config.h"
6 void Param_Vertex_Common_Denominator(Param_Vertices *V)
8 unsigned dim;
9 Value lcm;
10 int i;
12 assert(V->Vertex->NbRows > 0);
13 dim = V->Vertex->NbColumns-2;
15 value_init(lcm);
17 value_assign(lcm, V->Vertex->p[0][dim+1]);
18 for (i = 1; i < V->Vertex->NbRows; ++i)
19 value_lcm(V->Vertex->p[i][dim+1], lcm, &lcm);
21 for (i = 0; i < V->Vertex->NbRows; ++i) {
22 if (value_eq(V->Vertex->p[i][dim+1], lcm))
23 continue;
24 value_division(V->Vertex->p[i][dim+1], lcm, V->Vertex->p[i][dim+1]);
25 Vector_Scale(V->Vertex->p[i], V->Vertex->p[i],
26 V->Vertex->p[i][dim+1], dim+1);
27 value_assign(V->Vertex->p[i][dim+1], lcm);
30 value_clear(lcm);
33 /* Plug in the parametric vertex Vertex (nvar x (nparam + 2))
34 * in the constraint constraint (1 + nvar + nparam + 1).
35 * The result is stored in row (1 + nparam + 1),
36 * with the denominator in position 0.
38 void Param_Inner_Product(Value *constraint, Matrix *Vertex, Value *row)
40 unsigned nparam = Vertex->NbColumns - 2;
41 unsigned nvar = Vertex->NbRows;
42 int j;
43 Value tmp, tmp2;
45 value_set_si(row[0], 1);
46 Vector_Set(row+1, 0, nparam+1);
48 value_init(tmp);
49 value_init(tmp2);
51 for (j = 0 ; j < nvar; ++j) {
52 value_set_si(tmp, 1);
53 value_assign(tmp2, constraint[1+j]);
54 if (value_ne(row[0], Vertex->p[j][nparam+1])) {
55 value_assign(tmp, row[0]);
56 value_lcm(row[0], Vertex->p[j][nparam+1], &row[0]);
57 value_division(tmp, row[0], tmp);
58 value_multiply(tmp2, tmp2, row[0]);
59 value_division(tmp2, tmp2, Vertex->p[j][nparam+1]);
61 Vector_Combine(row+1, Vertex->p[j], row+1, tmp, tmp2, nparam+1);
63 value_set_si(tmp, 1);
64 Vector_Combine(row+1, constraint+1+nvar, row+1, tmp, row[0], nparam+1);
66 value_clear(tmp);
67 value_clear(tmp2);
70 static Param_Polyhedron *PL_P2PP(Polyhedron *Din, Polyhedron *Cin,
71 struct barvinok_options *options)
73 unsigned MaxRays = options->MaxRays;
74 if (MaxRays & (POL_NO_DUAL | POL_INTEGER))
75 MaxRays = 0;
76 return Polyhedron2Param_Domain(Din, Cin, MaxRays);
80 #ifndef POINTS2TRIANGS_PATH
81 Param_Polyhedron *TC_P2PP(Polyhedron *P, Polyhedron *C,
82 struct barvinok_options *options)
84 return NULL;
86 #endif
88 Param_Polyhedron *Polyhedron2Param_Polyhedron(Polyhedron *P, Polyhedron *C,
89 struct barvinok_options *options)
91 switch(options->chambers) {
92 case BV_CHAMBERS_POLYLIB:
93 return PL_P2PP(P, C, options);
94 break;
95 case BV_CHAMBERS_TOPCOM:
96 return TC_P2PP(P, C, options);
97 break;
98 default:
99 assert(0);