2 #include <barvinok/options.h>
3 #include <barvinok/util.h>
4 #include <barvinok/barvinok.h>
5 #include "reduce_domain.h"
7 Polyhedron
*true_context(Polyhedron
*P
, Polyhedron
*C
, unsigned MaxRays
)
9 unsigned nparam
= C
->Dimension
;
10 Polyhedron
*tmp
= Polyhedron_Project(P
, nparam
);
11 C
= DomainIntersection(tmp
, C
, MaxRays
);
16 Vector
*inner_point(Polyhedron
*P
)
21 unsigned dim
= P
->Dimension
;
24 average
= Vector_Alloc(1+dim
+1);
26 POL_ENSURE_VERTICES(P
);
27 for (i
= 0; i
< P
->NbRays
; ++i
) {
28 if (value_zero_p(P
->Ray
[i
][1+dim
]))
32 Vector_Copy(P
->Ray
[i
]+1, average
->p
+1, dim
+1);
39 value_assign(fc
, average
->p
[1+dim
]);
40 value_lcm(average
->p
[1+dim
], fc
, P
->Ray
[i
][1+dim
]);
41 value_division(fc
, average
->p
[1+dim
], fc
);
42 value_division(fv
, average
->p
[1+dim
], P
->Ray
[i
][1+dim
]);
43 Vector_Combine(average
->p
+1, P
->Ray
[i
]+1, average
->p
+1, fc
, fv
, dim
);
47 value_multiply(average
->p
[1+dim
], average
->p
[1+dim
], fc
);
48 Vector_Normalize(average
->p
+1, dim
+1);
52 for (i
= 0; i
< P
->NbRays
; ++i
) {
53 if (value_notzero_p(P
->Ray
[i
][1+dim
]))
55 Vector_Add(average
->p
+1, P
->Ray
[i
]+1, average
->p
+1, dim
);
60 int is_internal(Vector
*point
, Value
*constraint
)
63 unsigned dim
= point
->Size
-2;
65 Inner_Product(constraint
+1, point
->p
+1, dim
+1, &point
->p
[0]);
66 if (value_notzero_p(point
->p
[0]))
67 return value_pos_p(point
->p
[0]);
69 p
= First_Non_Zero(constraint
+1, dim
);
70 return value_pos_p(constraint
[1+p
]);
73 Polyhedron
*reduce_domain(Polyhedron
*D
, int nd
,
74 Vector
*inner
, struct barvinok_options
*options
)
82 rVD
= D
->next
? DomainConvex(D
, options
->MaxRays
) : Polyhedron_Copy(D
);
84 /* If there is only one chamber, then we don't need to take care
85 * of possible overlaps.
86 * Plus, this decomposition may be the result of a recursive call
87 * and then some of the assumptions used in determining whether
88 * the domain is too small in geometric dimension no longer apply.
94 assert(rVD
->Dimension
== inner
->Size
-2);
95 constraints
= Polyhedron2Constraints(rVD
);
97 for (i
= 0; i
< constraints
->NbRows
; ++i
) {
98 if (!is_internal(inner
, constraints
->p
[i
])) {
99 value_decrement(constraints
->p
[i
][1+rVD
->Dimension
],
100 constraints
->p
[i
][1+rVD
->Dimension
]);
105 Polyhedron_Free(rVD
);
106 rVD
= Constraints2Polyhedron(constraints
, options
->MaxRays
);
108 Matrix_Free(constraints
);
110 rVD
= DomainConstraintSimplify(rVD
, options
->MaxRays
);
111 POL_ENSURE_FACETS(rVD
);
118 barvinok_count_with_options(rVD
, &c
, options
);
119 if (value_zero_p(c
)) {