2 #include <isl_set_polylib.h>
3 #include <barvinok/barvinok.h>
4 #include <barvinok/evalue.h>
5 #include <barvinok/util.h>
6 #include "param_util.h"
8 #include "reduce_domain.h"
11 #define ALLOC(type) (type*)malloc(sizeof(type))
13 Polyhedron
*unfringe (Polyhedron
*P
, unsigned MaxRays
)
15 int len
= P
->Dimension
+2;
16 Polyhedron
*T
, *R
= P
;
19 Vector
*row
= Vector_Alloc(len
);
20 value_set_si(row
->p
[0], 1);
22 R
= DomainConstraintSimplify(Polyhedron_Copy(P
), MaxRays
);
24 Matrix
*M
= Matrix_Alloc(2, len
-1);
25 value_set_si(M
->p
[1][len
-2], 1);
26 for (int v
= 0; v
< P
->Dimension
; ++v
) {
27 value_set_si(M
->p
[0][v
], 1);
28 Polyhedron
*I
= Polyhedron_Image(R
, M
, 2+1);
29 value_set_si(M
->p
[0][v
], 0);
30 for (int r
= 0; r
< I
->NbConstraints
; ++r
) {
31 if (value_zero_p(I
->Constraint
[r
][0]))
33 if (value_zero_p(I
->Constraint
[r
][1]))
35 if (value_one_p(I
->Constraint
[r
][1]))
37 if (value_mone_p(I
->Constraint
[r
][1]))
39 value_absolute(g
, I
->Constraint
[r
][1]);
40 Vector_Set(row
->p
+1, 0, len
-2);
41 value_division(row
->p
[1+v
], I
->Constraint
[r
][1], g
);
42 mpz_fdiv_q(row
->p
[len
-1], I
->Constraint
[r
][2], g
);
44 R
= AddConstraints(row
->p
, 1, R
, MaxRays
);
56 /* Construct a constraint c from constraints l and u such that if
57 * if constraint c holds then for each value of the other variables
58 * there is at most one value of variable pos (position pos+1 in the constraints).
60 * Given a lower and an upper bound
61 * n_l v_i + <c_l,x> + c_l >= 0
62 * -n_u v_i + <c_u,x> + c_u >= 0
63 * the constructed constraint is
65 * -(n_l<c_u,x> + n_u<c_l,x>) + (-n_l c_u - n_u c_l + n_l n_u - 1)
67 * which is then simplified to remove the content of the non-constant coefficients
69 * len is the total length of the constraints.
70 * v is a temporary variable that can be used by this procedure
72 static void negative_test_constraint(Value
*l
, Value
*u
, Value
*c
, int pos
,
75 value_oppose(*v
, u
[pos
+1]);
76 Vector_Combine(l
+1, u
+1, c
+1, *v
, l
[pos
+1], len
-1);
77 value_multiply(*v
, *v
, l
[pos
+1]);
78 value_subtract(c
[len
-1], c
[len
-1], *v
);
80 Vector_Scale(c
+1, c
+1, *v
, len
-1);
81 value_decrement(c
[len
-1], c
[len
-1]);
82 ConstraintSimplify(c
, c
, len
, v
);
85 static bool parallel_constraints(Value
*l
, Value
*u
, Value
*c
, int pos
,
94 Vector_Gcd(&l
[1+pos
], len
, &g1
);
95 Vector_Gcd(&u
[1+pos
], len
, &g2
);
96 Vector_Combine(l
+1+pos
, u
+1+pos
, c
+1, g2
, g1
, len
);
97 parallel
= First_Non_Zero(c
+1, len
) == -1;
105 static void negative_test_constraint7(Value
*l
, Value
*u
, Value
*c
, int pos
,
106 int exist
, int len
, Value
*v
)
111 Vector_Gcd(&u
[1+pos
], exist
, v
);
112 Vector_Gcd(&l
[1+pos
], exist
, &g
);
113 Vector_Combine(l
+1, u
+1, c
+1, *v
, g
, len
-1);
114 value_multiply(*v
, *v
, g
);
115 value_subtract(c
[len
-1], c
[len
-1], *v
);
116 value_set_si(*v
, -1);
117 Vector_Scale(c
+1, c
+1, *v
, len
-1);
118 value_decrement(c
[len
-1], c
[len
-1]);
119 ConstraintSimplify(c
, c
, len
, v
);
124 /* Turns a x + b >= 0 into a x + b <= -1
126 * len is the total length of the constraint.
127 * v is a temporary variable that can be used by this procedure
129 static void oppose_constraint(Value
*c
, int len
, Value
*v
)
131 value_set_si(*v
, -1);
132 Vector_Scale(c
+1, c
+1, *v
, len
-1);
133 value_decrement(c
[len
-1], c
[len
-1]);
136 /* Split polyhedron P into two polyhedra *pos and *neg, where
137 * existential variable i has at most one solution for each
138 * value of the other variables in *neg.
140 * The splitting is performed using constraints l and u.
142 * nvar: number of set variables
143 * row: temporary vector that can be used by this procedure
144 * f: temporary value that can be used by this procedure
146 static bool SplitOnConstraint(Polyhedron
*P
, int i
, int l
, int u
,
147 int nvar
, int MaxRays
, Vector
*row
, Value
& f
,
148 Polyhedron
**pos
, Polyhedron
**neg
)
150 negative_test_constraint(P
->Constraint
[l
], P
->Constraint
[u
],
151 row
->p
, nvar
+i
, P
->Dimension
+2, &f
);
152 *neg
= AddConstraints(row
->p
, 1, P
, MaxRays
);
153 POL_ENSURE_VERTICES(*neg
);
155 /* We found an independent, but useless constraint
156 * Maybe we should detect this earlier and not
157 * mark the variable as INDEPENDENT
159 if (emptyQ((*neg
))) {
160 Polyhedron_Free(*neg
);
164 oppose_constraint(row
->p
, P
->Dimension
+2, &f
);
165 *pos
= AddConstraints(row
->p
, 1, P
, MaxRays
);
166 POL_ENSURE_VERTICES(*pos
);
168 if (emptyQ((*pos
))) {
169 Polyhedron_Free(*neg
);
170 Polyhedron_Free(*pos
);
178 * unimodularly transform P such that constraint r is transformed
179 * into a constraint that involves only a single (the first)
180 * existential variable
183 static Polyhedron
*rotate_along(Polyhedron
*P
, int r
, int nvar
, int exist
,
189 Matrix
*M
= Matrix_Alloc(exist
, exist
);
190 Vector_Copy(P
->Constraint
[r
]+1+nvar
, M
->p
[0], exist
);
191 Vector_Gcd(M
->p
[0], exist
, &g
);
192 if (value_notone_p(g
))
193 Vector_AntiScale(M
->p
[0], M
->p
[0], g
, exist
);
196 int ok
= unimodular_complete(M
, 1);
198 Matrix
*M2
= Matrix_Alloc(P
->Dimension
+1, P
->Dimension
+1);
199 for (r
= 0; r
< nvar
; ++r
)
200 value_set_si(M2
->p
[r
][r
], 1);
201 for ( ; r
< nvar
+exist
; ++r
)
202 Vector_Copy(M
->p
[r
-nvar
], M2
->p
[r
]+nvar
, exist
);
203 for ( ; r
< P
->Dimension
+1; ++r
)
204 value_set_si(M2
->p
[r
][r
], 1);
205 Polyhedron
*T
= Polyhedron_Image(P
, M2
, MaxRays
);
213 /* Split polyhedron P into two polyhedra *pos and *neg, where
214 * existential variable i has at most one solution for each
215 * value of the other variables in *neg.
217 * If independent is set, then the two constraints on which the
218 * split will be performed need to be independent of the other
219 * existential variables.
221 * Return true if an appropriate split could be performed.
223 * nvar: number of set variables
224 * exist: number of existential variables
225 * row: temporary vector that can be used by this procedure
226 * f: temporary value that can be used by this procedure
228 static bool SplitOnVar(Polyhedron
*P
, int i
,
229 int nvar
, int exist
, int MaxRays
,
230 Vector
*row
, Value
& f
, bool independent
,
231 Polyhedron
**pos
, Polyhedron
**neg
)
235 for (int l
= P
->NbEq
; l
< P
->NbConstraints
; ++l
) {
236 if (value_negz_p(P
->Constraint
[l
][nvar
+i
+1]))
240 for (j
= 0; j
< exist
; ++j
)
241 if (j
!= i
&& value_notzero_p(P
->Constraint
[l
][nvar
+j
+1]))
247 for (int u
= P
->NbEq
; u
< P
->NbConstraints
; ++u
) {
248 if (value_posz_p(P
->Constraint
[u
][nvar
+i
+1]))
252 for (j
= 0; j
< exist
; ++j
)
253 if (j
!= i
&& value_notzero_p(P
->Constraint
[u
][nvar
+j
+1]))
259 if (SplitOnConstraint(P
, i
, l
, u
, nvar
, MaxRays
, row
, f
, pos
, neg
)) {
262 Polyhedron_ExchangeColumns(*neg
, nvar
+1, nvar
+1+i
);
272 static bool double_bound_pair(Polyhedron
*P
, int nvar
, int exist
,
273 int i
, int l1
, int l2
,
274 Polyhedron
**pos
, Polyhedron
**neg
)
278 Vector
*row
= Vector_Alloc(P
->Dimension
+2);
279 value_set_si(row
->p
[0], 1);
280 value_oppose(f
, P
->Constraint
[l1
][nvar
+i
+1]);
281 Vector_Combine(P
->Constraint
[l1
]+1, P
->Constraint
[l2
]+1,
283 P
->Constraint
[l2
][nvar
+i
+1], f
,
285 ConstraintSimplify(row
->p
, row
->p
, P
->Dimension
+2, &f
);
286 *pos
= AddConstraints(row
->p
, 1, P
, 0);
287 POL_ENSURE_VERTICES(*pos
);
289 Vector_Scale(row
->p
+1, row
->p
+1, f
, P
->Dimension
+1);
290 value_decrement(row
->p
[P
->Dimension
+1], row
->p
[P
->Dimension
+1]);
291 *neg
= AddConstraints(row
->p
, 1, P
, 0);
292 POL_ENSURE_VERTICES(*neg
);
296 return !emptyQ((*pos
)) && !emptyQ((*neg
));
299 static bool double_bound(Polyhedron
*P
, int nvar
, int exist
,
300 Polyhedron
**pos
, Polyhedron
**neg
)
302 for (int i
= 0; i
< exist
; ++i
) {
304 for (l1
= P
->NbEq
; l1
< P
->NbConstraints
; ++l1
) {
305 if (value_negz_p(P
->Constraint
[l1
][nvar
+i
+1]))
307 for (l2
= l1
+ 1; l2
< P
->NbConstraints
; ++l2
) {
308 if (value_negz_p(P
->Constraint
[l2
][nvar
+i
+1]))
310 if (double_bound_pair(P
, nvar
, exist
, i
, l1
, l2
, pos
, neg
))
314 for (l1
= P
->NbEq
; l1
< P
->NbConstraints
; ++l1
) {
315 if (value_posz_p(P
->Constraint
[l1
][nvar
+i
+1]))
317 if (l1
< P
->NbConstraints
)
318 for (l2
= l1
+ 1; l2
< P
->NbConstraints
; ++l2
) {
319 if (value_posz_p(P
->Constraint
[l2
][nvar
+i
+1]))
321 if (double_bound_pair(P
, nvar
, exist
, i
, l1
, l2
, pos
, neg
))
333 INDEPENDENT
= 1 << 2,
337 static evalue
* enumerate_or(Polyhedron
*D
,
338 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
341 fprintf(stderr
, "\nER: Or\n");
342 #endif /* DEBUG_ER */
344 Polyhedron
*N
= D
->next
;
347 barvinok_enumerate_e_with_options(D
, exist
, nparam
, options
);
350 for (D
= N
; D
; D
= N
) {
355 barvinok_enumerate_e_with_options(D
, exist
, nparam
, options
);
367 static evalue
* enumerate_sum(Polyhedron
*P
,
368 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
370 int nvar
= P
->Dimension
- exist
- nparam
;
371 int toswap
= nvar
< exist
? nvar
: exist
;
372 for (int i
= 0; i
< toswap
; ++i
)
373 Polyhedron_ExchangeColumns(P
, 1 + i
, nvar
+exist
- i
);
377 fprintf(stderr
, "\nER: Sum\n");
378 #endif /* DEBUG_ER */
380 evalue
*EP
= barvinok_enumerate_e_with_options(P
, exist
, nparam
, options
);
382 evalue_split_domains_into_orthants(EP
, options
->MaxRays
);
384 evalue_range_reduction(EP
);
386 evalue_frac2floor(EP
);
388 evalue
*sum
= barvinok_summate(EP
, nvar
, options
);
393 evalue_range_reduction(EP
);
398 static evalue
* split_sure(Polyhedron
*P
, Polyhedron
*S
,
399 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
401 int nvar
= P
->Dimension
- exist
- nparam
;
403 Matrix
*M
= Matrix_Alloc(exist
, S
->Dimension
+2);
404 for (int i
= 0; i
< exist
; ++i
)
405 value_set_si(M
->p
[i
][nvar
+i
+1], 1);
407 S
= DomainAddRays(S
, M
, options
->MaxRays
);
409 Polyhedron
*F
= DomainAddRays(P
, M
, options
->MaxRays
);
410 Polyhedron
*D
= DomainDifference(F
, S
, options
->MaxRays
);
412 D
= Disjoint_Domain(D
, 0, options
->MaxRays
);
417 M
= Matrix_Alloc(P
->Dimension
+1-exist
, P
->Dimension
+1);
418 for (int j
= 0; j
< nvar
; ++j
)
419 value_set_si(M
->p
[j
][j
], 1);
420 for (int j
= 0; j
< nparam
+1; ++j
)
421 value_set_si(M
->p
[nvar
+j
][nvar
+exist
+j
], 1);
422 Polyhedron
*T
= Polyhedron_Image(S
, M
, options
->MaxRays
);
423 evalue
*EP
= barvinok_enumerate_e_with_options(T
, 0, nparam
, options
);
428 for (Polyhedron
*Q
= D
; Q
; Q
= Q
->next
) {
429 Polyhedron
*N
= Q
->next
;
431 T
= DomainIntersection(P
, Q
, options
->MaxRays
);
432 evalue
*E
= barvinok_enumerate_e_with_options(T
, exist
, nparam
, options
);
442 static evalue
* enumerate_sure(Polyhedron
*P
,
443 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
447 int nvar
= P
->Dimension
- exist
- nparam
;
453 for (i
= 0; i
< exist
; ++i
) {
454 Matrix
*M
= Matrix_Alloc(S
->NbConstraints
, S
->Dimension
+2);
456 value_set_si(lcm
, 1);
457 for (int j
= 0; j
< S
->NbConstraints
; ++j
) {
458 if (value_negz_p(S
->Constraint
[j
][1+nvar
+i
]))
460 if (value_one_p(S
->Constraint
[j
][1+nvar
+i
]))
462 value_lcm(lcm
, lcm
, S
->Constraint
[j
][1+nvar
+i
]);
465 for (int j
= 0; j
< S
->NbConstraints
; ++j
) {
466 if (value_negz_p(S
->Constraint
[j
][1+nvar
+i
]))
468 if (value_one_p(S
->Constraint
[j
][1+nvar
+i
]))
470 value_division(f
, lcm
, S
->Constraint
[j
][1+nvar
+i
]);
471 Vector_Scale(S
->Constraint
[j
], M
->p
[c
], f
, S
->Dimension
+2);
472 value_subtract(M
->p
[c
][S
->Dimension
+1],
473 M
->p
[c
][S
->Dimension
+1],
475 value_increment(M
->p
[c
][S
->Dimension
+1],
476 M
->p
[c
][S
->Dimension
+1]);
480 S
= AddConstraints(M
->p
[0], c
, S
, options
->MaxRays
);
495 fprintf(stderr
, "\nER: Sure\n");
496 #endif /* DEBUG_ER */
498 return split_sure(P
, S
, exist
, nparam
, options
);
501 static evalue
* enumerate_sure2(Polyhedron
*P
,
502 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
504 int nvar
= P
->Dimension
- exist
- nparam
;
506 for (r
= 0; r
< P
->NbRays
; ++r
)
507 if (value_one_p(P
->Ray
[r
][0]) &&
508 value_one_p(P
->Ray
[r
][P
->Dimension
+1]))
514 Matrix
*M
= Matrix_Alloc(nvar
+ 1 + nparam
, P
->Dimension
+2);
515 for (int i
= 0; i
< nvar
; ++i
)
516 value_set_si(M
->p
[i
][1+i
], 1);
517 for (int i
= 0; i
< nparam
; ++i
)
518 value_set_si(M
->p
[i
+nvar
][1+nvar
+exist
+i
], 1);
519 Vector_Copy(P
->Ray
[r
]+1+nvar
, M
->p
[nvar
+nparam
]+1+nvar
, exist
);
520 value_set_si(M
->p
[nvar
+nparam
][0], 1);
521 value_set_si(M
->p
[nvar
+nparam
][P
->Dimension
+1], 1);
522 Polyhedron
* F
= Rays2Polyhedron(M
, options
->MaxRays
);
525 Polyhedron
*I
= DomainIntersection(F
, P
, options
->MaxRays
);
529 fprintf(stderr
, "\nER: Sure2\n");
530 #endif /* DEBUG_ER */
532 return split_sure(P
, I
, exist
, nparam
, options
);
535 static evalue
* enumerate_cyclic(Polyhedron
*P
,
536 unsigned exist
, unsigned nparam
,
537 evalue
* EP
, int r
, int p
, unsigned MaxRays
)
539 int nvar
= P
->Dimension
- exist
- nparam
;
541 /* If EP in its fractional maps only contains references
542 * to the remainder parameter with appropriate coefficients
543 * then we could in principle avoid adding existentially
544 * quantified variables to the validity domains.
545 * We'd have to replace the remainder by m { p/m }
546 * and multiply with an appropriate factor that is one
547 * only in the appropriate range.
548 * This last multiplication can be avoided if EP
549 * has a single validity domain with no (further)
550 * constraints on the remainder parameter
553 Matrix
*CT
= Matrix_Alloc(nparam
+1, nparam
+3);
554 Matrix
*M
= Matrix_Alloc(1, 1+nparam
+3);
555 for (int j
= 0; j
< nparam
; ++j
)
557 value_set_si(CT
->p
[j
][j
], 1);
558 value_set_si(CT
->p
[p
][nparam
+1], 1);
559 value_set_si(CT
->p
[nparam
][nparam
+2], 1);
560 value_set_si(M
->p
[0][1+p
], -1);
561 value_absolute(M
->p
[0][1+nparam
], P
->Ray
[0][1+nvar
+exist
+p
]);
562 value_set_si(M
->p
[0][1+nparam
+1], 1);
563 Polyhedron
*CEq
= Constraints2Polyhedron(M
, 1);
565 addeliminatedparams_enum(EP
, CT
, CEq
, MaxRays
, nparam
);
566 Polyhedron_Free(CEq
);
572 static void enumerate_vd_add_ray(evalue
*EP
, Matrix
*Rays
, unsigned MaxRays
)
574 if (value_notzero_p(EP
->d
))
577 assert(EP
->x
.p
->type
== partition
);
578 assert(EP
->x
.p
->pos
== EVALUE_DOMAIN(EP
->x
.p
->arr
[0])->Dimension
);
579 for (int i
= 0; i
< EP
->x
.p
->size
/2; ++i
) {
580 Polyhedron
*D
= EVALUE_DOMAIN(EP
->x
.p
->arr
[2*i
]);
581 Polyhedron
*N
= DomainAddRays(D
, Rays
, MaxRays
);
582 EVALUE_SET_DOMAIN(EP
->x
.p
->arr
[2*i
], N
);
587 static evalue
* enumerate_line(Polyhedron
*P
,
588 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
594 fprintf(stderr
, "\nER: Line\n");
595 #endif /* DEBUG_ER */
597 int nvar
= P
->Dimension
- exist
- nparam
;
599 for (i
= 0; i
< nparam
; ++i
)
600 if (value_notzero_p(P
->Ray
[0][1+nvar
+exist
+i
]))
603 for (j
= i
+1; j
< nparam
; ++j
)
604 if (value_notzero_p(P
->Ray
[0][1+nvar
+exist
+i
]))
606 assert(j
>= nparam
); // for now
608 Matrix
*M
= Matrix_Alloc(2, P
->Dimension
+2);
609 value_set_si(M
->p
[0][0], 1);
610 value_set_si(M
->p
[0][1+nvar
+exist
+i
], 1);
611 value_set_si(M
->p
[1][0], 1);
612 value_set_si(M
->p
[1][1+nvar
+exist
+i
], -1);
613 value_absolute(M
->p
[1][1+P
->Dimension
], P
->Ray
[0][1+nvar
+exist
+i
]);
614 value_decrement(M
->p
[1][1+P
->Dimension
], M
->p
[1][1+P
->Dimension
]);
615 Polyhedron
*S
= AddConstraints(M
->p
[0], 2, P
, options
->MaxRays
);
616 evalue
*EP
= barvinok_enumerate_e_with_options(S
, exist
, nparam
, options
);
620 return enumerate_cyclic(P
, exist
, nparam
, EP
, 0, i
, options
->MaxRays
);
623 static int single_param_pos(Polyhedron
*P
, unsigned exist
, unsigned nparam
,
626 int nvar
= P
->Dimension
- exist
- nparam
;
627 if (First_Non_Zero(P
->Ray
[r
]+1, nvar
) != -1)
629 int i
= First_Non_Zero(P
->Ray
[r
]+1+nvar
+exist
, nparam
);
632 if (First_Non_Zero(P
->Ray
[r
]+1+nvar
+exist
+1, nparam
-i
-1) != -1)
637 static evalue
* enumerate_remove_ray(Polyhedron
*P
, int r
,
638 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
641 fprintf(stderr
, "\nER: RedundantRay\n");
642 #endif /* DEBUG_ER */
646 value_set_si(one
, 1);
647 int len
= P
->NbRays
-1;
648 Matrix
*M
= Matrix_Alloc(2 * len
, P
->Dimension
+2);
649 Vector_Copy(P
->Ray
[0], M
->p
[0], r
* (P
->Dimension
+2));
650 Vector_Copy(P
->Ray
[r
+1], M
->p
[r
], (len
-r
) * (P
->Dimension
+2));
651 for (int j
= 0; j
< P
->NbRays
; ++j
) {
654 Vector_Combine(P
->Ray
[j
], P
->Ray
[r
], M
->p
[len
+j
-(j
>r
)],
655 one
, P
->Ray
[j
][P
->Dimension
+1], P
->Dimension
+2);
658 P
= Rays2Polyhedron(M
, options
->MaxRays
);
660 evalue
*EP
= barvinok_enumerate_e_with_options(P
, exist
, nparam
, options
);
667 static evalue
* enumerate_redundant_ray(Polyhedron
*P
,
668 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
670 assert(P
->NbBid
== 0);
671 int nvar
= P
->Dimension
- exist
- nparam
;
675 for (int r
= 0; r
< P
->NbRays
; ++r
) {
676 if (value_notzero_p(P
->Ray
[r
][P
->Dimension
+1]))
678 int i1
= single_param_pos(P
, exist
, nparam
, r
);
681 for (int r2
= r
+1; r2
< P
->NbRays
; ++r2
) {
682 if (value_notzero_p(P
->Ray
[r2
][P
->Dimension
+1]))
684 int i2
= single_param_pos(P
, exist
, nparam
, r2
);
690 value_division(m
, P
->Ray
[r
][1+nvar
+exist
+i1
],
691 P
->Ray
[r2
][1+nvar
+exist
+i1
]);
692 value_multiply(m
, m
, P
->Ray
[r2
][1+nvar
+exist
+i1
]);
693 /* r2 divides r => r redundant */
694 if (value_eq(m
, P
->Ray
[r
][1+nvar
+exist
+i1
])) {
696 return enumerate_remove_ray(P
, r
, exist
, nparam
, options
);
699 value_division(m
, P
->Ray
[r2
][1+nvar
+exist
+i1
],
700 P
->Ray
[r
][1+nvar
+exist
+i1
]);
701 value_multiply(m
, m
, P
->Ray
[r
][1+nvar
+exist
+i1
]);
702 /* r divides r2 => r2 redundant */
703 if (value_eq(m
, P
->Ray
[r2
][1+nvar
+exist
+i1
])) {
705 return enumerate_remove_ray(P
, r2
, exist
, nparam
, options
);
713 static Polyhedron
*upper_bound(Polyhedron
*P
,
714 int pos
, Value
*max
, Polyhedron
**R
)
723 for (Polyhedron
*Q
= P
; Q
; Q
= N
) {
725 for (r
= 0; r
< P
->NbRays
; ++r
) {
726 if (value_zero_p(P
->Ray
[r
][P
->Dimension
+1]) &&
727 value_pos_p(P
->Ray
[r
][1+pos
]))
738 for (r
= 0; r
< P
->NbRays
; ++r
) {
739 if (value_zero_p(P
->Ray
[r
][P
->Dimension
+1]))
741 mpz_fdiv_q(v
, P
->Ray
[r
][1+pos
], P
->Ray
[r
][1+P
->Dimension
]);
742 if ((!Q
->next
&& r
== 0) || value_gt(v
, *max
))
743 value_assign(*max
, v
);
750 static evalue
* enumerate_ray(Polyhedron
*P
,
751 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
753 assert(P
->NbBid
== 0);
754 int nvar
= P
->Dimension
- exist
- nparam
;
757 for (r
= 0; r
< P
->NbRays
; ++r
)
758 if (value_zero_p(P
->Ray
[r
][P
->Dimension
+1]))
764 for (r2
= r
+1; r2
< P
->NbRays
; ++r2
)
765 if (value_zero_p(P
->Ray
[r2
][P
->Dimension
+1]))
767 if (r2
< P
->NbRays
) {
769 return enumerate_sum(P
, exist
, nparam
, options
);
773 fprintf(stderr
, "\nER: Ray\n");
774 #endif /* DEBUG_ER */
780 value_set_si(one
, 1);
781 int i
= single_param_pos(P
, exist
, nparam
, r
);
782 assert(i
!= -1); // for now;
784 Matrix
*M
= Matrix_Alloc(P
->NbRays
, P
->Dimension
+2);
785 for (int j
= 0; j
< P
->NbRays
; ++j
) {
786 Vector_Combine(P
->Ray
[j
], P
->Ray
[r
], M
->p
[j
],
787 one
, P
->Ray
[j
][P
->Dimension
+1], P
->Dimension
+2);
789 Polyhedron
*S
= Rays2Polyhedron(M
, options
->MaxRays
);
791 Polyhedron
*D
= DomainDifference(P
, S
, options
->MaxRays
);
793 // Polyhedron_Print(stderr, P_VALUE_FMT, D);
794 assert(value_pos_p(P
->Ray
[r
][1+nvar
+exist
+i
])); // for now
796 D
= upper_bound(D
, nvar
+exist
+i
, &m
, &R
);
800 M
= Matrix_Alloc(2, P
->Dimension
+2);
801 value_set_si(M
->p
[0][0], 1);
802 value_set_si(M
->p
[1][0], 1);
803 value_set_si(M
->p
[0][1+nvar
+exist
+i
], -1);
804 value_set_si(M
->p
[1][1+nvar
+exist
+i
], 1);
805 value_assign(M
->p
[0][1+P
->Dimension
], m
);
806 value_oppose(M
->p
[1][1+P
->Dimension
], m
);
807 value_addto(M
->p
[1][1+P
->Dimension
], M
->p
[1][1+P
->Dimension
],
808 P
->Ray
[r
][1+nvar
+exist
+i
]);
809 value_decrement(M
->p
[1][1+P
->Dimension
], M
->p
[1][1+P
->Dimension
]);
810 // Matrix_Print(stderr, P_VALUE_FMT, M);
811 D
= AddConstraints(M
->p
[0], 2, P
, options
->MaxRays
);
812 // Polyhedron_Print(stderr, P_VALUE_FMT, D);
813 value_subtract(M
->p
[0][1+P
->Dimension
], M
->p
[0][1+P
->Dimension
],
814 P
->Ray
[r
][1+nvar
+exist
+i
]);
815 // Matrix_Print(stderr, P_VALUE_FMT, M);
816 S
= AddConstraints(M
->p
[0], 1, P
, options
->MaxRays
);
817 // Polyhedron_Print(stderr, P_VALUE_FMT, S);
820 evalue
*EP
= barvinok_enumerate_e_with_options(D
, exist
, nparam
, options
);
825 if (value_notone_p(P
->Ray
[r
][1+nvar
+exist
+i
]))
826 EP
= enumerate_cyclic(P
, exist
, nparam
, EP
, r
, i
, options
->MaxRays
);
828 M
= Matrix_Alloc(1, nparam
+2);
829 value_set_si(M
->p
[0][0], 1);
830 value_set_si(M
->p
[0][1+i
], 1);
831 enumerate_vd_add_ray(EP
, M
, options
->MaxRays
);
836 evalue
*E
= barvinok_enumerate_e_with_options(S
, exist
, nparam
, options
);
844 evalue
*ER
= enumerate_or(R
, exist
, nparam
, options
);
846 free_evalue_refs(ER
);
853 static evalue
* enumerate_vd(Polyhedron
**PA
,
854 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
857 int nvar
= P
->Dimension
- exist
- nparam
;
858 Param_Polyhedron
*PP
= NULL
;
859 Polyhedron
*C
= Universe_Polyhedron(nparam
);
861 PP
= Polyhedron2Param_Polyhedron(PR
, C
, options
);
865 Param_Domain
*D
, *last
;
868 for (nd
= 0, D
=PP
->D
; D
; D
=D
->next
, ++nd
)
871 Polyhedron
**VD
= new Polyhedron
*[nd
];
872 Polyhedron
*TC
= true_context(P
, C
, options
->MaxRays
);
873 FORALL_REDUCED_DOMAIN(PP
, TC
, nd
, options
, i
, D
, rVD
)
876 END_FORALL_REDUCED_DOMAIN
884 /* This doesn't seem to have any effect */
886 Polyhedron
*CA
= align_context(VD
[0], P
->Dimension
, options
->MaxRays
);
888 P
= DomainIntersection(P
, CA
, options
->MaxRays
);
902 fprintf(stderr
, "\nER: VD\n");
903 #endif /* DEBUG_ER */
904 for (int i
= 0; i
< nd
; ++i
) {
905 Polyhedron
*CA
= align_context(VD
[i
], P
->Dimension
, options
->MaxRays
);
906 Polyhedron
*I
= DomainIntersection(P
, CA
, options
->MaxRays
);
909 EP
= barvinok_enumerate_e_with_options(I
, exist
, nparam
, options
);
911 evalue
*E
= barvinok_enumerate_e_with_options(I
, exist
, nparam
,
921 for (int i
= 0; i
< nd
; ++i
)
922 Polyhedron_Free(VD
[i
]);
926 if (!EP
&& nvar
== 0) {
929 Param_Vertices
*V
, *V2
;
930 Matrix
* M
= Matrix_Alloc(1, P
->Dimension
+2);
932 FORALL_PVertex_in_ParamPolyhedron(V
, last
, PP
) {
934 FORALL_PVertex_in_ParamPolyhedron(V2
, last
, PP
) {
941 for (int i
= 0; i
< exist
; ++i
) {
942 value_oppose(f
, V
->Vertex
->p
[i
][nparam
+1]);
943 Vector_Combine(V
->Vertex
->p
[i
],
945 M
->p
[0] + 1 + nvar
+ exist
,
946 V2
->Vertex
->p
[i
][nparam
+1],
950 for (j
= 0; j
< nparam
; ++j
)
951 if (value_notzero_p(M
->p
[0][1+nvar
+exist
+j
]))
955 ConstraintSimplify(M
->p
[0], M
->p
[0],
957 value_set_si(M
->p
[0][0], 0);
958 Polyhedron
*para
= AddConstraints(M
->p
[0], 1, P
,
960 POL_ENSURE_VERTICES(para
);
962 Polyhedron_Free(para
);
965 Polyhedron
*pos
, *neg
;
966 value_set_si(M
->p
[0][0], 1);
967 value_decrement(M
->p
[0][P
->Dimension
+1],
968 M
->p
[0][P
->Dimension
+1]);
969 neg
= AddConstraints(M
->p
[0], 1, P
, options
->MaxRays
);
971 Vector_Scale(M
->p
[0]+1, M
->p
[0]+1, f
,
973 value_decrement(M
->p
[0][P
->Dimension
+1],
974 M
->p
[0][P
->Dimension
+1]);
975 value_decrement(M
->p
[0][P
->Dimension
+1],
976 M
->p
[0][P
->Dimension
+1]);
977 pos
= AddConstraints(M
->p
[0], 1, P
, options
->MaxRays
);
978 POL_ENSURE_VERTICES(neg
);
979 POL_ENSURE_VERTICES(pos
);
980 if (emptyQ(neg
) && emptyQ(pos
)) {
981 Polyhedron_Free(para
);
982 Polyhedron_Free(pos
);
983 Polyhedron_Free(neg
);
987 fprintf(stderr
, "\nER: Order\n");
988 #endif /* DEBUG_ER */
989 EP
= barvinok_enumerate_e_with_options(para
, exist
, nparam
,
993 E
= barvinok_enumerate_e_with_options(pos
, exist
, nparam
,
999 E
= barvinok_enumerate_e_with_options(neg
, exist
, nparam
,
1004 Polyhedron_Free(para
);
1005 Polyhedron_Free(pos
);
1006 Polyhedron_Free(neg
);
1011 } END_FORALL_PVertex_in_ParamPolyhedron
;
1014 } END_FORALL_PVertex_in_ParamPolyhedron
;
1017 /* Search for vertex coordinate to split on */
1018 /* First look for one independent of the parameters */
1019 FORALL_PVertex_in_ParamPolyhedron(V
, last
, PP
) {
1020 for (int i
= 0; i
< exist
; ++i
) {
1022 for (j
= 0; j
< nparam
; ++j
)
1023 if (value_notzero_p(V
->Vertex
->p
[i
][j
]))
1027 value_set_si(M
->p
[0][0], 1);
1028 Vector_Set(M
->p
[0]+1, 0, nvar
+exist
);
1029 Vector_Copy(V
->Vertex
->p
[i
],
1030 M
->p
[0] + 1 + nvar
+ exist
, nparam
+1);
1031 value_oppose(M
->p
[0][1+nvar
+i
],
1032 V
->Vertex
->p
[i
][nparam
+1]);
1034 Polyhedron
*pos
, *neg
;
1035 value_set_si(M
->p
[0][0], 1);
1036 value_decrement(M
->p
[0][P
->Dimension
+1],
1037 M
->p
[0][P
->Dimension
+1]);
1038 neg
= AddConstraints(M
->p
[0], 1, P
, options
->MaxRays
);
1039 value_set_si(f
, -1);
1040 Vector_Scale(M
->p
[0]+1, M
->p
[0]+1, f
,
1042 value_decrement(M
->p
[0][P
->Dimension
+1],
1043 M
->p
[0][P
->Dimension
+1]);
1044 value_decrement(M
->p
[0][P
->Dimension
+1],
1045 M
->p
[0][P
->Dimension
+1]);
1046 pos
= AddConstraints(M
->p
[0], 1, P
, options
->MaxRays
);
1047 POL_ENSURE_VERTICES(neg
);
1048 POL_ENSURE_VERTICES(pos
);
1049 if (emptyQ(neg
) || emptyQ(pos
)) {
1050 Polyhedron_Free(pos
);
1051 Polyhedron_Free(neg
);
1054 Polyhedron_Free(pos
);
1055 value_increment(M
->p
[0][P
->Dimension
+1],
1056 M
->p
[0][P
->Dimension
+1]);
1057 pos
= AddConstraints(M
->p
[0], 1, P
, options
->MaxRays
);
1059 fprintf(stderr
, "\nER: Vertex\n");
1060 #endif /* DEBUG_ER */
1062 EP
= enumerate_or(pos
, exist
, nparam
, options
);
1067 } END_FORALL_PVertex_in_ParamPolyhedron
;
1071 /* Search for vertex coordinate to split on */
1072 /* Now look for one that depends on the parameters */
1073 FORALL_PVertex_in_ParamPolyhedron(V
, last
, PP
) {
1074 for (int i
= 0; i
< exist
; ++i
) {
1075 value_set_si(M
->p
[0][0], 1);
1076 Vector_Set(M
->p
[0]+1, 0, nvar
+exist
);
1077 Vector_Copy(V
->Vertex
->p
[i
],
1078 M
->p
[0] + 1 + nvar
+ exist
, nparam
+1);
1079 value_oppose(M
->p
[0][1+nvar
+i
],
1080 V
->Vertex
->p
[i
][nparam
+1]);
1082 Polyhedron
*pos
, *neg
;
1083 value_set_si(M
->p
[0][0], 1);
1084 value_decrement(M
->p
[0][P
->Dimension
+1],
1085 M
->p
[0][P
->Dimension
+1]);
1086 neg
= AddConstraints(M
->p
[0], 1, P
, options
->MaxRays
);
1087 value_set_si(f
, -1);
1088 Vector_Scale(M
->p
[0]+1, M
->p
[0]+1, f
,
1090 value_decrement(M
->p
[0][P
->Dimension
+1],
1091 M
->p
[0][P
->Dimension
+1]);
1092 value_decrement(M
->p
[0][P
->Dimension
+1],
1093 M
->p
[0][P
->Dimension
+1]);
1094 pos
= AddConstraints(M
->p
[0], 1, P
, options
->MaxRays
);
1095 POL_ENSURE_VERTICES(neg
);
1096 POL_ENSURE_VERTICES(pos
);
1097 if (emptyQ(neg
) || emptyQ(pos
)) {
1098 Polyhedron_Free(pos
);
1099 Polyhedron_Free(neg
);
1102 Polyhedron_Free(pos
);
1103 value_increment(M
->p
[0][P
->Dimension
+1],
1104 M
->p
[0][P
->Dimension
+1]);
1105 pos
= AddConstraints(M
->p
[0], 1, P
, options
->MaxRays
);
1107 fprintf(stderr
, "\nER: ParamVertex\n");
1108 #endif /* DEBUG_ER */
1110 EP
= enumerate_or(pos
, exist
, nparam
, options
);
1115 } END_FORALL_PVertex_in_ParamPolyhedron
;
1123 Param_Polyhedron_Free(PP
);
1129 evalue
* barvinok_enumerate_pip(Polyhedron
*P
, unsigned exist
, unsigned nparam
,
1133 barvinok_options
*options
= barvinok_options_new_with_defaults();
1134 options
->MaxRays
= MaxRays
;
1135 E
= barvinok_enumerate_pip_with_options(P
, exist
, nparam
, options
);
1136 barvinok_options_free(options
);
1140 evalue
*barvinok_enumerate_pip_with_options(Polyhedron
*P
,
1141 unsigned exist
, unsigned nparam
, struct barvinok_options
*options
)
1143 int nvar
= P
->Dimension
- exist
- nparam
;
1144 evalue
*EP
= evalue_zero();
1148 fprintf(stderr
, "\nER: PIP\n");
1149 #endif /* DEBUG_ER */
1151 Polyhedron
*D
= pip_projectout(P
, nvar
, exist
, nparam
);
1152 for (Q
= D
; Q
; Q
= N
) {
1156 exist
= Q
->Dimension
- nvar
- nparam
;
1157 E
= barvinok_enumerate_e_with_options(Q
, exist
, nparam
, options
);
1166 evalue
*barvinok_enumerate_isl(Polyhedron
*P
,
1167 unsigned exist
, unsigned nparam
, struct barvinok_options
*options
)
1169 isl_ctx
*ctx
= isl_ctx_alloc();
1171 isl_basic_set
*bset
;
1173 evalue
*EP
= evalue_zero();
1174 Polyhedron
*D
, *Q
, *N
;
1175 Polyhedron
*U
= Universe_Polyhedron(nparam
);
1177 dims
= isl_dim_set_alloc(ctx
, nparam
, P
->Dimension
- nparam
- exist
);
1178 bset
= isl_basic_set_new_from_polylib(P
, dims
);
1180 set
= isl_basic_set_compute_divs(bset
);
1182 D
= isl_set_to_polylib(set
);
1183 for (Q
= D
; Q
; Q
= N
) {
1187 E
= barvinok_enumerate_with_options(Q
, U
, options
);
1200 static bool is_single(Value
*row
, int pos
, int len
)
1202 return First_Non_Zero(row
, pos
) == -1 &&
1203 First_Non_Zero(row
+pos
+1, len
-pos
-1) == -1;
1206 static evalue
* barvinok_enumerate_e_r(Polyhedron
*P
,
1207 unsigned exist
, unsigned nparam
, barvinok_options
*options
);
1210 static int er_level
= 0;
1212 evalue
* barvinok_enumerate_e_with_options(Polyhedron
*P
,
1213 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
1215 fprintf(stderr
, "\nER: level %i\n", er_level
);
1217 Polyhedron_PrintConstraints(stderr
, P_VALUE_FMT
, P
);
1218 fprintf(stderr
, "\nE %d\nP %d\n", exist
, nparam
);
1220 P
= DomainConstraintSimplify(Polyhedron_Copy(P
), options
->MaxRays
);
1221 evalue
*EP
= barvinok_enumerate_e_r(P
, exist
, nparam
, options
);
1227 evalue
* barvinok_enumerate_e_with_options(Polyhedron
*P
,
1228 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
1230 P
= DomainConstraintSimplify(Polyhedron_Copy(P
), options
->MaxRays
);
1231 evalue
*EP
= barvinok_enumerate_e_r(P
, exist
, nparam
, options
);
1237 evalue
* barvinok_enumerate_e(Polyhedron
*P
, unsigned exist
, unsigned nparam
,
1241 barvinok_options
*options
= barvinok_options_new_with_defaults();
1242 options
->MaxRays
= MaxRays
;
1243 E
= barvinok_enumerate_e_with_options(P
, exist
, nparam
, options
);
1244 barvinok_options_free(options
);
1248 static evalue
*universal_zero(unsigned nparam
)
1252 eres
= ALLOC(evalue
);
1253 value_init(eres
->d
);
1254 value_set_si(eres
->d
, 0);
1255 eres
->x
.p
= new_enode(partition
, 2, nparam
);
1256 EVALUE_SET_DOMAIN(eres
->x
.p
->arr
[0], Universe_Polyhedron(nparam
));
1257 value_set_si(eres
->x
.p
->arr
[1].d
, 1);
1258 value_init(eres
->x
.p
->arr
[1].x
.n
);
1263 static evalue
* barvinok_enumerate_e_r(Polyhedron
*P
,
1264 unsigned exist
, unsigned nparam
, barvinok_options
*options
)
1267 Polyhedron
*U
= Universe_Polyhedron(nparam
);
1268 evalue
*EP
= barvinok_enumerate_with_options(P
, U
, options
);
1269 //char *param_name[] = {"P", "Q", "R", "S", "T" };
1270 //print_evalue(stdout, EP, param_name);
1275 int nvar
= P
->Dimension
- exist
- nparam
;
1276 int len
= P
->Dimension
+ 2;
1279 POL_ENSURE_FACETS(P
);
1280 POL_ENSURE_VERTICES(P
);
1283 return evalue_zero();
1285 if (nvar
== 0 && nparam
== 0) {
1286 evalue
*EP
= universal_zero(nparam
);
1287 barvinok_count_with_options(P
, &EP
->x
.p
->arr
[1].x
.n
, options
);
1288 if (value_pos_p(EP
->x
.p
->arr
[1].x
.n
))
1289 value_set_si(EP
->x
.p
->arr
[1].x
.n
, 1);
1294 for (r
= 0; r
< P
->NbRays
; ++r
)
1295 if (value_zero_p(P
->Ray
[r
][0]) ||
1296 value_zero_p(P
->Ray
[r
][P
->Dimension
+1])) {
1298 for (i
= 0; i
< nvar
; ++i
)
1299 if (value_notzero_p(P
->Ray
[r
][i
+1]))
1303 for (i
= nvar
+ exist
; i
< nvar
+ exist
+ nparam
; ++i
)
1304 if (value_notzero_p(P
->Ray
[r
][i
+1]))
1306 if (i
>= nvar
+ exist
+ nparam
)
1309 if (r
< P
->NbRays
) {
1310 evalue
*EP
= universal_zero(nparam
);
1311 value_set_si(EP
->x
.p
->arr
[1].x
.n
, -1);
1316 for (r
= 0; r
< P
->NbEq
; ++r
)
1317 if ((first
= First_Non_Zero(P
->Constraint
[r
]+1+nvar
, exist
)) != -1)
1320 if (First_Non_Zero(P
->Constraint
[r
]+1+nvar
+first
+1,
1321 exist
-first
-1) != -1) {
1322 Polyhedron
*T
= rotate_along(P
, r
, nvar
, exist
, options
->MaxRays
);
1324 fprintf(stderr
, "\nER: Equality\n");
1325 #endif /* DEBUG_ER */
1326 evalue
*EP
= barvinok_enumerate_e_with_options(T
, exist
-1, nparam
,
1332 fprintf(stderr
, "\nER: Fixed\n");
1333 #endif /* DEBUG_ER */
1335 return barvinok_enumerate_e_with_options(P
, exist
-1, nparam
,
1338 Polyhedron
*T
= Polyhedron_Copy(P
);
1339 Polyhedron_ExchangeColumns(T
, nvar
+1, nvar
+1+first
);
1340 evalue
*EP
= barvinok_enumerate_e_with_options(T
, exist
-1, nparam
,
1348 Vector
*row
= Vector_Alloc(len
);
1349 value_set_si(row
->p
[0], 1);
1354 enum constraint
* info
= new constraint
[exist
];
1355 for (int i
= 0; i
< exist
; ++i
) {
1357 for (int l
= P
->NbEq
; l
< P
->NbConstraints
; ++l
) {
1358 if (value_negz_p(P
->Constraint
[l
][nvar
+i
+1]))
1360 bool l_parallel
= is_single(P
->Constraint
[l
]+nvar
+1, i
, exist
);
1361 for (int u
= P
->NbEq
; u
< P
->NbConstraints
; ++u
) {
1362 if (value_posz_p(P
->Constraint
[u
][nvar
+i
+1]))
1364 bool lu_parallel
= l_parallel
||
1365 is_single(P
->Constraint
[u
]+nvar
+1, i
, exist
);
1366 value_oppose(f
, P
->Constraint
[u
][nvar
+i
+1]);
1367 Vector_Combine(P
->Constraint
[l
]+1, P
->Constraint
[u
]+1, row
->p
+1,
1368 f
, P
->Constraint
[l
][nvar
+i
+1], len
-1);
1369 if (!(info
[i
] & INDEPENDENT
)) {
1371 for (j
= 0; j
< exist
; ++j
)
1372 if (j
!= i
&& value_notzero_p(row
->p
[nvar
+j
+1]))
1375 //printf("independent: i: %d, l: %d, u: %d\n", i, l, u);
1376 info
[i
] = (constraint
)(info
[i
] | INDEPENDENT
);
1379 if (info
[i
] & ALL_POS
) {
1380 value_addto(row
->p
[len
-1], row
->p
[len
-1],
1381 P
->Constraint
[l
][nvar
+i
+1]);
1382 value_addto(row
->p
[len
-1], row
->p
[len
-1], f
);
1383 value_multiply(f
, f
, P
->Constraint
[l
][nvar
+i
+1]);
1384 value_subtract(row
->p
[len
-1], row
->p
[len
-1], f
);
1385 value_decrement(row
->p
[len
-1], row
->p
[len
-1]);
1386 ConstraintSimplify(row
->p
, row
->p
, len
, &f
);
1387 value_set_si(f
, -1);
1388 Vector_Scale(row
->p
+1, row
->p
+1, f
, len
-1);
1389 value_decrement(row
->p
[len
-1], row
->p
[len
-1]);
1390 Polyhedron
*T
= AddConstraints(row
->p
, 1, P
, options
->MaxRays
);
1391 POL_ENSURE_VERTICES(T
);
1393 //printf("not all_pos: i: %d, l: %d, u: %d\n", i, l, u);
1394 info
[i
] = (constraint
)(info
[i
] ^ ALL_POS
);
1396 //puts("pos remainder");
1397 //Polyhedron_Print(stdout, P_VALUE_FMT, T);
1400 if (!(info
[i
] & ONE_NEG
)) {
1402 negative_test_constraint(P
->Constraint
[l
],
1404 row
->p
, nvar
+i
, len
, &f
);
1405 oppose_constraint(row
->p
, len
, &f
);
1406 Polyhedron
*T
= AddConstraints(row
->p
, 1, P
,
1408 POL_ENSURE_VERTICES(T
);
1410 //printf("one_neg i: %d, l: %d, u: %d\n", i, l, u);
1411 info
[i
] = (constraint
)(info
[i
] | ONE_NEG
);
1413 //puts("neg remainder");
1414 //Polyhedron_Print(stdout, P_VALUE_FMT, T);
1416 } else if (!(info
[i
] & ROT_NEG
)) {
1417 if (parallel_constraints(P
->Constraint
[l
],
1419 row
->p
, nvar
, exist
)) {
1420 negative_test_constraint7(P
->Constraint
[l
],
1422 row
->p
, nvar
, exist
,
1424 oppose_constraint(row
->p
, len
, &f
);
1425 Polyhedron
*T
= AddConstraints(row
->p
, 1, P
,
1427 POL_ENSURE_VERTICES(T
);
1429 // printf("rot_neg i: %d, l: %d, u: %d\n", i, l, u);
1430 info
[i
] = (constraint
)(info
[i
] | ROT_NEG
);
1433 //puts("neg remainder");
1434 //Polyhedron_Print(stdout, P_VALUE_FMT, T);
1439 if (!(info
[i
] & ALL_POS
) && (info
[i
] & (ONE_NEG
| ROT_NEG
)))
1443 if (info
[i
] & ALL_POS
)
1450 for (int i = 0; i < exist; ++i)
1451 printf("%i: %i\n", i, info[i]);
1453 for (int i
= 0; i
< exist
; ++i
)
1454 if (info
[i
] & ALL_POS
) {
1456 fprintf(stderr
, "\nER: Positive\n");
1457 #endif /* DEBUG_ER */
1459 // Maybe we should chew off some of the fat here
1460 Matrix
*M
= Matrix_Alloc(P
->Dimension
, P
->Dimension
+1);
1461 for (int j
= 0; j
< P
->Dimension
; ++j
)
1462 value_set_si(M
->p
[j
][j
+ (j
>= i
+nvar
)], 1);
1463 Polyhedron
*T
= Polyhedron_Image(P
, M
, options
->MaxRays
);
1465 evalue
*EP
= barvinok_enumerate_e_with_options(T
, exist
-1, nparam
,
1473 for (int i
= 0; i
< exist
; ++i
)
1474 if (info
[i
] & ONE_NEG
) {
1476 fprintf(stderr
, "\nER: Negative\n");
1477 #endif /* DEBUG_ER */
1482 return barvinok_enumerate_e_with_options(P
, exist
-1, nparam
,
1485 Polyhedron
*T
= Polyhedron_Copy(P
);
1486 Polyhedron_ExchangeColumns(T
, nvar
+1, nvar
+1+i
);
1487 evalue
*EP
= barvinok_enumerate_e_with_options(T
, exist
-1, nparam
,
1493 for (int i
= 0; i
< exist
; ++i
)
1494 if (info
[i
] & ROT_NEG
) {
1496 fprintf(stderr
, "\nER: Rotate\n");
1497 #endif /* DEBUG_ER */
1501 Polyhedron
*T
= rotate_along(P
, r
, nvar
, exist
, options
->MaxRays
);
1502 evalue
*EP
= barvinok_enumerate_e_with_options(T
, exist
-1, nparam
,
1507 for (int i
= 0; i
< exist
; ++i
)
1508 if (info
[i
] & INDEPENDENT
) {
1509 Polyhedron
*pos
, *neg
;
1511 /* Find constraint again and split off negative part */
1513 if (SplitOnVar(P
, i
, nvar
, exist
, options
->MaxRays
,
1514 row
, f
, true, &pos
, &neg
)) {
1516 fprintf(stderr
, "\nER: Split\n");
1517 #endif /* DEBUG_ER */
1520 barvinok_enumerate_e_with_options(neg
, exist
-1, nparam
, options
);
1522 barvinok_enumerate_e_with_options(pos
, exist
, nparam
, options
);
1525 Polyhedron_Free(neg
);
1526 Polyhedron_Free(pos
);
1540 EP
= enumerate_line(P
, exist
, nparam
, options
);
1544 EP
= barvinok_enumerate_pip_with_options(P
, exist
, nparam
, options
);
1548 EP
= enumerate_redundant_ray(P
, exist
, nparam
, options
);
1552 EP
= enumerate_sure(P
, exist
, nparam
, options
);
1556 EP
= enumerate_ray(P
, exist
, nparam
, options
);
1560 EP
= enumerate_sure2(P
, exist
, nparam
, options
);
1564 F
= unfringe(P
, options
->MaxRays
);
1565 if (!PolyhedronIncludes(F
, P
)) {
1567 fprintf(stderr
, "\nER: Fringed\n");
1568 #endif /* DEBUG_ER */
1569 EP
= barvinok_enumerate_e_with_options(F
, exist
, nparam
, options
);
1576 EP
= enumerate_vd(&P
, exist
, nparam
, options
);
1581 EP
= enumerate_sum(P
, exist
, nparam
, options
);
1588 Polyhedron
*pos
, *neg
;
1589 for (i
= 0; i
< exist
; ++i
)
1590 if (SplitOnVar(P
, i
, nvar
, exist
, options
->MaxRays
,
1591 row
, f
, false, &pos
, &neg
))
1597 EP
= enumerate_or(pos
, exist
, nparam
, options
);