3 #include <barvinok/util.h>
4 #include <barvinok/options.h>
7 #ifndef HAVE_ENUMERATE4
8 #define Polyhedron_Enumerate(a,b,c,d) Polyhedron_Enumerate(a,b,c)
11 #define ALLOC(type) (type*)malloc(sizeof(type))
12 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
15 #define NALLOC(p,n) p = (typeof(p))malloc((n) * sizeof(*p))
17 #define NALLOC(p,n) p = (void *)malloc((n) * sizeof(*p))
20 #ifndef HAVE_ENUMERATION_FREE
21 #define Enumeration_Free(en) /* just leak some memory */
24 void manual_count(Polyhedron
*P
, Value
* result
)
26 Polyhedron
*U
= Universe_Polyhedron(0);
27 Enumeration
*en
= Polyhedron_Enumerate(P
,U
,1024,NULL
);
28 Value
*v
= compute_poly(en
,NULL
);
29 value_assign(*result
, *v
);
36 #ifndef HAVE_ENUMERATION_FREE
37 #undef Enumeration_Free
40 #include <barvinok/evalue.h>
41 #include <barvinok/util.h>
42 #include <barvinok/barvinok.h>
44 /* Return random value between 0 and max-1 inclusive
46 int random_int(int max
) {
47 return (int) (((double)(max
))*rand()/(RAND_MAX
+1.0));
50 Polyhedron
*Polyhedron_Read(unsigned MaxRays
)
53 unsigned NbRows
, NbColumns
;
58 while (fgets(s
, sizeof(s
), stdin
)) {
61 if (strncasecmp(s
, "vertices", sizeof("vertices")-1) == 0)
63 if (sscanf(s
, "%u %u", &NbRows
, &NbColumns
) == 2)
68 M
= Matrix_Alloc(NbRows
,NbColumns
);
71 P
= Rays2Polyhedron(M
, MaxRays
);
73 P
= Constraints2Polyhedron(M
, MaxRays
);
78 /* Inplace polarization
80 void Polyhedron_Polarize(Polyhedron
*P
)
82 unsigned NbRows
= P
->NbConstraints
+ P
->NbRays
;
86 q
= (Value
**)malloc(NbRows
* sizeof(Value
*));
88 for (i
= 0; i
< P
->NbRays
; ++i
)
90 for (; i
< NbRows
; ++i
)
91 q
[i
] = P
->Constraint
[i
-P
->NbRays
];
92 P
->NbConstraints
= NbRows
- P
->NbConstraints
;
93 P
->NbRays
= NbRows
- P
->NbRays
;
96 P
->Ray
= q
+ P
->NbConstraints
;
100 * Rather general polar
101 * We can optimize it significantly if we assume that
104 * Also, we calculate the polar as defined in Schrijver
105 * The opposite should probably work as well and would
106 * eliminate the need for multiplying by -1
108 Polyhedron
* Polyhedron_Polar(Polyhedron
*P
, unsigned NbMaxRays
)
112 unsigned dim
= P
->Dimension
+ 2;
113 Matrix
*M
= Matrix_Alloc(P
->NbRays
, dim
);
117 value_set_si(mone
, -1);
118 for (i
= 0; i
< P
->NbRays
; ++i
) {
119 Vector_Scale(P
->Ray
[i
], M
->p
[i
], mone
, dim
);
120 value_multiply(M
->p
[i
][0], M
->p
[i
][0], mone
);
121 value_multiply(M
->p
[i
][dim
-1], M
->p
[i
][dim
-1], mone
);
123 P
= Constraints2Polyhedron(M
, NbMaxRays
);
131 * Returns the supporting cone of P at the vertex with index v
133 Polyhedron
* supporting_cone(Polyhedron
*P
, int v
)
138 unsigned char *supporting
= (unsigned char *)malloc(P
->NbConstraints
);
139 unsigned dim
= P
->Dimension
+ 2;
141 assert(v
>=0 && v
< P
->NbRays
);
142 assert(value_pos_p(P
->Ray
[v
][dim
-1]));
146 for (i
= 0, n
= 0; i
< P
->NbConstraints
; ++i
) {
147 Inner_Product(P
->Constraint
[i
] + 1, P
->Ray
[v
] + 1, dim
- 1, &tmp
);
148 if ((supporting
[i
] = value_zero_p(tmp
)))
151 assert(n
>= dim
- 2);
153 M
= Matrix_Alloc(n
, dim
);
155 for (i
= 0, j
= 0; i
< P
->NbConstraints
; ++i
)
157 value_set_si(M
->p
[j
][dim
-1], 0);
158 Vector_Copy(P
->Constraint
[i
], M
->p
[j
++], dim
-1);
161 P
= Constraints2Polyhedron(M
, P
->NbRays
+1);
167 void value_lcm(const Value i
, const Value j
, Value
* lcm
)
171 value_multiply(aux
,i
,j
);
173 value_division(*lcm
,aux
,*lcm
);
177 Polyhedron
* supporting_cone_p(Polyhedron
*P
, Param_Vertices
*v
)
180 Value lcm
, tmp
, tmp2
;
181 unsigned char *supporting
= (unsigned char *)malloc(P
->NbConstraints
);
182 unsigned dim
= P
->Dimension
+ 2;
183 unsigned nparam
= v
->Vertex
->NbColumns
- 2;
184 unsigned nvar
= dim
- nparam
- 2;
189 row
= Vector_Alloc(nparam
+1);
194 value_set_si(lcm
, 1);
195 for (i
= 0, n
= 0; i
< P
->NbConstraints
; ++i
) {
196 Vector_Set(row
->p
, 0, nparam
+1);
197 for (j
= 0 ; j
< nvar
; ++j
) {
198 value_set_si(tmp
, 1);
199 value_assign(tmp2
, P
->Constraint
[i
][j
+1]);
200 if (value_ne(lcm
, v
->Vertex
->p
[j
][nparam
+1])) {
201 value_assign(tmp
, lcm
);
202 value_lcm(lcm
, v
->Vertex
->p
[j
][nparam
+1], &lcm
);
203 value_division(tmp
, lcm
, tmp
);
204 value_multiply(tmp2
, tmp2
, lcm
);
205 value_division(tmp2
, tmp2
, v
->Vertex
->p
[j
][nparam
+1]);
207 Vector_Combine(row
->p
, v
->Vertex
->p
[j
], row
->p
,
208 tmp
, tmp2
, nparam
+1);
210 value_set_si(tmp
, 1);
211 Vector_Combine(row
->p
, P
->Constraint
[i
]+1+nvar
, row
->p
, tmp
, lcm
, nparam
+1);
212 for (j
= 0; j
< nparam
+1; ++j
)
213 if (value_notzero_p(row
->p
[j
]))
215 if ((supporting
[i
] = (j
== nparam
+ 1)))
223 M
= Matrix_Alloc(n
, nvar
+2);
225 for (i
= 0, j
= 0; i
< P
->NbConstraints
; ++i
)
227 value_set_si(M
->p
[j
][nvar
+1], 0);
228 Vector_Copy(P
->Constraint
[i
], M
->p
[j
++], nvar
+1);
231 P
= Constraints2Polyhedron(M
, P
->NbRays
+1);
237 Polyhedron
* triangulate_cone(Polyhedron
*P
, unsigned NbMaxCons
)
239 const static int MAX_TRY
=10;
242 unsigned dim
= P
->Dimension
;
243 Matrix
*M
= Matrix_Alloc(P
->NbRays
+1, dim
+3);
245 Polyhedron
*L
, *R
, *T
;
246 assert(P
->NbEq
== 0);
251 Vector_Set(M
->p
[0]+1, 0, dim
+1);
252 value_set_si(M
->p
[0][0], 1);
253 value_set_si(M
->p
[0][dim
+2], 1);
254 Vector_Set(M
->p
[P
->NbRays
]+1, 0, dim
+2);
255 value_set_si(M
->p
[P
->NbRays
][0], 1);
256 value_set_si(M
->p
[P
->NbRays
][dim
+1], 1);
258 /* Delaunay triangulation */
259 for (i
= 0, r
= 1; i
< P
->NbRays
; ++i
) {
260 if (value_notzero_p(P
->Ray
[i
][dim
+1]))
262 Vector_Copy(P
->Ray
[i
], M
->p
[r
], dim
+1);
263 Inner_Product(M
->p
[r
]+1, M
->p
[r
]+1, dim
, &tmp
);
264 value_assign(M
->p
[r
][dim
+1], tmp
);
265 value_set_si(M
->p
[r
][dim
+2], 0);
270 L
= Rays2Polyhedron(M3
, NbMaxCons
);
273 M2
= Matrix_Alloc(dim
+1, dim
+2);
278 /* Usually R should still be 0 */
281 for (r
= 1; r
< P
->NbRays
; ++r
) {
282 value_set_si(M
->p
[r
][dim
+1], random_int((t
+1)*dim
*P
->NbRays
)+1);
285 L
= Rays2Polyhedron(M3
, NbMaxCons
);
289 assert(t
<= MAX_TRY
);
294 for (i
= 0; i
< L
->NbConstraints
; ++i
) {
295 /* Ignore perpendicular facets, i.e., facets with 0 z-coordinate */
296 if (value_negz_p(L
->Constraint
[i
][dim
+1]))
298 if (value_notzero_p(L
->Constraint
[i
][dim
+2]))
300 for (j
= 1, r
= 1; j
< M
->NbRows
; ++j
) {
301 Inner_Product(M
->p
[j
]+1, L
->Constraint
[i
]+1, dim
+1, &tmp
);
302 if (value_notzero_p(tmp
))
306 Vector_Copy(M
->p
[j
]+1, M2
->p
[r
]+1, dim
);
307 value_set_si(M2
->p
[r
][0], 1);
308 value_set_si(M2
->p
[r
][dim
+1], 0);
312 Vector_Set(M2
->p
[0]+1, 0, dim
);
313 value_set_si(M2
->p
[0][0], 1);
314 value_set_si(M2
->p
[0][dim
+1], 1);
315 T
= Rays2Polyhedron(M2
, P
->NbConstraints
+1);
329 void check_triangulization(Polyhedron
*P
, Polyhedron
*T
)
331 Polyhedron
*C
, *D
, *E
, *F
, *G
, *U
;
332 for (C
= T
; C
; C
= C
->next
) {
336 U
= DomainConvex(DomainUnion(U
, C
, 100), 100);
337 for (D
= C
->next
; D
; D
= D
->next
) {
342 E
= DomainIntersection(C
, D
, 600);
343 assert(E
->NbRays
== 0 || E
->NbEq
>= 1);
349 assert(PolyhedronIncludes(U
, P
));
350 assert(PolyhedronIncludes(P
, U
));
353 /* Computes x, y and g such that g = gcd(a,b) and a*x+b*y = g */
354 void Extended_Euclid(Value a
, Value b
, Value
*x
, Value
*y
, Value
*g
)
356 Value c
, d
, e
, f
, tmp
;
363 value_absolute(c
, a
);
364 value_absolute(d
, b
);
367 while(value_pos_p(d
)) {
368 value_division(tmp
, c
, d
);
369 value_multiply(tmp
, tmp
, f
);
370 value_subtract(e
, e
, tmp
);
371 value_division(tmp
, c
, d
);
372 value_multiply(tmp
, tmp
, d
);
373 value_subtract(c
, c
, tmp
);
380 else if (value_pos_p(a
))
382 else value_oppose(*x
, e
);
386 value_multiply(tmp
, a
, *x
);
387 value_subtract(tmp
, c
, tmp
);
388 value_division(*y
, tmp
, b
);
397 Matrix
* unimodular_complete(Vector
*row
)
399 Value g
, b
, c
, old
, tmp
;
408 m
= Matrix_Alloc(row
->Size
, row
->Size
);
409 for (j
= 0; j
< row
->Size
; ++j
) {
410 value_assign(m
->p
[0][j
], row
->p
[j
]);
412 value_assign(g
, row
->p
[0]);
413 for (i
= 1; value_zero_p(g
) && i
< row
->Size
; ++i
) {
414 for (j
= 0; j
< row
->Size
; ++j
) {
416 value_set_si(m
->p
[i
][j
], 1);
418 value_set_si(m
->p
[i
][j
], 0);
420 value_assign(g
, row
->p
[i
]);
422 for (; i
< row
->Size
; ++i
) {
423 value_assign(old
, g
);
424 Extended_Euclid(old
, row
->p
[i
], &c
, &b
, &g
);
426 for (j
= 0; j
< row
->Size
; ++j
) {
428 value_multiply(tmp
, row
->p
[j
], b
);
429 value_division(m
->p
[i
][j
], tmp
, old
);
431 value_assign(m
->p
[i
][j
], c
);
433 value_set_si(m
->p
[i
][j
], 0);
445 * Returns a full-dimensional polyhedron with the same number
446 * of integer points as P
448 Polyhedron
*remove_equalities(Polyhedron
*P
)
452 Polyhedron
*p
= Polyhedron_Copy(P
), *q
;
453 unsigned dim
= p
->Dimension
;
458 while (!emptyQ2(p
) && p
->NbEq
> 0) {
460 Vector_Gcd(p
->Constraint
[0]+1, dim
+1, &g
);
461 Vector_AntiScale(p
->Constraint
[0]+1, p
->Constraint
[0]+1, g
, dim
+1);
462 Vector_Gcd(p
->Constraint
[0]+1, dim
, &g
);
463 if (value_notone_p(g
) && value_notmone_p(g
)) {
465 p
= Empty_Polyhedron(0);
468 v
= Vector_Alloc(dim
);
469 Vector_Copy(p
->Constraint
[0]+1, v
->p
, dim
);
470 m1
= unimodular_complete(v
);
471 m2
= Matrix_Alloc(dim
, dim
+1);
472 for (i
= 0; i
< dim
-1 ; ++i
) {
473 Vector_Copy(m1
->p
[i
+1], m2
->p
[i
], dim
);
474 value_set_si(m2
->p
[i
][dim
], 0);
476 Vector_Set(m2
->p
[dim
-1], 0, dim
);
477 value_set_si(m2
->p
[dim
-1][dim
], 1);
478 q
= Polyhedron_Image(p
, m2
, p
->NbConstraints
+1+p
->NbRays
);
491 * Returns a full-dimensional polyhedron with the same number
492 * of integer points as P
493 * nvar specifies the number of variables
494 * The remaining dimensions are assumed to be parameters
496 * factor is NbEq x (nparam+2) matrix, containing stride constraints
497 * on the parameters; column nparam is the constant;
498 * column nparam+1 is the stride
500 * if factor is NULL, only remove equalities that don't affect
501 * the number of points
503 Polyhedron
*remove_equalities_p(Polyhedron
*P
, unsigned nvar
, Matrix
**factor
)
507 Polyhedron
*p
= P
, *q
;
508 unsigned dim
= p
->Dimension
;
514 f
= Matrix_Alloc(p
->NbEq
, dim
-nvar
+2);
519 while (nvar
> 0 && p
->NbEq
- skip
> 0) {
522 while (skip
< p
->NbEq
&&
523 First_Non_Zero(p
->Constraint
[skip
]+1, nvar
) == -1)
528 Vector_Gcd(p
->Constraint
[skip
]+1, dim
+1, &g
);
529 Vector_AntiScale(p
->Constraint
[skip
]+1, p
->Constraint
[skip
]+1, g
, dim
+1);
530 Vector_Gcd(p
->Constraint
[skip
]+1, nvar
, &g
);
531 if (!factor
&& value_notone_p(g
) && value_notmone_p(g
)) {
536 Vector_Copy(p
->Constraint
[skip
]+1+nvar
, f
->p
[j
], dim
-nvar
+1);
537 value_assign(f
->p
[j
][dim
-nvar
+1], g
);
539 v
= Vector_Alloc(dim
);
540 Vector_AntiScale(p
->Constraint
[skip
]+1, v
->p
, g
, nvar
);
541 Vector_Set(v
->p
+nvar
, 0, dim
-nvar
);
542 m1
= unimodular_complete(v
);
543 m2
= Matrix_Alloc(dim
, dim
+1);
544 for (i
= 0; i
< dim
-1 ; ++i
) {
545 Vector_Copy(m1
->p
[i
+1], m2
->p
[i
], dim
);
546 value_set_si(m2
->p
[i
][dim
], 0);
548 Vector_Set(m2
->p
[dim
-1], 0, dim
);
549 value_set_si(m2
->p
[dim
-1][dim
], 1);
550 q
= Polyhedron_Image(p
, m2
, p
->NbConstraints
+1+p
->NbRays
);
564 void Line_Length(Polyhedron
*P
, Value
*len
)
570 assert(P
->Dimension
== 1);
576 for (i
= 0; i
< P
->NbConstraints
; ++i
) {
577 value_oppose(tmp
, P
->Constraint
[i
][2]);
578 if (value_pos_p(P
->Constraint
[i
][1])) {
579 mpz_cdiv_q(tmp
, tmp
, P
->Constraint
[i
][1]);
580 if (!p
|| value_gt(tmp
, pos
))
581 value_assign(pos
, tmp
);
584 mpz_fdiv_q(tmp
, tmp
, P
->Constraint
[i
][1]);
585 if (!n
|| value_lt(tmp
, neg
))
586 value_assign(neg
, tmp
);
590 value_subtract(tmp
, neg
, pos
);
591 value_increment(*len
, tmp
);
593 value_set_si(*len
, -1);
602 * Factors the polyhedron P into polyhedra Q_i such that
603 * the number of integer points in P is equal to the product
604 * of the number of integer points in the individual Q_i
606 * If no factors can be found, NULL is returned.
607 * Otherwise, a linked list of the factors is returned.
609 * If there are factors and if T is not NULL, then a matrix will be
610 * returned through T expressing the old variables in terms of the
611 * new variables as they appear in the sequence of factors.
613 * The algorithm works by first computing the Hermite normal form
614 * and then grouping columns linked by one or more constraints together,
615 * where a constraints "links" two or more columns if the constraint
616 * has nonzero coefficients in the columns.
618 Polyhedron
* Polyhedron_Factor(Polyhedron
*P
, unsigned nparam
, Matrix
**T
,
622 Matrix
*M
, *H
, *Q
, *U
;
623 int *pos
; /* for each column: row position of pivot */
624 int *group
; /* group to which a column belongs */
625 int *cnt
; /* number of columns in the group */
626 int *rowgroup
; /* group to which a constraint belongs */
627 int nvar
= P
->Dimension
- nparam
;
628 Polyhedron
*F
= NULL
;
636 NALLOC(rowgroup
, P
->NbConstraints
);
638 M
= Matrix_Alloc(P
->NbConstraints
, nvar
);
639 for (i
= 0; i
< P
->NbConstraints
; ++i
)
640 Vector_Copy(P
->Constraint
[i
]+1, M
->p
[i
], nvar
);
641 left_hermite(M
, &H
, &Q
, &U
);
645 for (i
= 0; i
< P
->NbConstraints
; ++i
)
647 for (i
= 0, j
= 0; i
< H
->NbColumns
; ++i
) {
648 for ( ; j
< H
->NbRows
; ++j
)
649 if (value_notzero_p(H
->p
[j
][i
]))
651 assert (j
< H
->NbRows
);
654 for (i
= 0; i
< nvar
; ++i
) {
658 for (i
= 0; i
< H
->NbColumns
&& cnt
[0] < nvar
; ++i
) {
659 if (rowgroup
[pos
[i
]] == -1)
660 rowgroup
[pos
[i
]] = i
;
661 for (j
= pos
[i
]+1; j
< H
->NbRows
; ++j
) {
662 if (value_zero_p(H
->p
[j
][i
]))
664 if (rowgroup
[j
] != -1)
666 rowgroup
[j
] = group
[i
];
667 for (k
= i
+1; k
< H
->NbColumns
&& j
>= pos
[k
]; ++k
) {
672 if (group
[k
] != group
[i
] && value_notzero_p(H
->p
[j
][k
])) {
673 assert(cnt
[group
[k
]] != 0);
674 assert(cnt
[group
[i
]] != 0);
675 if (group
[i
] < group
[k
]) {
676 cnt
[group
[i
]] += cnt
[group
[k
]];
680 cnt
[group
[k
]] += cnt
[group
[i
]];
689 if (cnt
[0] != nvar
) {
690 /* Extract out pure context constraints separately */
691 Polyhedron
**next
= &F
;
694 *T
= Matrix_Alloc(nvar
, nvar
);
695 for (i
= nparam
? -1 : 0; i
< nvar
; ++i
) {
699 for (j
= 0, k
= 0; j
< P
->NbConstraints
; ++j
)
700 if (rowgroup
[j
] == -1) {
701 if (First_Non_Zero(P
->Constraint
[j
]+1+nvar
,
714 for (j
= 0, k
= 0; j
< P
->NbConstraints
; ++j
)
715 if (rowgroup
[j
] >= 0 && group
[rowgroup
[j
]] == i
) {
722 for (j
= 0; j
< nvar
; ++j
) {
724 for (l
= 0, m
= 0; m
< d
; ++l
) {
727 value_assign((*T
)->p
[j
][tot_d
+m
++], U
->p
[j
][l
]);
731 M
= Matrix_Alloc(k
, d
+nparam
+2);
732 for (j
= 0, k
= 0; j
< P
->NbConstraints
; ++j
) {
734 if (rowgroup
[j
] != i
)
736 value_assign(M
->p
[k
][0], P
->Constraint
[j
][0]);
737 for (l
= 0, m
= 0; m
< d
; ++l
) {
740 value_assign(M
->p
[k
][1+m
++], H
->p
[j
][l
]);
742 Vector_Copy(P
->Constraint
[j
]+1+nvar
, M
->p
[k
]+1+m
, nparam
+1);
745 *next
= Constraints2Polyhedron(M
, NbMaxRays
);
746 next
= &(*next
)->next
;
761 * Project on final dim dimensions
763 Polyhedron
* Polyhedron_Project(Polyhedron
*P
, int dim
)
766 int remove
= P
->Dimension
- dim
;
770 if (P
->Dimension
== dim
)
771 return Polyhedron_Copy(P
);
773 T
= Matrix_Alloc(dim
+1, P
->Dimension
+1);
774 for (i
= 0; i
< dim
+1; ++i
)
775 value_set_si(T
->p
[i
][i
+remove
], 1);
776 I
= Polyhedron_Image(P
, T
, P
->NbConstraints
);
781 /* Constructs a new constraint that ensures that
782 * the first constraint is (strictly) smaller than
785 static void smaller_constraint(Value
*a
, Value
*b
, Value
*c
, int pos
, int shift
,
786 int len
, int strict
, Value
*tmp
)
788 value_oppose(*tmp
, b
[pos
+1]);
789 value_set_si(c
[0], 1);
790 Vector_Combine(a
+1+shift
, b
+1+shift
, c
+1, *tmp
, a
[pos
+1], len
-shift
-1);
792 value_decrement(c
[len
-shift
-1], c
[len
-shift
-1]);
793 ConstraintSimplify(c
, c
, len
-shift
, tmp
);
796 struct section
{ Polyhedron
* D
; evalue E
; };
798 evalue
* ParamLine_Length_mod(Polyhedron
*P
, Polyhedron
*C
, int MaxRays
)
800 unsigned dim
= P
->Dimension
;
801 unsigned nvar
= dim
- C
->Dimension
;
816 NALLOC(pos
, P
->NbConstraints
);
819 evalue_set_si(&mone
, -1, 1);
821 for (i
= 0, z
= 0; i
< P
->NbConstraints
; ++i
)
822 if (value_zero_p(P
->Constraint
[i
][1]))
824 /* put those with positive coefficients first; number: p */
825 for (i
= 0, p
= 0, n
= P
->NbConstraints
-z
-1; i
< P
->NbConstraints
; ++i
)
826 if (value_pos_p(P
->Constraint
[i
][1]))
828 else if (value_neg_p(P
->Constraint
[i
][1]))
830 n
= P
->NbConstraints
-z
-p
;
831 assert (p
>= 1 && n
>= 1);
832 s
= (struct section
*) malloc(p
* n
* sizeof(struct section
));
833 M
= Matrix_Alloc((p
-1) + (n
-1), dim
-nvar
+2);
834 for (k
= 0; k
< p
; ++k
) {
835 for (k2
= 0; k2
< p
; ++k2
) {
840 P
->Constraint
[pos
[k
]],
841 P
->Constraint
[pos
[k2
]],
842 M
->p
[q
], 0, nvar
, dim
+2, k2
> k
, &g
);
844 for (l
= p
; l
< p
+n
; ++l
) {
845 for (l2
= p
; l2
< p
+n
; ++l2
) {
850 P
->Constraint
[pos
[l2
]],
851 P
->Constraint
[pos
[l
]],
852 M
->p
[q
], 0, nvar
, dim
+2, l2
> l
, &g
);
855 T
= Constraints2Polyhedron(M2
, P
->NbRays
);
857 s
[nd
].D
= DomainIntersection(T
, C
, MaxRays
);
859 POL_ENSURE_VERTICES(s
[nd
].D
);
860 if (emptyQ(s
[nd
].D
)) {
861 Polyhedron_Free(s
[nd
].D
);
864 L
= bv_ceil3(P
->Constraint
[pos
[k
]]+1+nvar
,
866 P
->Constraint
[pos
[k
]][0+1], s
[nd
].D
);
867 U
= bv_ceil3(P
->Constraint
[pos
[l
]]+1+nvar
,
869 P
->Constraint
[pos
[l
]][0+1], s
[nd
].D
);
885 value_set_si(F
->d
, 0);
886 F
->x
.p
= new_enode(partition
, 2*nd
, dim
-nvar
);
887 for (k
= 0; k
< nd
; ++k
) {
888 EVALUE_SET_DOMAIN(F
->x
.p
->arr
[2*k
], s
[k
].D
);
889 value_clear(F
->x
.p
->arr
[2*k
+1].d
);
890 F
->x
.p
->arr
[2*k
+1] = s
[k
].E
;
894 free_evalue_refs(&mone
);
901 evalue
* ParamLine_Length(Polyhedron
*P
, Polyhedron
*C
,
902 struct barvinok_options
*options
)
905 tmp
= ParamLine_Length_mod(P
, C
, options
->MaxRays
);
906 if (options
->lookup_table
) {
907 evalue_mod2table(tmp
, C
->Dimension
);
913 Bool
isIdentity(Matrix
*M
)
916 if (M
->NbRows
!= M
->NbColumns
)
919 for (i
= 0;i
< M
->NbRows
; i
++)
920 for (j
= 0; j
< M
->NbColumns
; j
++)
922 if(value_notone_p(M
->p
[i
][j
]))
925 if(value_notzero_p(M
->p
[i
][j
]))
931 void Param_Polyhedron_Print(FILE* DST
, Param_Polyhedron
*PP
, char **param_names
)
936 for(P
=PP
->D
;P
;P
=P
->next
) {
938 /* prints current val. dom. */
939 printf( "---------------------------------------\n" );
940 printf( "Domain :\n");
941 Print_Domain( stdout
, P
->Domain
, param_names
);
943 /* scan the vertices */
944 printf( "Vertices :\n");
945 FORALL_PVertex_in_ParamPolyhedron(V
,P
,PP
) {
947 /* prints each vertex */
948 Print_Vertex( stdout
, V
->Vertex
, param_names
);
951 END_FORALL_PVertex_in_ParamPolyhedron
;
955 void Enumeration_Print(FILE *Dst
, Enumeration
*en
, char **params
)
957 for (; en
; en
= en
->next
) {
958 Print_Domain(Dst
, en
->ValidityDomain
, params
);
959 print_evalue(Dst
, &en
->EP
, params
);
963 void Enumeration_Free(Enumeration
*en
)
969 free_evalue_refs( &(en
->EP
) );
970 Domain_Free( en
->ValidityDomain
);
977 void Enumeration_mod2table(Enumeration
*en
, unsigned nparam
)
979 for (; en
; en
= en
->next
) {
980 evalue_mod2table(&en
->EP
, nparam
);
981 reduce_evalue(&en
->EP
);
985 size_t Enumeration_size(Enumeration
*en
)
989 for (; en
; en
= en
->next
) {
990 s
+= domain_size(en
->ValidityDomain
);
991 s
+= evalue_size(&en
->EP
);
996 void Free_ParamNames(char **params
, int m
)
1003 /* Check whether every set in D2 is included in some set of D1 */
1004 int DomainIncludes(Polyhedron
*D1
, Polyhedron
*D2
)
1006 for ( ; D2
; D2
= D2
->next
) {
1008 for (P1
= D1
; P1
; P1
= P1
->next
)
1009 if (PolyhedronIncludes(P1
, D2
))
1017 int line_minmax(Polyhedron
*I
, Value
*min
, Value
*max
)
1022 value_oppose(I
->Constraint
[0][2], I
->Constraint
[0][2]);
1023 /* There should never be a remainder here */
1024 if (value_pos_p(I
->Constraint
[0][1]))
1025 mpz_fdiv_q(*min
, I
->Constraint
[0][2], I
->Constraint
[0][1]);
1027 mpz_fdiv_q(*min
, I
->Constraint
[0][2], I
->Constraint
[0][1]);
1028 value_assign(*max
, *min
);
1029 } else for (i
= 0; i
< I
->NbConstraints
; ++i
) {
1030 if (value_zero_p(I
->Constraint
[i
][1])) {
1035 value_oppose(I
->Constraint
[i
][2], I
->Constraint
[i
][2]);
1036 if (value_pos_p(I
->Constraint
[i
][1]))
1037 mpz_cdiv_q(*min
, I
->Constraint
[i
][2], I
->Constraint
[i
][1]);
1039 mpz_fdiv_q(*max
, I
->Constraint
[i
][2], I
->Constraint
[i
][1]);
1047 PROCEDURES TO COMPUTE ENUMERATION. recursive procedure, recurse for
1050 @param pos index position of current loop index (1..hdim-1)
1051 @param P loop domain
1052 @param context context values for fixed indices
1053 @param exist number of existential variables
1054 @return the number of integer points in this
1058 void count_points_e (int pos
, Polyhedron
*P
, int exist
, int nparam
,
1059 Value
*context
, Value
*res
)
1064 value_set_si(*res
, 0);
1068 value_init(LB
); value_init(UB
); value_init(k
);
1072 if (lower_upper_bounds(pos
,P
,context
,&LB
,&UB
) !=0) {
1073 /* Problem if UB or LB is INFINITY */
1074 value_clear(LB
); value_clear(UB
); value_clear(k
);
1075 if (pos
> P
->Dimension
- nparam
- exist
)
1076 value_set_si(*res
, 1);
1078 value_set_si(*res
, -1);
1085 for (value_assign(k
,LB
); value_le(k
,UB
); value_increment(k
,k
)) {
1086 fprintf(stderr
, "(");
1087 for (i
=1; i
<pos
; i
++) {
1088 value_print(stderr
,P_VALUE_FMT
,context
[i
]);
1089 fprintf(stderr
,",");
1091 value_print(stderr
,P_VALUE_FMT
,k
);
1092 fprintf(stderr
,")\n");
1097 value_set_si(context
[pos
],0);
1098 if (value_lt(UB
,LB
)) {
1099 value_clear(LB
); value_clear(UB
); value_clear(k
);
1100 value_set_si(*res
, 0);
1105 value_set_si(*res
, 1);
1107 value_subtract(k
,UB
,LB
);
1108 value_add_int(k
,k
,1);
1109 value_assign(*res
, k
);
1111 value_clear(LB
); value_clear(UB
); value_clear(k
);
1115 /*-----------------------------------------------------------------*/
1116 /* Optimization idea */
1117 /* If inner loops are not a function of k (the current index) */
1118 /* i.e. if P->Constraint[i][pos]==0 for all P following this and */
1120 /* Then CNT = (UB-LB+1)*count_points(pos+1, P->next, context) */
1121 /* (skip the for loop) */
1122 /*-----------------------------------------------------------------*/
1125 value_set_si(*res
, 0);
1126 for (value_assign(k
,LB
);value_le(k
,UB
);value_increment(k
,k
)) {
1127 /* Insert k in context */
1128 value_assign(context
[pos
],k
);
1129 count_points_e(pos
+1, P
->next
, exist
, nparam
, context
, &c
);
1130 if(value_notmone_p(c
))
1131 value_addto(*res
, *res
, c
);
1133 value_set_si(*res
, -1);
1136 if (pos
> P
->Dimension
- nparam
- exist
&&
1143 fprintf(stderr
,"%d\n",CNT
);
1147 value_set_si(context
[pos
],0);
1148 value_clear(LB
); value_clear(UB
); value_clear(k
);
1150 } /* count_points_e */
1152 int DomainContains(Polyhedron
*P
, Value
*list_args
, int len
,
1153 unsigned MaxRays
, int set
)
1158 if (P
->Dimension
== len
)
1159 return in_domain(P
, list_args
);
1161 assert(set
); // assume list_args is large enough
1162 assert((P
->Dimension
- len
) % 2 == 0);
1164 for (i
= 0; i
< P
->Dimension
- len
; i
+= 2) {
1166 for (j
= 0 ; j
< P
->NbEq
; ++j
)
1167 if (value_notzero_p(P
->Constraint
[j
][1+len
+i
]))
1169 assert(j
< P
->NbEq
);
1170 value_absolute(m
, P
->Constraint
[j
][1+len
+i
]);
1171 k
= First_Non_Zero(P
->Constraint
[j
]+1, len
);
1173 assert(First_Non_Zero(P
->Constraint
[j
]+1+k
+1, len
- k
- 1) == -1);
1174 mpz_fdiv_q(list_args
[len
+i
], list_args
[k
], m
);
1175 mpz_fdiv_r(list_args
[len
+i
+1], list_args
[k
], m
);
1179 return in_domain(P
, list_args
);
1182 Polyhedron
*DomainConcat(Polyhedron
*head
, Polyhedron
*tail
)
1187 for (S
= head
; S
->next
; S
= S
->next
)
1193 #ifndef HAVE_LEXSMALLER
1195 evalue
*barvinok_lexsmaller_ev(Polyhedron
*P
, Polyhedron
*D
, unsigned dim
,
1196 Polyhedron
*C
, unsigned MaxRays
)
1202 #include <polylib/ranking.h>
1204 evalue
*barvinok_lexsmaller_ev(Polyhedron
*P
, Polyhedron
*D
, unsigned dim
,
1205 Polyhedron
*C
, unsigned MaxRays
)
1208 Polyhedron
*RC
, *RD
, *Q
;
1209 unsigned nparam
= dim
+ C
->Dimension
;
1213 RC
= LexSmaller(P
, D
, dim
, C
, MaxRays
);
1217 exist
= RD
->Dimension
- nparam
- dim
;
1218 CA
= align_context(RC
, RD
->Dimension
, MaxRays
);
1219 Q
= DomainIntersection(RD
, CA
, MaxRays
);
1220 Polyhedron_Free(CA
);
1222 Polyhedron_Free(RC
);
1225 for (Q
= RD
; Q
; Q
= Q
->next
) {
1227 Polyhedron
*next
= Q
->next
;
1230 t
= barvinok_enumerate_e(Q
, exist
, nparam
, MaxRays
);
1236 free_evalue_refs(t
);
1248 Enumeration
*barvinok_lexsmaller(Polyhedron
*P
, Polyhedron
*D
, unsigned dim
,
1249 Polyhedron
*C
, unsigned MaxRays
)
1251 evalue
*EP
= barvinok_lexsmaller_ev(P
, D
, dim
, C
, MaxRays
);
1253 return partition2enumeration(EP
);
1257 /* "align" matrix to have nrows by inserting
1258 * the necessary number of rows and an equal number of columns in front
1260 Matrix
*align_matrix(Matrix
*M
, int nrows
)
1263 int newrows
= nrows
- M
->NbRows
;
1264 Matrix
*M2
= Matrix_Alloc(nrows
, newrows
+ M
->NbColumns
);
1265 for (i
= 0; i
< newrows
; ++i
)
1266 value_set_si(M2
->p
[i
][i
], 1);
1267 for (i
= 0; i
< M
->NbRows
; ++i
)
1268 Vector_Copy(M
->p
[i
], M2
->p
[newrows
+i
]+newrows
, M
->NbColumns
);
1272 static void print_varlist(FILE *out
, int n
, char **names
)
1276 for (i
= 0; i
< n
; ++i
) {
1279 fprintf(out
, "%s", names
[i
]);
1284 static void print_term(FILE *out
, Value v
, int pos
, int dim
, int nparam
,
1285 char **iter_names
, char **param_names
, int *first
)
1287 if (value_zero_p(v
)) {
1288 if (first
&& *first
&& pos
>= dim
+ nparam
)
1294 if (!*first
&& value_pos_p(v
))
1298 if (pos
< dim
+ nparam
) {
1299 if (value_mone_p(v
))
1301 else if (!value_one_p(v
))
1302 value_print(out
, VALUE_FMT
, v
);
1304 fprintf(out
, "%s", iter_names
[pos
]);
1306 fprintf(out
, "%s", param_names
[pos
-dim
]);
1308 value_print(out
, VALUE_FMT
, v
);
1311 char **util_generate_names(int n
, char *prefix
)
1314 int len
= (prefix
? strlen(prefix
) : 0) + 10;
1315 char **names
= ALLOCN(char*, n
);
1317 fprintf(stderr
, "ERROR: memory overflow.\n");
1320 for (i
= 0; i
< n
; ++i
) {
1321 names
[i
] = ALLOCN(char, len
);
1323 fprintf(stderr
, "ERROR: memory overflow.\n");
1327 snprintf(names
[i
], len
, "%d", i
);
1329 snprintf(names
[i
], len
, "%s%d", prefix
, i
);
1335 void util_free_names(int n
, char **names
)
1338 for (i
= 0; i
< n
; ++i
)
1343 void Polyhedron_pprint(FILE *out
, Polyhedron
*P
, int dim
, int nparam
,
1344 char **iter_names
, char **param_names
)
1349 assert(dim
+ nparam
== P
->Dimension
);
1355 print_varlist(out
, nparam
, param_names
);
1356 fprintf(out
, " -> ");
1358 print_varlist(out
, dim
, iter_names
);
1359 fprintf(out
, " : ");
1362 fprintf(out
, "FALSE");
1363 else for (i
= 0; i
< P
->NbConstraints
; ++i
) {
1365 int v
= First_Non_Zero(P
->Constraint
[i
]+1, P
->Dimension
);
1366 if (v
== -1 && value_pos_p(P
->Constraint
[i
][0]))
1369 fprintf(out
, " && ");
1370 if (v
== -1 && value_notzero_p(P
->Constraint
[i
][1+P
->Dimension
]))
1371 fprintf(out
, "FALSE");
1372 else if (value_pos_p(P
->Constraint
[i
][v
+1])) {
1373 print_term(out
, P
->Constraint
[i
][v
+1], v
, dim
, nparam
,
1374 iter_names
, param_names
, NULL
);
1375 if (value_zero_p(P
->Constraint
[i
][0]))
1376 fprintf(out
, " = ");
1378 fprintf(out
, " >= ");
1379 for (j
= v
+1; j
<= dim
+nparam
; ++j
) {
1380 value_oppose(tmp
, P
->Constraint
[i
][1+j
]);
1381 print_term(out
, tmp
, j
, dim
, nparam
,
1382 iter_names
, param_names
, &first
);
1385 value_oppose(tmp
, P
->Constraint
[i
][1+v
]);
1386 print_term(out
, tmp
, v
, dim
, nparam
,
1387 iter_names
, param_names
, NULL
);
1388 fprintf(out
, " <= ");
1389 for (j
= v
+1; j
<= dim
+nparam
; ++j
)
1390 print_term(out
, P
->Constraint
[i
][1+j
], j
, dim
, nparam
,
1391 iter_names
, param_names
, &first
);
1395 fprintf(out
, " }\n");
1400 /* Construct a cone over P with P placed at x_d = 1, with
1401 * x_d the coordinate of an extra dimension
1403 * It's probably a mistake to depend so much on the internal
1404 * representation. We should probably simply compute the
1405 * vertices/facets first.
1407 Polyhedron
*Cone_over_Polyhedron(Polyhedron
*P
)
1409 unsigned NbConstraints
= 0;
1410 unsigned NbRays
= 0;
1414 if (POL_HAS(P
, POL_INEQUALITIES
))
1415 NbConstraints
= P
->NbConstraints
+ 1;
1416 if (POL_HAS(P
, POL_POINTS
))
1417 NbRays
= P
->NbRays
+ 1;
1419 C
= Polyhedron_Alloc(P
->Dimension
+1, NbConstraints
, NbRays
);
1420 if (POL_HAS(P
, POL_INEQUALITIES
)) {
1422 for (i
= 0; i
< P
->NbConstraints
; ++i
)
1423 Vector_Copy(P
->Constraint
[i
], C
->Constraint
[i
], P
->Dimension
+2);
1425 value_set_si(C
->Constraint
[P
->NbConstraints
][0], 1);
1426 value_set_si(C
->Constraint
[P
->NbConstraints
][1+P
->Dimension
], 1);
1428 if (POL_HAS(P
, POL_POINTS
)) {
1429 C
->NbBid
= P
->NbBid
;
1430 for (i
= 0; i
< P
->NbRays
; ++i
)
1431 Vector_Copy(P
->Ray
[i
], C
->Ray
[i
], P
->Dimension
+2);
1433 value_set_si(C
->Ray
[P
->NbRays
][0], 1);
1434 value_set_si(C
->Ray
[P
->NbRays
][1+C
->Dimension
], 1);
1436 POL_SET(C
, POL_VALID
);
1437 if (POL_HAS(P
, POL_INEQUALITIES
))
1438 POL_SET(C
, POL_INEQUALITIES
);
1439 if (POL_HAS(P
, POL_POINTS
))
1440 POL_SET(C
, POL_POINTS
);
1441 if (POL_HAS(P
, POL_VERTICES
))
1442 POL_SET(C
, POL_VERTICES
);
1446 /* Returns a (dim+nparam+1)x((dim-n)+nparam+1) matrix
1447 * mapping the transformed subspace back to the original space.
1448 * n is the number of equalities involving the variables
1449 * (i.e., not purely the parameters).
1450 * The remaining n coordinates in the transformed space would
1451 * have constant (parametric) values and are therefore not
1452 * included in the variables of the new space.
1454 Matrix
*compress_variables(Matrix
*Equalities
, unsigned nparam
)
1456 unsigned dim
= (Equalities
->NbColumns
-2) - nparam
;
1457 Matrix
*M
, *H
, *Q
, *U
, *C
, *ratH
, *invH
, *Ul
, *T1
, *T2
, *T
;
1462 for (n
= 0; n
< Equalities
->NbRows
; ++n
)
1463 if (First_Non_Zero(Equalities
->p
[n
]+1, dim
) == -1)
1466 return Identity(dim
+nparam
+1);
1468 value_set_si(mone
, -1);
1469 M
= Matrix_Alloc(n
, dim
);
1470 C
= Matrix_Alloc(n
+1, nparam
+1);
1471 for (i
= 0; i
< n
; ++i
) {
1472 Vector_Copy(Equalities
->p
[i
]+1, M
->p
[i
], dim
);
1473 Vector_Scale(Equalities
->p
[i
]+1+dim
, C
->p
[i
], mone
, nparam
+1);
1475 value_set_si(C
->p
[n
][nparam
], 1);
1476 left_hermite(M
, &H
, &Q
, &U
);
1481 ratH
= Matrix_Alloc(n
+1, n
+1);
1482 invH
= Matrix_Alloc(n
+1, n
+1);
1483 for (i
= 0; i
< n
; ++i
)
1484 Vector_Copy(H
->p
[i
], ratH
->p
[i
], n
);
1485 value_set_si(ratH
->p
[n
][n
], 1);
1486 ok
= Matrix_Inverse(ratH
, invH
);
1490 T1
= Matrix_Alloc(n
+1, nparam
+1);
1491 Matrix_Product(invH
, C
, T1
);
1494 if (value_notone_p(T1
->p
[n
][nparam
])) {
1495 for (i
= 0; i
< n
; ++i
) {
1496 if (!mpz_divisible_p(T1
->p
[i
][nparam
], T1
->p
[n
][nparam
])) {
1501 /* compress_params should have taken care of this */
1502 for (j
= 0; j
< nparam
; ++j
)
1503 assert(mpz_divisible_p(T1
->p
[i
][j
], T1
->p
[n
][nparam
]));
1504 Vector_AntiScale(T1
->p
[i
], T1
->p
[i
], T1
->p
[n
][nparam
], nparam
+1);
1506 value_set_si(T1
->p
[n
][nparam
], 1);
1508 Ul
= Matrix_Alloc(dim
+1, n
+1);
1509 for (i
= 0; i
< dim
; ++i
)
1510 Vector_Copy(U
->p
[i
], Ul
->p
[i
], n
);
1511 value_set_si(Ul
->p
[dim
][n
], 1);
1512 T2
= Matrix_Alloc(dim
+1, nparam
+1);
1513 Matrix_Product(Ul
, T1
, T2
);
1517 T
= Matrix_Alloc(dim
+nparam
+1, (dim
-n
)+nparam
+1);
1518 for (i
= 0; i
< dim
; ++i
) {
1519 Vector_Copy(U
->p
[i
]+n
, T
->p
[i
], dim
-n
);
1520 Vector_Copy(T2
->p
[i
], T
->p
[i
]+dim
-n
, nparam
+1);
1522 for (i
= 0; i
< nparam
+1; ++i
)
1523 value_set_si(T
->p
[dim
+i
][(dim
-n
)+i
], 1);
1524 assert(value_one_p(T2
->p
[dim
][nparam
]));
1531 Matrix
*left_inverse(Matrix
*M
, Matrix
**Eq
)
1534 Matrix
*L
, *H
, *Q
, *U
, *ratH
, *invH
, *Ut
, *inv
;
1539 L
= Matrix_Alloc(M
->NbRows
-1, M
->NbColumns
-1);
1540 for (i
= 0; i
< L
->NbRows
; ++i
)
1541 Vector_Copy(M
->p
[i
], L
->p
[i
], L
->NbColumns
);
1542 right_hermite(L
, &H
, &U
, &Q
);
1545 t
= Vector_Alloc(U
->NbColumns
);
1546 for (i
= 0; i
< U
->NbColumns
; ++i
)
1547 value_oppose(t
->p
[i
], M
->p
[i
][M
->NbColumns
-1]);
1549 *Eq
= Matrix_Alloc(H
->NbRows
- H
->NbColumns
, 2 + U
->NbColumns
);
1550 for (i
= 0; i
< H
->NbRows
- H
->NbColumns
; ++i
) {
1551 Vector_Copy(U
->p
[H
->NbColumns
+i
], (*Eq
)->p
[i
]+1, U
->NbColumns
);
1552 Inner_Product(U
->p
[H
->NbColumns
+i
], t
->p
, U
->NbColumns
,
1553 (*Eq
)->p
[i
]+1+U
->NbColumns
);
1556 ratH
= Matrix_Alloc(H
->NbColumns
+1, H
->NbColumns
+1);
1557 invH
= Matrix_Alloc(H
->NbColumns
+1, H
->NbColumns
+1);
1558 for (i
= 0; i
< H
->NbColumns
; ++i
)
1559 Vector_Copy(H
->p
[i
], ratH
->p
[i
], H
->NbColumns
);
1560 value_set_si(ratH
->p
[ratH
->NbRows
-1][ratH
->NbColumns
-1], 1);
1562 ok
= Matrix_Inverse(ratH
, invH
);
1565 Ut
= Matrix_Alloc(invH
->NbRows
, U
->NbColumns
+1);
1566 for (i
= 0; i
< Ut
->NbRows
-1; ++i
) {
1567 Vector_Copy(U
->p
[i
], Ut
->p
[i
], U
->NbColumns
);
1568 Inner_Product(U
->p
[i
], t
->p
, U
->NbColumns
, &Ut
->p
[i
][Ut
->NbColumns
-1]);
1572 value_set_si(Ut
->p
[Ut
->NbRows
-1][Ut
->NbColumns
-1], 1);
1573 inv
= Matrix_Alloc(invH
->NbRows
, Ut
->NbColumns
);
1574 Matrix_Product(invH
, Ut
, inv
);
1580 /* Check whether all rays are revlex positive in the parameters
1582 int Polyhedron_has_revlex_positive_rays(Polyhedron
*P
, unsigned nparam
)
1585 for (r
= 0; r
< P
->NbRays
; ++r
) {
1586 if (value_notzero_p(P
->Ray
[r
][P
->Dimension
+1]))
1589 for (i
= P
->Dimension
-1; i
>= P
->Dimension
-nparam
; --i
) {
1590 if (value_neg_p(P
->Ray
[r
][i
+1]))
1592 if (value_pos_p(P
->Ray
[r
][i
+1]))
1595 /* A ray independent of the parameters */
1596 if (i
< P
->Dimension
-nparam
)
1602 static Polyhedron
*Recession_Cone(Polyhedron
*P
, unsigned nparam
, unsigned MaxRays
)
1605 unsigned nvar
= P
->Dimension
- nparam
;
1606 Matrix
*M
= Matrix_Alloc(P
->NbConstraints
, 1 + nvar
+ 1);
1607 for (i
= 0; i
< P
->NbConstraints
; ++i
)
1608 Vector_Copy(P
->Constraint
[i
], M
->p
[i
], 1+nvar
);
1609 Polyhedron
*R
= Constraints2Polyhedron(M
, MaxRays
);
1614 int Polyhedron_is_unbounded(Polyhedron
*P
, unsigned nparam
, unsigned MaxRays
)
1618 Polyhedron
*R
= Recession_Cone(P
, nparam
, MaxRays
);
1619 POL_ENSURE_VERTICES(R
);
1621 for (i
= 0; i
< R
->NbRays
; ++i
)
1622 if (value_zero_p(R
->Ray
[i
][1+R
->Dimension
]))
1624 is_unbounded
= R
->NbBid
> 0 || i
< R
->NbRays
;
1626 return is_unbounded
;