1 #include <barvinok/options.h>
2 #include <barvinok/util.h>
3 #include "reduce_domain.h"
5 Polyhedron
*true_context(Polyhedron
*P
, Polyhedron
*C
, unsigned MaxRays
)
7 unsigned nparam
= C
->Dimension
;
8 Polyhedron
*tmp
= Polyhedron_Project(P
, nparam
);
9 C
= DomainIntersection(tmp
, C
, MaxRays
);
14 Vector
*inner_point(Polyhedron
*P
)
19 unsigned dim
= P
->Dimension
;
22 average
= Vector_Alloc(1+dim
+1);
24 POL_ENSURE_VERTICES(P
);
25 for (i
= 0; i
< P
->NbRays
; ++i
) {
26 if (value_zero_p(P
->Ray
[i
][1+dim
]))
30 Vector_Copy(P
->Ray
[i
]+1, average
->p
+1, dim
+1);
37 value_assign(fc
, average
->p
[1+dim
]);
38 value_lcm(fc
, P
->Ray
[i
][1+dim
], &average
->p
[1+dim
]);
39 value_division(fc
, average
->p
[1+dim
], fc
);
40 value_division(fv
, average
->p
[1+dim
], P
->Ray
[i
][1+dim
]);
41 Vector_Combine(average
->p
+1, P
->Ray
[i
]+1, average
->p
+1, fc
, fv
, dim
);
45 value_multiply(average
->p
[1+dim
], average
->p
[1+dim
], fc
);
46 Vector_Normalize(average
->p
+1, dim
+1);
50 for (i
= 0; i
< P
->NbRays
; ++i
) {
51 if (value_notzero_p(P
->Ray
[i
][1+dim
]))
53 Vector_Add(average
->p
+1, P
->Ray
[i
]+1, average
->p
+1, dim
);
58 int is_internal(Vector
*point
, Value
*constraint
)
61 unsigned dim
= point
->Size
-2;
63 Inner_Product(constraint
+1, point
->p
+1, dim
+1, &point
->p
[0]);
64 if (value_notzero_p(point
->p
[0]))
65 return value_pos_p(point
->p
[0]);
67 p
= First_Non_Zero(constraint
+1, dim
);
68 return value_pos_p(constraint
[1+p
]);
71 Polyhedron
*reduce_domain(Polyhedron
*D
, int nd
,
72 Vector
*inner
, struct barvinok_options
*options
)
80 rVD
= D
->next
? DomainConvex(D
, options
->MaxRays
) : Polyhedron_Copy(D
);
82 /* If there is only one chamber, then we don't need to take care
83 * of possible overlaps.
84 * Plus, this decomposition may be the result of a recursive call
85 * and then some of the assumptions used in determining whether
86 * the domain is too small in geometric dimension no longer apply.
92 assert(rVD
->Dimension
== inner
->Size
-2);
93 constraints
= Polyhedron2Constraints(rVD
);
95 for (i
= 0; i
< constraints
->NbRows
; ++i
) {
96 if (!is_internal(inner
, constraints
->p
[i
])) {
97 value_decrement(constraints
->p
[i
][1+rVD
->Dimension
],
98 constraints
->p
[i
][1+rVD
->Dimension
]);
103 Polyhedron_Free(rVD
);
104 rVD
= Constraints2Polyhedron(constraints
, options
->MaxRays
);
106 Matrix_Free(constraints
);
108 rVD
= DomainConstraintSimplify(rVD
, options
->MaxRays
);
109 POL_ENSURE_FACETS(rVD
);
116 barvinok_count_with_options(rVD
, &c
, options
);
117 if (value_zero_p(c
)) {