Changeset 1f3450 in git


Ignore:
Timestamp:
Feb 5, 2010, 6:02:12 PM (14 years ago)
Author:
Martin Monerjan
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
b086f1d24cfeb668d2a93ab34efd9d448c31be12
Parents:
55587862408d1e92ee43d342befb2d834ea91635
Message:
Fixed rebuilding of rings in readConeFromFile()
Fixed memleak in normalize
SIZEOF_LONG==8 preprocessor checks
Minor change in gcone::~gcone rDelete(this->baseRing)
Bugfix in kernel computation
rDelete(gcTmp->baseRing) and rDelete(gcDel->baseRing) in noRevS
general cleanup


git-svn-id: file:///usr/local/Singular/svn/trunk@12519 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/gfan.cc

    r555878 r1f3450  
    174174        /* Cleanup the codim2-structure */
    175175        if(this->codim==2)
     176//      if(this->codim2Ptr!=NULL)
    176177        {
    177178                facet *codim2Ptr;
     
    185186                        }
    186187                }
     188//              delete this->codim2Ptr;
    187189        }
    188190        if(this->codim2Ptr!=NULL)
     
    191193                idDelete((ideal *)&this->flipGB);
    192194        if(this->flipRing!=NULL && this->flipRing->idroot!=(idhdl)0xfbfbfbfbfbfbfbfb)
    193 //              rDelete(this->flipRing);
     195                rDelete(this->flipRing);
    194196//      this->flipRing=NULL;
    195197        this->prev=NULL;
     
    317319inline int facet::getUCN()
    318320{
    319         if(this!=NULL)//  && this!=(facet *)0xfbfbfbfbfbfbfbfb)// || this!=(facet *)0xfbfbfbfb) )
    320 //      if(this!=NULL && ( this->fNormal!=(int64vec *)0xfbfbfbfb || this->fNormal!=(int64vec *)0xfbfbfbfbfbfbfbfb) )
     321#ifndef NDEBUG
     322  #if SIZEOF_LONG==8
     323        if((this!=NULL && this!=(facet * const)0xfbfbfbfbfbfbfbfb))
     324  #elif
     325        if((this!=NULL && this!=(facet * const)0xfbfbfbfb))
     326  #endif
     327#endif
     328#ifdef NDEBUG
     329        if(this!=NULL)
     330#endif                 
    321331                return this->UCN;
    322332        else
     
    435445        this->pred=gc.UCN;
    436446        this->facetPtr=NULL;
    437 //      this->gcBasis=idCopy(f.flipGB);
    438 //      ring saveRing=currRing;
    439 //      ring tmpRing=f.flipRing;
    440 //      rComplete(f.flipRing);
    441 //      rChangeCurrRing(f.flipRing);
    442447        this->gcBasis=idrCopyR(f.flipGB, f.flipRing);
    443448//      this->inputIdeal=idCopy(this->gcBasis);
    444449        this->baseRing=rCopy(f.flipRing);
    445 //      rComplete(this->baseRing);
    446 //      rChangeCurrRing(saveRing);
    447450        this->numFacets=0;
    448451        this->ivIntPt=NULL;
    449 //      this->rootRing=NULL;
    450         //rComplete(this->baseRing);
    451         //rChangeCurrRing(this->baseRing);
    452452}
    453453               
     
    462462//      if (this->rootRing!=NULL && this->rootRing!=(ip_sring *)0xfefefefefefefefe)
    463463//              rDelete(this->rootRing);
    464 //      if(this->UCN!=1)
    465 //              rDelete(this->baseRing);
     464        if(this->UCN!=1 && this->baseRing!=NULL)
     465                rDelete(this->baseRing);
    466466        facet *fAct;
    467467        facet *fDel;
     
    555555        facet *fAct;
    556556        fAct = &f;
    557         facet *codim2Act;
    558         codim2Act = fAct->codim2Ptr;
    559        
    560         cout << endl;
    561         while(fAct!=NULL)
    562         {
    563                 int64vec *fNormal;             
    564                 fNormal=fAct->getFacetNormal();
    565                 cout << "(";
    566                 fNormal->show(1,0);
    567                 if(fAct->isFlippable==TRUE)
    568                         cout << ") ";
    569                 else
    570                         cout << ")* ";
    571                 delete fNormal;
     557        if(fAct!=NULL)
     558        {
     559                facet *codim2Act;
    572560                codim2Act = fAct->codim2Ptr;
    573                 cout << " Codim2: ";
    574                 while(codim2Act!=NULL)
    575                 {
    576                         int64vec *f2Normal;
    577                         f2Normal = codim2Act->getFacetNormal();
     561               
     562                cout << endl;
     563                while(fAct!=NULL)
     564                {
     565                        int64vec *fNormal;             
     566                        fNormal=fAct->getFacetNormal();
    578567                        cout << "(";
    579                         f2Normal->show(1,0);
    580                         cout << ") ";
    581                         delete f2Normal;
    582                         codim2Act = codim2Act->next;
     568                        fNormal->show(1,0);
     569                        if(fAct->isFlippable==TRUE)
     570                                cout << ") ";
     571                        else
     572                                cout << ")* ";
     573                        delete fNormal;
     574                        codim2Act = fAct->codim2Ptr;
     575                        cout << " Codim2: ";
     576                        while(codim2Act!=NULL)
     577                        {
     578                                int64vec *f2Normal;
     579                                f2Normal = codim2Act->getFacetNormal();
     580                                cout << "(";
     581                                f2Normal->show(1,0);
     582                                cout << ") ";
     583                                delete f2Normal;
     584                                codim2Act = codim2Act->next;
     585                        }
     586                        cout << "UCN = " << fAct->getUCN() << endl;                             
     587                        fAct = fAct->next;
    583588                }
    584                 cout << "UCN = " << fAct->getUCN() << endl;                             
    585                 fAct = fAct->next;
    586589        }
    587590}
     
    16401643        test|=Sy_bit(OPT_REDTAIL);
    16411644#ifdef gfan_DEBUG
    1642         test|=Sy_bit(6);        //OPT_DEBUG
     1645//      test|=Sy_bit(6);        //OPT_DEBUG
    16431646#endif
    16441647        ideal tmpI;
     
    17521755        for (int ii=0;ii<size;ii++)
    17531756        {
    1754                 poly temp1=pInit();
    1755                 poly temp2=pInit();
     1757//              poly temp1=pInit();
     1758//              poly temp2=pInit();
    17561759                poly temp3=pInit();//polys to temporarily store values for pSub
    17571760//              res->m[ii]=pCopy(kNF(G, NULL,H->m[ii],0,0));
    1758                 temp1=pCopy(H->m[ii]);
     1761//              temp1=pCopy(H->m[ii]);
    17591762//              temp2=pCopy(res->m[ii]);
    17601763                //NOTE if gfanHeuristic=0 (sic!) this results in dPolyErrors - mon from wrong ring
    1761                 temp2=pCopy(kNF(G, NULL,H->m[ii],0,0));
    1762                 temp3=pSub(temp1, temp2);
     1764//              temp2=pCopy(kNF(G, NULL,H->m[ii],0,0));
     1765//              temp3=pSub(temp1, temp2);
     1766                temp3=pSub(pCopy(H->m[ii]),pCopy(kNF(G,NULL,H->m[ii],0,0)));
    17631767                res->m[ii]=pCopy(temp3);
    17641768                //res->m[ii]=pSub(temp1,temp2); //buggy         
    17651769                //cout << "res->m["<<ii<<"]=";pWrite(res->m[ii]);
    1766                 pDelete(&temp1);
     1770//              pDelete(&temp1);
    17671771//              pDelete(&temp2);
    1768 //              pDelete(&temp3); //NOTE does not work, so commented out
     1772                pDelete(&temp3); //NOTE does not work, so commented out
    17691773        }
    17701774        return res;
     
    18031807                }
    18041808                delete iv;
     1809                delete ivNull;
    18051810        }
    18061811        //Remove duplicates of rows
     
    18731878inline int64vec *gcone::ivNeg(int64vec *iv)
    18741879{       //Hm, switching to int64vec const int64vec does no longer work
    1875         //NOTE: Can't this be done without new?
    18761880        int64vec *res;// = new int64vec(iv->length());
    18771881        res=iv64Copy(iv);
     
    22012205                                                mpq_set(ratd,ddineq->matrix[ii][k]);
    22022206                                                mpq_set_str(ddineq->matrix[ii][k],"0",10);                     
    2203                                                 for(int ss=k+1;ss<m;ss++)
     2207                                                for(int ss=k+1;ss<n;ss++)
    22042208                                                {
    22052209                                                        mpq_t prod; mpq_init(prod);
     
    23132317        gcAct->getExtremalRays(*gcAct);
    23142318                               
    2315         //Compute unique representation of codim-2-facets
     2319        //Compute unique representation of Facets and rays
    23162320        gcAct->normalize();
    23172321                       
     
    24372441                        {
    24382442                                gcTmp->writeConeToFile(*gcTmp);
    2439                                 //The for loop is no longer needed
    2440 //                              for(int ii=0;ii<IDELEMS(gcTmp->gcBasis);ii++)
    2441 //                              {
    2442 //                                      pDelete(&gcTmp->gcBasis->m[ii]);
    2443 //                              }
    24442443                                idDelete((ideal*)&gcTmp->gcBasis);//Whonder why?
    24452444                                //If you use the following make sure it is uncommented in readConeFromFile
    2446 //                              rDelete(gcTmp->baseRing);
     2445                                rDelete(gcTmp->baseRing);
    24472446                        }                       
    24482447#ifdef gfan_DEBUG
    2449 //                      if(SearchListRoot!=NULL)
    2450 //                              gcTmp->showSLA(*SearchListRoot);
    2451 #endif
     2448                        if(SearchListRoot!=NULL)
     2449                                gcTmp->showSLA(*SearchListRoot);
     2450#endif                 
    24522451                        rChangeCurrRing(gcAct->baseRing);
    24532452                        rDelete(rTmp);
     
    24662465                //Search for cone with smallest UCN
    24672466                gcNext = gcHead;
    2468                 while(gcNext!=NULL && SearchListRoot!=NULL && gcNext!=(gcone * const)0xfbfbfbfbfbfbfbfb && gcNext!=(gcone * const)0xfbfbfbfb)
     2467#ifndef NDEBUG
     2468  #if SIZEOF_LONG==8    //64 bit
     2469                while(gcNext!=(gcone * const)0xfbfbfbfbfbfbfbfb && SearchListRoot!=NULL)
     2470  #elif
     2471                while(gcNext!=(gcone * const)0xfbfbfbfb && SearchListRoot!=NULL)
     2472  #endif
     2473#endif
     2474#ifdef NDEBUG
     2475                while(gcNext!=NULL && SearchListRoot!=NULL)     
     2476#endif
    24692477                {                       
    24702478                        if( gcNext->getUCN() == SearchListRoot->getUCN() )
    2471                         {//NOTE: Implement heuristic to be used!
     2479                        {
    24722480                                if(gfanHeuristic==0)
    24732481                                {
     
    24852493                                        gcDel = gcAct;                                 
    24862494                                        gcAct = gcNext;
    2487 //                                      rDelete(gcDel->baseRing);
    2488                                         //Read st00f from file
     2495                                        //Read st00f from file &
    24892496                                        //implant the GB into gcAct
    24902497                                        readConeFromFile(gcAct->getUCN(), gcAct);
     2498                                        //Kill the baseRing but ONLY if it is not the ring the computation started in!
     2499                                        if(gcDel->getUCN()!=1)
     2500                                                rDelete(gcDel->baseRing);
    24912501//                                      rAct=rCopy(gcAct->baseRing);
    24922502                                        /*The ring change occurs in readConeFromFile, so as to
     
    25752585inline void gcone::normalize()
    25762586{
    2577         int *ggT = new int;
    2578                 *ggT=1;
     2587//      int *ggT = new int;
     2588//              *ggT=1;
    25792589        facet *fAct;
    25802590        facet *codim2Act;
     
    25852595                int64vec *fNormal;
    25862596                fNormal = fAct->getFacetNormal();
     2597                int *ggT = new int;
     2598                *ggT=1;
    25872599                for(int ii=0;ii<this->numVars;ii++)
    25882600                {
    25892601                        *ggT=intgcd((*ggT),(*fNormal)[ii]);
    25902602                }
    2591                 for(int ii=0;ii<this->numVars;ii++)
    2592                         (*fNormal)[ii] = ((*fNormal)[ii])/(*ggT);
    2593                 fAct->setFacetNormal(fNormal);
     2603                if(*ggT>1)//We only need to do this if the ggT is non-trivial
     2604                {
     2605                        for(int ii=0;ii<this->numVars;ii++)
     2606                                (*fNormal)[ii] = ((*fNormal)[ii])/(*ggT);
     2607                        fAct->setFacetNormal(fNormal);
     2608                }               
    25942609                delete fNormal;
     2610                delete ggT;
    25952611                /*And now for the codim2*/
    25962612                while(codim2Act!=NULL)
     
    25982614                        int64vec *n;
    25992615                        n=codim2Act->getFacetNormal();
     2616                        int *ggT=new int;
     2617                        *ggT=1;
    26002618                        for(int ii=0;ii<this->numVars;ii++)
    26012619                        {
    26022620                                *ggT = intgcd((*ggT),(*n)[ii]);
    26032621                        }
    2604                         for(int ii=0;ii<this->numVars;ii++)
    2605                         {
    2606                                 (*n)[ii] = ((*n)[ii])/(*ggT);
    2607                         }
    2608                         codim2Act->setFacetNormal(n);
     2622                        if(*ggT>1)
     2623                        {
     2624                                for(int ii=0;ii<this->numVars;ii++)
     2625                                {
     2626                                        (*n)[ii] = ((*n)[ii])/(*ggT);
     2627                                }
     2628                                codim2Act->setFacetNormal(n);
     2629                        }
    26092630                        codim2Act = codim2Act->next;
    26102631                        delete n;
     2632                        delete ggT;
    26112633                }
    26122634                fAct = fAct->next;
    26132635        }
    2614         delete ggT;                             
    26152636}
    26162637
     
    26492670        deleteMarker = NULL;
    26502671                       
    2651         /** Flag to indicate a facet that should be added to SLA*/
    2652 //      bool doNotAdd=FALSE;
    26532672        /** \brief  Flag to mark a facet that might be added
    26542673         * The following case may occur:
     
    26732692//              gcone::lengthOfSearchList++;
    26742693        }
    2675         /*1st step: compare facetNormals*/
    2676 //      int64vec *fNormal=NULL;gcone::
    2677 //      int64vec *slNormal=NULL;
    2678                        
     2694        /*1st step: compare facetNormals*/                     
    26792695        while(fAct!=NULL)
    26802696        {                                               
     
    26822698                {
    26832699                        int64vec *fNormal=NULL;
    2684 //                      int64vec *slNormal=NULL;
    26852700                        fNormal=fAct->getFacetNormal();
    26862701                        slAct = slHead;
     
    27102725                        /*End of dumping into SLA*/
    27112726                        while(slAct!=NULL)
    2712                         //while(slAct!=slEndStatic->next)
    27132727                        {
    27142728                                int64vec *slNormal=NULL;
     
    27162730                                slNormal = slAct->getFacetNormal();
    27172731#ifdef gfan_DEBUG
    2718                                 cout << "Checking facet (";
    2719                                 fNormal->show(1,1);
    2720                                 cout << ") against (";
    2721                                 slNormal->show(1,1);
    2722                                 cout << ")" << endl;
     2732//                              cout << "Checking facet (";fNormal->show(1,1);cout << ") against (";slNormal->show(1,1);cout << ")" << endl;
    27232733#endif                         
    27242734                                if(areEqual(fAct,slAct))
     
    27292739                                                slHead = slAct->next;                                           
    27302740                                                if(slHead!=NULL)
    2731                                                         slHead->prev = NULL;                                           
     2741                                                        slHead->prev = NULL;
    27322742                                        }
    27332743                                        else if (slAct==slEnd)
    27342744                                        {
    27352745                                                slEnd=slEnd->prev;
    2736                                                 slEnd->next = NULL;                                             
     2746                                                slEnd->next = NULL;
    27372747                                        }                                                               
    27382748                                        else
    27392749                                        {
    27402750                                                slAct->prev->next = slAct->next;
    2741                                                 slAct->next->prev = slAct->prev;                                               
     2751                                                slAct->next->prev = slAct->prev;
    27422752                                        }
    27432753                                        removalOccured=TRUE;
    2744 //                                      cout << gcone::lengthOfSearchList << endl;
    27452754                                        gcone::lengthOfSearchList--;
    2746 //                                      cout << gcone::lengthOfSearchList << endl;
    27472755                                        if(deleteMarker!=NULL)
    27482756                                        {
     
    27512759                                        }
    27522760#ifdef gfan_DEBUG
    2753                                         cout << "Removing (";
    2754                                         fNormal->show(1,1);
    2755                                         cout << ") from list" << endl;
     2761                                        cout << "Removing (";fNormal->show(1,1);cout << ") from list" << endl;
    27562762#endif
    27572763                                        delete slNormal;
    27582764                                        break;//leave the while loop, since we found fAct=slAct thus delete slAct and do not add fAct
    2759                                 }               
    2760                                
     2765                                }
    27612766                                slAct = slAct->next;
    27622767                                /* NOTE The following lines must not be here but rather called inside the if-block above.
     
    27762781                        {
    27772782#ifdef gfan_DEBUG
    2778                                 cout << "Adding facet (";
    2779                                 fNormal->show(1,0);
    2780                                 cout << ") to SLA " << endl;
     2783                                cout << "Adding facet (";fNormal->show(1,0);cout << ") to SLA " << endl;
    27812784#endif
    27822785                                //Add fAct to SLA
     
    27872790                                               
    27882791                                slEnd->next = new facet();
    2789                                 slEnd = slEnd->next;
     2792                                slEnd = slEnd->next;//Update slEnd
    27902793                                facet *slEndCodim2Root;
    27912794                                facet *slEndCodim2Act;
     
    28202823                                }
    28212824                                gcone::lengthOfSearchList++;                                                   
    2822 //                              cout << gcone::lengthOfSearchList << endl;
    28232825                        }//if( (notParallelCtr==lengthOfSearchList && removalOccured==FALSE) ||
    28242826                        fAct = fAct->next;
     
    30193021        ss << UCN;
    30203022        string UCNstr = ss.str();
    3021 //      string line;
    3022 //      string strGcBasisLength;
    3023 //      string strMonom, strCoeff, strCoeffNom, strCoeffDenom;
    30243023        int gcBasisLength=0;
    3025 //      int intCoeff=1;
    3026 //      int intCoeffNom=1;              //better (number) but that's not compatible with stringstream;
    3027 //      int intCoeffDenom=1;
    3028        
    3029 //      bool hasCoeffInQ = FALSE;       //does the polynomial have rational coeff?
    3030 //      bool hasNegCoeff = FALSE;       //or a negative one?
    30313024        size_t found;                   //used for find_first_(not)_of
    30323025
     
    30423035        ring saveRing=currRing;
    30433036        //Comment the following if you uncomment the if(line=="RING") part below
    3044         rChangeCurrRing(gc->baseRing);
     3037//      rChangeCurrRing(gc->baseRing);
    30453038       
    30463039        while( !gcInputFile.eof() )
     
    30483041                string line;
    30493042                getline(gcInputFile,line);
    3050 //              hasCoeffInQ = FALSE;
    3051 //              hasNegCoeff = FALSE;
    3052                
    30533043                if(line=="RING")
    30543044                {
    3055 //                      getline(gcInputFile,line);
    3056 //                      found = line.find("a(");
    3057 //                      line.erase(0,found+2);
    3058 //                      string strweight;
    3059 //                      strweight=line.substr(0,line.find_first_of(")"));
    3060 //                      int64vec *iv=new int64vec(this->numVars);
    3061 //                      for(int ii=0;ii<this->numVars;ii++)
    3062 //                      {
    3063 //                              string weight;
    3064 //                              weight=line.substr(0,line.find_first_of(",)"));                         
    3065 //                              (*iv)[ii]=atoi(weight.c_str());
    3066 //                              line.erase(0,line.find_first_of(",)")+1);
    3067 //                      }
    3068 //                      ring newRing;
    3069 //                      if(currRing->order[0]!=ringorder_a)
    3070 //                      {
    3071 //                              newRing=rCopyAndAddWeight(currRing,iv);
    3072 //                      }
    3073 //                      else
    3074 //                      {                       
    3075 //                              newRing=rCopy0(currRing);
    3076 //                              int length=this->numVars;
    3077 //                              int *A=(int *)omAlloc0(length*sizeof(int));
    3078 //                              for(int jj=0;jj<length;jj++)
    3079 //                              {
    3080 //                                      A[jj]=-(*iv)[jj];
    3081 //                              }
    3082 //                              omFree(newRing->wvhdl[0]);
    3083 //                              newRing->wvhdl[0]=(int*)A;
    3084 //                              newRing->block1[0]=length;
    3085 //                      }
    3086 //                      delete iv;
    3087 //                      rComplete(newRing);
    3088 //                      gc->baseRing=rCopy(newRing);
    3089 // //                   rDelete(newRing);
    3090 //                      rComplete(gc->baseRing);
    3091 //                      if(currRing!=gc->baseRing)
    3092 //                              rChangeCurrRing(gc->baseRing);
     3045                        getline(gcInputFile,line);
     3046                        found = line.find("a(");
     3047                        line.erase(0,found+2);
     3048                        string strweight;
     3049                        strweight=line.substr(0,line.find_first_of(")"));
     3050                        int64vec *iv=new int64vec(this->numVars);
     3051                        for(int ii=0;ii<this->numVars;ii++)
     3052                        {
     3053                                string weight;
     3054                                weight=line.substr(0,line.find_first_of(",)"));                         
     3055                                (*iv)[ii]=atol(weight.c_str());//Better to long. Weight bound in Singular:2147483647
     3056                                line.erase(0,line.find_first_of(",)")+1);
     3057                        }
     3058                        ring newRing;
     3059                        if(currRing->order[0]!=ringorder_a)
     3060                        {
     3061                                newRing=rCopyAndAddWeight(currRing,iv);
     3062                        }
     3063                        else
     3064                        {                       
     3065                                newRing=rCopy0(currRing);
     3066                                int length=this->numVars;
     3067                                int *A=(int *)omAlloc0(length*sizeof(int));
     3068                                for(int jj=0;jj<length;jj++)
     3069                                {
     3070                                        A[jj]=(*iv)[jj];
     3071                                }
     3072                                omFree(newRing->wvhdl[0]);
     3073                                newRing->wvhdl[0]=(int*)A;
     3074                                newRing->block1[0]=length;
     3075                        }
     3076                        delete iv;
     3077                        rComplete(newRing);
     3078                        gc->baseRing=rCopy(newRing);
     3079                        rDelete(newRing);
     3080                        rComplete(gc->baseRing);
     3081                        if(currRing!=gc->baseRing)
     3082                                rChangeCurrRing(gc->baseRing);
    30933083                }
    30943084               
     
    31153105                                while(!line.empty())
    31163106                                {
    3117 //                                      poly strPoly=pInit();
     3107//                                      poly strPoly;//=pInit();
    31183108                                        number nCoeff=nInit(1);
    31193109                                        number nCoeffNom=nInit(1);
     
    32243214/** \brief Gather the output
    32253215* List of lists
     3216* If heuristic==1 readConeFromFile() is called once more on every cone. This may slow down the computation but it also
     3217* allows us to rDelete(gcDel->baseRing) and the such in gcone::noRevS.
    32263218*\param *gc Pointer to gcone, preferably gcRoot ;-)
    32273219*\param n the number of cones
     
    34063398                        gcAct->getConeNormals(gcAct->gcBasis);
    34073399                        gcAct->noRevS(*gcAct);  //Here we go!
     3400                        //Switch back to the ring the computation was started in
    34083401                        rChangeCurrRing(inputRing);
    34093402                        //res=gcAct->gcBasis;
     
    34363429        /*Return result*/
    34373430#ifdef gfanp
    3438         cout << "t_getConeNormals:" << gcone::time_getConeNormals << endl;
     3431        cout << endl << "t_getConeNormals:" << gcone::time_getConeNormals << endl;
    34393432//      cout << "t_getCodim2Normals:" << gcone::time_getCodim2Normals << endl;
    34403433//      cout << "  t_ddMC:" << gcone::t_ddMC << endl;
Note: See TracChangeset for help on using the changeset viewer.