Changeset 68eb0c in git
- Timestamp:
- Mar 6, 2010, 6:09:52 PM (13 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- 5151ac95d6e9778dc832b31c28c9649d358d1b0c
- Parents:
- 51346c4ca4b934458da6e3ad84176f094bfd5caa
- Location:
- kernel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/gfan.cc
r51346c4 r68eb0c 77 77 //NOTE Defining this will slow things down! 78 78 //Only good for very coarse profiling 79 #define gfanp79 // #define gfanp 80 80 #ifdef gfanp 81 81 #include <sys/time.h> … … 206 206 this->next=NULL; 207 207 this->flipGB=NULL; 208 // delete this;208 // delete(this); 209 209 } 210 210 … … 226 226 if(codim2Ptr->fNormal!=NULL) 227 227 { 228 delete codim2Ptr->fNormal; 228 delete codim2Ptr->fNormal;//NOTE Do not want this anymore since the rays are now in gcone! 229 229 codim2Ptr = codim2Ptr->next; 230 230 } … … 232 232 // delete this->codim2Ptr; 233 233 } 234 if(this->codim2Ptr!=NULL) 235 delete this->codim2Ptr; 234 //The rays are stored in the cone! 235 // if(this->codim2Ptr!=NULL) 236 // delete this->codim2Ptr; 236 237 if(this->flipGB!=NULL) 237 238 idDelete((ideal *)&this->flipGB); … … 562 563 this->numFacets=0; 563 564 this->ivIntPt=NULL; 565 this->gcRays=NULL; 564 566 } 565 567 … … 587 589 this->numFacets=0; 588 590 this->ivIntPt=NULL; 591 this->gcRays=NULL; 589 592 } 590 593 … … 609 612 this->numFacets=0; 610 613 this->ivIntPt=NULL; 614 this->gcRays=NULL; 611 615 } 612 616 … … 649 653 // dd_FreeMatrix(this->ddFacets); 650 654 //dd_FreeMatrix(this->ddFacets); 655 for(int ii=0;ii<this->numRays;ii++) 656 delete(gcRays[ii]); 657 omFree(gcRays); 651 658 } 652 659 … … 1435 1442 /* Compute interior point on the fly*/ 1436 1443 intvec *ivIntPointOfCone = new intvec(this->numVars); 1437 // for(int ii=0;ii<P->rowsize;ii++)1438 // {}1439 1444 mpq_t *colSum = new mpq_t[this->numVars]; 1440 1445 int denom[this->numVars];//denominators of colSum … … 1528 1533 int rows=P->rowsize; 1529 1534 facet *fAct=gc.facetPtr; 1535 //Construct an array to hold the extremal rays of the cone 1536 this->gcRays = (intvec**)omAlloc0(sizeof(intvec*)*P->rowsize); 1537 for(int ii=0;ii<P->rowsize;ii++) 1538 { 1539 intvec *rowvec = new intvec(this->numVars); 1540 makeInt(P,ii+1,*rowvec);//get an integer entry instead of rational, rowvec is primitve 1541 this->gcRays[ii] = ivCopy(rowvec); 1542 delete rowvec; 1543 } 1544 this->numRays=P->rowsize; 1545 //Check which rays belong to which facet 1530 1546 while(fAct!=NULL) 1531 1547 { … … 1535 1551 for(int ii=0;ii<rows;ii++) 1536 1552 { 1537 intvec *rowvec = new intvec(this->numVars); 1538 makeInt(P,ii+1,*rowvec);//get an integer entry instead of rational, rowvec is primitve 1539 if(dotProduct(*fNormal,*rowvec)==0) 1553 if(dotProduct(*fNormal,this->gcRays[ii])==0) 1540 1554 { 1541 1555 intvec *tmp = ivIntPointOfFacet;//Prevent memleak … … 1552 1566 codim2Act = codim2Act->next; 1553 1567 } 1554 codim2Act->setFacetNormal(rowvec); 1555 fAct->numRays++; 1556 //TODO Add up to interior point here! 1557 //Memleak sinve ivAdd returns a new intvec 1558 ivIntPointOfFacet=ivAdd(ivIntPointOfFacet,rowvec); 1559 //Now tmp still points to the OLD address of ivIntPt 1568 //codim2Act->setFacetNormal(rowvec); 1569 //Rather just let codim2Act point to the corresponding intvec of gcRays 1570 codim2Act->fNormal=this->gcRays[ii]; 1571 fAct->numRays++; 1572 //Memleak avoided via tmp 1573 ivIntPointOfFacet=ivAdd(ivIntPointOfFacet,this->gcRays[ii]); 1574 //Now tmp still points to the OLD address of ivIntPointOfFacet 1560 1575 delete(tmp); 1561 1576 1562 1577 } 1563 delete(rowvec);1564 1578 }//For non-homog input ivIntPointOfFacet should already be >0 here 1565 1579 if(!hasHomInput) {assert(iv64isStrictlyPositive(ivIntPointOfFacet));} … … 1571 1585 for(int ii=0;ii<this->numVars;ii++) 1572 1586 (*ivOne)[ii]=1; 1573 // intvec *diff = new intvec(this->numVars);1574 // diff=ivSub(ivIntPointOfFacet,ivOne);1575 1587 while( !iv64isStrictlyPositive(ivIntPointOfFacet) ) 1576 1588 { … … 1579 1591 { 1580 1592 (*ivOne)[jj] = (*ivOne)[jj] << 1; //times 2 1581 // (*diff)[jj]= (*diff)[jj] << 1;1582 1593 } 1583 1594 ivIntPointOfFacet = ivAdd(ivIntPointOfFacet/*diff*/,ivOne); 1584 1595 delete tmp; 1585 1596 } 1586 //fAct->setInteriorPoint(ivIntPointOfFacet);1587 1597 delete ivOne; 1588 1598 } 1589 //else1590 1599 int ggT=(*ivIntPointOfFacet)[0]; 1591 1600 for(int ii=0;ii<this->numVars;ii++) … … 1639 1648 // delete fNormal; 1640 1649 fAct = fAct->next; 1641 } 1650 }//end of facet checking 1642 1651 dd_FreeMatrix(P); 1643 1652 //Now all extremal rays should be set w.r.t their respective fNormal … … 2449 2458 * 2450 2459 */ 2451 // inline int gcone::dotProduct(intvec &iva, intvec &ivb)2452 // {2453 // int res=0;2454 // for (int i=0;i<this->numVars;i++)2455 // {2456 // res = res+(iva[i]*ivb[i]);2457 // }2458 // return res;2459 // }//int dotProduct2460 2460 inline int gcone::dotProduct(const intvec &iva, const intvec &ivb) 2461 2461 { … … 2499 2499 return res; 2500 2500 }//bool isParallel 2501 // inline int gcone::dotProduct(const intvec *a, const intvec *b) 2502 // { 2503 // int res=0; 2504 // for (int i=0;i<this->numVars;i++) 2505 // { 2506 // res = res+((*a)[i]*(*b)[i]); 2507 // } 2508 // return res; 2509 // }//int dotProduct 2510 // inline bool gcone::isParallel(const intvec* a, const intvec* b) 2511 // { 2512 // int lhs,rhs; 2513 // bool res; 2514 // lhs=dotProduct(a,b)*dotProduct(a,b); 2515 // rhs=dotProduct(a,a)*dotProduct(b,b); 2516 // //cout << "LHS="<<lhs<<", RHS="<<rhs<<endl; 2517 // if (lhs==rhs) 2518 // { 2519 // res = TRUE; 2520 // } 2521 // else 2522 // { 2523 // res = FALSE; 2524 // } 2525 // return res; 2526 // } 2501 2527 2502 /** \brief Compute an interior point of a given cone 2528 2503 * Result will be written into intvec iv. … … 2792 2767 mpz_clear(kgV); 2793 2768 mpq_clear(qkgV); mpq_clear(res); 2794 2795 /***************************************************/2796 // //We need to find out if there are at least two pos rays2797 // facet *f1 = this->facetPtr;2798 // facet *f2 = NULL;2799 // intvec *intF1=NULL;2800 // intvec *intF2=NULL;2801 // while(f1!=NULL)2802 // {2803 // if(f1->isFlippable)2804 // {2805 // facet *f1Ray=f1->codim2Ptr;2806 // while(f1Ray!=NULL)2807 // {2808 // intvec *check = f1Ray->getFacetNormal();2809 // if(iv64isStrictlyPositive(check))2810 // {2811 // intF1=ivCopy(check);2812 // delete check;2813 // break;2814 // }2815 // delete check;2816 // f1Ray = f1Ray->next;2817 // }2818 // }2819 // if(intF1!=NULL)//We have found the first strictly positive ray2820 // break;2821 // f1 = f1->next;2822 // }2823 // if(f1->next!=NULL)2824 // f2=f1->next;2825 // while(f2!=NULL)2826 // {2827 // if(f2->isFlippable)2828 // {2829 // facet *f2Ray=f2->codim2Ptr;2830 // while(f2Ray!=NULL)2831 // {2832 // intvec *check = f2Ray->getFacetNormal();2833 // if(iv64isStrictlyPositive(check))2834 // {2835 // //and not equal to intF12836 // if(check->compare(intF1)!=0)//we found a distinct 2nd ray2837 // {2838 // intF2=ivCopy(check);2839 // delete check;2840 // }2841 // break;2842 // }2843 // delete check;2844 // f2Ray = f2Ray->next;2845 // }2846 // }2847 // if(intF2!=NULL)2848 // break;2849 // f2=f2->next;2850 // }2851 // if(intF2==NULL)//do some linear algebra2852 // {2853 // f2=f1->next;2854 // intvec *arbitraryRay = f2->codim2Ptr->getFacetNormal();2855 // //Now add2856 // intvec *ivSum = ivAdd(intF1, arbitraryRay);2857 // while(iv64isStrictlyPositive(ivSum)==FALSE)2858 // {2859 // intvec *tmp = intF1;2860 // for(int ii=0;ii<this->numVars;ii++)2861 // (*intF1)[ii] = (*intF1)[ii] << 1; //times 22862 // intF1 = ivAdd(intF1,ivSum);2863 // delete tmp;2864 //2865 // }2866 // this->setIntPoint(ivSum);2867 //2868 // }2869 // else //just add intF1+intF22870 // {2871 // intvec *sum = ivAdd(intF1, intF2);2872 // this->setIntPoint(sum);2873 // delete sum;2874 // }2875 /***************************************************/2876 // //Find 1st flippable facet2877 // facet *f1 = this->facetPtr;2878 // facet *f2 = NULL; //idPrint(this->gcBasis);2879 // intvec *intF1=NULL;2880 // intvec *intF2=NULL;2881 // while(f1->isFlippable==FALSE && f1!=NULL)2882 // f1=f1->next;2883 // if(f1!=NULL)2884 // {2885 // intF1 = f1->getInteriorPoint();2886 // f2 = f1->next;2887 // }2888 // while(f2!=NULL && f2->isFlippable==FALSE)2889 // f2=f2->next;2890 // if(f1==NULL || f2==NULL) //Is there only one flippable facet?2891 // { //f1==NULL would mean there ain't any flippable facet...2892 // /*If f2==NULL we ignore f2 and try to find an int point2893 // * using f1 and linear algebra2894 // */2895 // bool foundIntPoint=FALSE;2896 // intvec *f1Ray=f1->codim2Ptr->getFacetNormal();2897 // const intvec *fNormal=f1->getRef2FacetNormal();2898 // while(foundIntPoint==FALSE)2899 // {2900 // intvec *res;// = new intvec(this->numVars);2901 // res = ivAdd(const_cast<intvec*>(fNormal), f1Ray);2902 // int posCtr=0; //Count the pos entries of res2903 // for(int ii=0;ii<this->numVars;ii++)2904 // {2905 // if( (*res)[ii]>0)2906 // posCtr++;2907 // }2908 // if(posCtr==this->numVars)2909 // {2910 // foundIntPoint=TRUE;2911 // this->setIntPoint(res);2912 // }2913 // else2914 // {2915 // for(int ii=0;ii<this->numVars;ii++)2916 // (*f1Ray)[ii] = ((*f1Ray)[ii]) << 1;2917 // }2918 // delete res;2919 // }2920 // //Now we should have an int point2921 // delete f1Ray;2922 // }2923 // else //ok, we have two flippable facets2924 // {2925 // intF2=f2->getInteriorPoint();2926 // mpq_t *ratIntPt = new mpq_t[this->numVars];2927 // for(int ii=0;ii<this->numVars;ii++)2928 // mpq_init(ratIntPt[ii]);2929 // for(int ii=0;ii<this->numVars;ii++)2930 // {2931 // mpq_t a,b;2932 // mpq_init(a); mpq_init(b);2933 // mpq_set_si(a,(*intF1)[ii],1);2934 // mpq_set_si(b,(*intF2)[ii],1);2935 // mpq_t diff;2936 // mpq_init(diff);2937 // mpq_sub(diff,a,b); //diff=a-b2938 // mpq_t quot;2939 // mpq_init(quot);2940 // mpq_div_2exp(quot,diff,1); //quot=diff/2=(a-b)/22941 // mpq_clear(diff);2942 // //Don't be clever and reuse diff here2943 // mpq_t sum; mpq_init(sum);2944 // mpq_add(sum,b,quot); //sum=b+quot=b+(a-b)/22945 // mpq_set(ratIntPt[ii],sum);2946 // mpq_clear(sum);2947 // mpq_clear(quot);2948 // mpq_clear(a); mpq_clear(b);2949 // }2950 // /*Compute lcm of the denominators*/2951 // mpz_t *denom = new mpz_t[this->numVars];2952 // mpz_t tmp,kgV;2953 // mpz_init(tmp); mpz_init(kgV);2954 // for (int ii=0;ii<this->numVars;ii++)2955 // {2956 // mpz_t z;2957 // mpz_init(z);2958 // mpq_get_den(z,ratIntPt[ii]);2959 // mpz_init(denom[ii]);2960 // mpz_set( denom[ii], z);2961 // mpz_clear(z);2962 // }2963 //2964 // mpz_set(tmp,denom[0]);2965 // for (int ii=0;ii<this->numVars;ii++)2966 // {2967 // mpz_lcm(kgV,tmp,denom[ii]);2968 // mpz_set(tmp,kgV);2969 // }2970 // mpz_clear(tmp);2971 // /*Multiply the nominators by kgV*/2972 // mpq_t qkgV,res;2973 // mpq_init(qkgV);2974 // /*mpq_set_str(qkgV,"1",10);*/2975 // mpq_canonicalize(qkgV);2976 //2977 // mpq_init(res);2978 // /*mpq_set_str(res,"1",10);*/2979 // mpq_canonicalize(res);2980 //2981 // mpq_set_num(qkgV,kgV);2982 // intvec *n=new intvec(this->numVars);2983 // for (int ii=0;ii<this->numVars;ii++)2984 // {2985 // mpq_canonicalize(ratIntPt[ii]);mpq_mul(res,qkgV,ratIntPt[ii]);2986 // (*n)[ii]=(int)mpz_get_d(mpq_numref(res));2987 // }2988 // this->setIntPoint(n);2989 // delete n;2990 // delete [] ratIntPt;2991 // delete [] denom;2992 // mpz_clear(kgV);2993 // mpq_clear(qkgV); mpq_clear(res);2994 // }2995 2769 } 2996 2770 … … 3962 3736 cout << "Removing (";fAct->fNormal->show(1,1);cout << ") from list" << endl; 3963 3737 #endif 3964 marker->shallowDelete();3738 // marker->shallowDelete(); 3965 3739 // delete(marker); 3966 3740 break; -
kernel/gfan.h
r51346c4 r68eb0c 75 75 facet *codim2Ptr; //Pointer to (codim-2)-facet. Bit of recursion here ;-) 76 76 int numCodim2Facets; //#of (codim-2)-facets of this facet. Set in getCodim2Normals() 77 unsigned numRays; //Number of spanning rays of the cone77 unsigned numRays; //Number of spanning rays of the facet 78 78 ring flipRing; //the ring on the other side of the facet 79 79 … … 84 84 /** The copy constructor */ 85 85 facet(const facet& f); 86 /** A shallow copy of facets*/ 86 87 facet* shallowCopy(const facet& f); 87 88 void shallowDelete(); … … 94 95 /** Stores the facet normal \param intvec*/ 95 96 inline void setFacetNormal(intvec *iv); 96 /** Hopefully returns the facet normal */97 /** Returns the facet normal */ 97 98 inline intvec *getFacetNormal(); 98 99 /** Return a reference to the facet normal*/ … … 189 190 dd_MatrixPtr ddFacets; //Matrix to store irredundant facets of the cone 190 191 192 /** Array of intvecs representing the rays of the cone*/ 193 intvec **gcRays; 194 unsigned numRays; //#rays of the cone 191 195 /** Contains the Groebner basis of the cone. Is set by gcone::getGB(ideal I)*/ 192 196 ideal gcBasis; //GB of the cone, set by gcone::getGB();
Note: See TracChangeset
for help on using the changeset viewer.