setTreeNodes UnorderedTree::TreeComponents(TreeNodes *t,bool bCanonical=false){ //Returns the components ( subtree of next level) of a tree setTreeNodes setTreeComponents; //Insert into a set, the components TreeNodes::iterator itTreeNodes; Integer level=(*t)[0]; TreeNodes component; itTreeNodes=t->begin(); int i=0; bool blnend=false; while(i<t->size() &&itTreeNodes!=t->end()) { //The components start at level 0, the canonical form no if (*itTreeNodes!=level) component.push_back( (*itTreeNodes)-(bCanonical ? 0 :level)); ++itTreeNodes;i++; if (itTreeNodes==t->end()) blnend=true; else if((*itTreeNodes)<= level+1 ) blnend=true; if (blnend==true){ blnend=false; if(component.size()>0){ setTreeComponents.insert(bCanonical ? CanonicalForm(component): component ); component.clear(); } } } return setTreeComponents; }
TreeNodes UnorderedTree::SubtreeAtNode(TreeNodes *supertree,Integer *iNode){ //Outputs the bigest bottom subtree rooted at iNode TreeNodes tn; int i=*iNode; int v=(*supertree)[i].depth; int init_depth=v; do { tn.push_back(Node(v-init_depth,(*supertree)[i].label)); i++; v=(*supertree)[i].depth; } while (v-init_depth>0 && i<supertree->size() ); return CanonicalForm(tn); }
/* * Given a Z-polyhderon 'A' and a Z-domain 'Head', return a new Z-domain with * 'A' added to it. If the new Z-polyhedron 'A', is already included in the * Z-domain 'Head', it is not added in the list. Othewise, the function checks * if the new Z-polyhedron 'A' to be added to the Z-domain 'Head' has a common * lattice with some other Z-polyhderon already present in the Z-domain. If it * is so, it takes the union of the underlying polyhdera; domains and returns. * The function tries to make sure that the added Z-polyhedron 'A' is in the * canonical form. */ static ZPolyhedron *AddZPolytoZDomain(ZPolyhedron *A, ZPolyhedron *Head) { ZPolyhedron *Zpol, *temp, *temp1; Polyhedron *i; Bool Added; if ((A == NULL) || (isEmptyZPolyhedron(A))) return Head; /* For each "underlying" Pol, find the Cnf and add Zpol in Cnf*/ for(i=A->P; i!= NULL; i=i->next) { ZPolyhedron *Z, *Z1; Polyhedron *Image; Matrix *H, *U; Lattice *Lat ; Added = False; Image = Domain_Copy(i); Domain_Free(Image->next); Image->next = NULL; Z1 = ZPolyhedron_Alloc(A->Lat,Image); Domain_Free(Image); CanonicalForm(Z1,&Z,&H); ZDomain_Free(Z1); Lat = (Lattice *)Matrix_Alloc(H->NbRows,Z->Lat->NbColumns); Matrix_Product(H,Z->Lat,(Matrix *)Lat); Matrix_Free(H); AffineHermite(Lat,(Lattice **)&H,&U); Image = DomainImage(Z->P,U,MAXNOOFRAYS); ZDomain_Free(Z); Zpol=ZPolyhedron_Alloc((Lattice *)H,Image); Domain_Free(Image); Matrix_Free((Matrix *)Lat); Matrix_Free(H); Matrix_Free(U); if ((Head == NULL) || (isEmptyZPolyhedron (Head))) { Head = Zpol; continue; } temp1 = temp = Head; /* Check if the curr pol is included in the zpol or vice versa. */ for(; temp != NULL; temp = temp->next) { if (ZPolyhedronIncludes(Zpol, temp) == True) { ZPolyhedron_Free (Zpol); Added = True; break; } else if (ZPolyhedronIncludes(temp, Zpol) == True) { if (temp == Head) { Zpol->next = temp->next; Head = Zpol; ZPolyhedron_Free (temp); Added = True; break; } temp1->next = Zpol; Zpol->next = temp->next; ZPolyhedron_Free (temp); Added = True; break ; } temp1 = temp ; } if(Added == True) continue ; for(temp = Head; temp != NULL; temp = temp->next) { if(sameLattice(temp->Lat, Zpol->Lat) == True) { Polyhedron *Union; Union = DomainUnion (temp->P,Zpol->P,MAXNOOFRAYS); if (!Union) fprintf (stderr,"\n In AddZPolytoZDomain: Out of memory\n"); else { Domain_Free(temp->P); temp->P = Union; Added = True; ZPolyhedron_Free(Zpol); } break ; } temp1 = temp; } if (Added == False) temp1->next = Zpol; } return Head ; } /* AddZPolytoZDomain */