From 456d0c5e24b3278071c3f88dbd3864b3b0c4aef4 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 12 Apr 2007 18:11:07 +0200 Subject: [PATCH] reduce_domain: exploit that no caller uses Polyhedron2Param_SimplifiedDomain --- barvinok.cc | 8 ++++---- lexmin.cc | 5 ++--- reduce_domain.c | 40 +++++++--------------------------------- reduce_domain.h | 10 ++++------ scale.c | 8 ++++---- volume.c | 4 ++-- 6 files changed, 23 insertions(+), 52 deletions(-) diff --git a/barvinok.cc b/barvinok.cc index 01efbf0..ae95f58 100644 --- a/barvinok.cc +++ b/barvinok.cc @@ -1802,8 +1802,8 @@ try_again: et = enumerator_base::create(P, dim, PP->nbV, options); - Polyhedron *TC = true_context(P, NULL, C, options->MaxRays); - FORALL_REDUCED_DOMAIN(PP, TC, NULL, NULL, nd, options, i, D, rVD) + Polyhedron *TC = true_context(P, C, options->MaxRays); + FORALL_REDUCED_DOMAIN(PP, TC, nd, options, i, D, rVD) Param_Vertices *V; value_init(s[i].E.d); @@ -2715,8 +2715,8 @@ static evalue* enumerate_vd(Polyhedron **PA, ; Polyhedron **VD = new Polyhedron_p[nd]; - Polyhedron *TC = true_context(P, NULL, C, options->MaxRays); - FORALL_REDUCED_DOMAIN(PP, TC, NULL, C, nd, options, i, D, rVD) + Polyhedron *TC = true_context(P, C, options->MaxRays); + FORALL_REDUCED_DOMAIN(PP, TC, nd, options, i, D, rVD) VD[nd++] = rVD; last = D; END_FORALL_REDUCED_DOMAIN diff --git a/lexmin.cc b/lexmin.cc index bdf3132..fa5cbe0 100644 --- a/lexmin.cc +++ b/lexmin.cc @@ -2681,9 +2681,8 @@ static vector lexmin(Polyhedron *P, Polyhedron *C, construct_rational_vertices(PP, T, T ? T->NbRows-nparam-1 : dim, nparam, all_vertices); - Polyhedron *TC = true_context(P, NULL, C, options->verify.barvinok->MaxRays); - FORALL_REDUCED_DOMAIN(PP, TC, NULL, NULL, nd, options->verify.barvinok, - i, D, rVD) + Polyhedron *TC = true_context(P, C, options->verify.barvinok->MaxRays); + FORALL_REDUCED_DOMAIN(PP, TC, nd, options->verify.barvinok, i, D, rVD) Param_Vertices *V; EDomain *epVD = new EDomain(rVD); diff --git a/reduce_domain.c b/reduce_domain.c index 5616db8..db174b1 100644 --- a/reduce_domain.c +++ b/reduce_domain.c @@ -2,15 +2,11 @@ #include #include "reduce_domain.h" -Polyhedron *true_context(Polyhedron *P, Matrix *CT, - Polyhedron *C, unsigned MaxRays) +Polyhedron *true_context(Polyhedron *P, Polyhedron *C, unsigned MaxRays) { - unsigned nparam = CT ? CT->NbRows - 1 : C->Dimension; + unsigned nparam = C->Dimension; Polyhedron *tmp = Polyhedron_Project(P, nparam); - Polyhedron *D = CT ? DomainPreimage(tmp, CT, MaxRays) : tmp; - C = DomainIntersection(D, C, MaxRays); - if (CT) - Polyhedron_Free(D); + C = DomainIntersection(tmp, C, MaxRays); Polyhedron_Free(tmp); return C; } @@ -72,19 +68,16 @@ int is_internal(Vector *point, Value *constraint) return value_pos_p(constraint[1+p]); } -Polyhedron *reduce_domain(Polyhedron *D, Matrix *CT, Polyhedron *CEq, int nd, +Polyhedron *reduce_domain(Polyhedron *D, int nd, Vector *inner, struct barvinok_options *options) { - Polyhedron *Dt, *rVD; - Polyhedron *C; + Polyhedron *rVD; Value c; int i; Matrix *constraints; int changed; - C = D->next ? DomainConvex(D, options->MaxRays) : D; - Dt = CT ? DomainPreimage(C, CT, options->MaxRays) : C; - rVD = CEq ? DomainIntersection(Dt, CEq, options->MaxRays) : Domain_Copy(Dt); + rVD = D->next ? DomainConvex(D, options->MaxRays) : Polyhedron_Copy(D); /* If there is only one chamber, then we don't need to take care * of possible overlaps. @@ -92,26 +85,10 @@ Polyhedron *reduce_domain(Polyhedron *D, Matrix *CT, Polyhedron *CEq, int nd, * and then some of the assumptions used in determining whether * the domain is too small in geometric dimension no longer apply. */ - if (nd == 1) - goto done; - - /* if rVD is empty or too small in geometric dimension */ - if(!rVD || emptyQ(rVD) || - (CEq && rVD->Dimension-rVD->NbEq < Dt->Dimension-Dt->NbEq-CEq->NbEq)) { - if (rVD) - Domain_Free(rVD); - rVD = NULL; /* empty validity domain */ -done: - if (D->next) - Polyhedron_Free(C); - if (CT) - Domain_Free(Dt); + if (nd == 1) { return rVD; } - if (CT) - Domain_Free(Dt); - assert(rVD->Dimension == inner->Size-2); constraints = Polyhedron2Constraints(rVD); changed = 0; @@ -128,9 +105,6 @@ done: } Matrix_Free(constraints); - if (D->next) - Polyhedron_Free(C); - rVD = DomainConstraintSimplify(rVD, options->MaxRays); POL_ENSURE_FACETS(rVD); if (emptyQ(rVD)) { diff --git a/reduce_domain.h b/reduce_domain.h index 7ca95e6..361895e 100644 --- a/reduce_domain.h +++ b/reduce_domain.h @@ -6,17 +6,16 @@ extern "C" { struct barvinok_options; -Polyhedron *true_context(Polyhedron *P, Matrix *CT, - Polyhedron *C, unsigned MaxRays); +Polyhedron *true_context(Polyhedron *P, Polyhedron *C, unsigned MaxRays); Vector *inner_point(Polyhedron *P); int is_internal(Vector *point, Value *constraint); -Polyhedron *reduce_domain(Polyhedron *D, Matrix *CT, Polyhedron *CEq, int nd, +Polyhedron *reduce_domain(Polyhedron *D, int nd, Vector *inner, struct barvinok_options *options); #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type)) -#define FORALL_REDUCED_DOMAIN(PP,C,CT,CEq,nd,options,i,D,rVD) \ +#define FORALL_REDUCED_DOMAIN(PP,C,nd,options,i,D,rVD) \ do { \ Param_Domain *D; \ Polyhedron *rVD; \ @@ -26,8 +25,7 @@ Polyhedron *reduce_domain(Polyhedron *D, Matrix *CT, Polyhedron *CEq, int nd, if (nd < 0) \ for (nd = 0, D = PP->D; D; ++nd, D = D->next); \ for (i = 0, D = PP->D; D; D = _frd_next) { \ - rVD = reduce_domain(D->Domain, CT, CEq, nd, \ - _frd_inner, options); \ + rVD = reduce_domain(D->Domain, nd, _frd_inner, options); \ _frd_next = D->next; \ if (!rVD) \ continue; \ diff --git a/scale.c b/scale.c index 67db6cb..b549ca5 100644 --- a/scale.c +++ b/scale.c @@ -640,9 +640,9 @@ static evalue *enumerate_narrow_flated(Polyhedron *P, Polyhedron *C, if ((options->scale_flags & BV_APPROX_SCALE_CHAMBER) && PP->D->next) { int nd = -1; evalue *tmp, *eres = NULL; - Polyhedron *TC = true_context(P, NULL, C, options->MaxRays); + Polyhedron *TC = true_context(P, C, options->MaxRays); - FORALL_REDUCED_DOMAIN(PP, TC, NULL, NULL, nd, options, i, D, rVD) + FORALL_REDUCED_DOMAIN(PP, TC, nd, options, i, D, rVD) Polyhedron *P2, *CA; /* Intersect with D->Domain, so we only have the relevant constraints * left. Don't use rVD, though, since we still want to recognize @@ -706,9 +706,9 @@ evalue *scale(Param_Polyhedron *PP, Polyhedron *P, Polyhedron *C, if ((options->scale_flags & BV_APPROX_SCALE_CHAMBER) && PP->D->next) { int nd = -1; evalue *tmp; - Polyhedron *TC = true_context(P, NULL, C, options->MaxRays); + Polyhedron *TC = true_context(P, C, options->MaxRays); - FORALL_REDUCED_DOMAIN(PP, TC, NULL, NULL, nd, options, i, D, rVD) + FORALL_REDUCED_DOMAIN(PP, TC, nd, options, i, D, rVD) Param_Polyhedron *PP_D = Param_Polyhedron_Domain(PP, D, rVD); tmp = scale(PP_D, P, rVD, options); if (!eres) diff --git a/volume.c b/volume.c index 1fdd957..86103ef 100644 --- a/volume.c +++ b/volume.c @@ -609,7 +609,7 @@ evalue* Param_Polyhedron_Volume(Polyhedron *P, Polyhedron* C, return vol; } - TC = true_context(P, NULL, C, options->MaxRays); + TC = true_context(P, C, options->MaxRays); if (PP_MaxRays & POL_NO_DUAL) PP_MaxRays = 0; @@ -629,7 +629,7 @@ evalue* Param_Polyhedron_Volume(Polyhedron *P, Polyhedron* C, for (i = 0; i < nvar+1; ++i) matrix[i] = ALLOCN(evalue *, nvar); - FORALL_REDUCED_DOMAIN(PP, TC, NULL, NULL, nd, options, i, D, rVD) + FORALL_REDUCED_DOMAIN(PP, TC, nd, options, i, D, rVD) Polyhedron *CA, *F; struct parameter_point *point; -- 2.11.4.GIT