Changeset bec3b0 in git


Ignore:
Timestamp:
Oct 13, 2009, 4:35:18 PM (14 years ago)
Author:
Martin Monerjan
Branches:
(u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
Children:
6666eaa6f8a2ff004dc43a60643801895ec2db11
Parents:
609fa72729d2369c950c0cd27105be8ec0e7d420
Message:
~gcone
Garbage collection
writeConeToFile
readConeFromFile


git-svn-id: file:///usr/local/Singular/svn/trunk@12191 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
kernel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/gfan.cc

    r609fa7 rbec3b0  
    22Compute the Groebner fan of an ideal
    33$Author: monerjan $
    4 $Date: 2009-10-01 16:50:22 $
    5 $Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.95 2009-10-01 16:50:22 monerjan Exp $
    6 $Id: gfan.cc,v 1.95 2009-10-01 16:50:22 monerjan Exp $
     4$Date: 2009-10-13 14:35:17 $
     5$Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.96 2009-10-13 14:35:17 monerjan Exp $
     6$Id: gfan.cc,v 1.96 2009-10-13 14:35:17 monerjan Exp $
    77*/
    88
     
    359359        this->numFacets=0;
    360360        this->ivIntPt=NULL;
     361        this->rootRing=NULL;
    361362        //rComplete(this->baseRing);
    362363        //rChangeCurrRing(this->baseRing);
     
    367368gcone::~gcone()
    368369{
    369         idDelete((ideal *)&this->gcBasis);
    370         idDelete((ideal *)&this->inputIdeal);
    371         rDelete(this->rootRing);
    372         rDelete(this->baseRing);
     370        if(this->gcBasis!=NULL)
     371                idDelete((ideal *)&this->gcBasis);
     372        if(this->inputIdeal!=NULL)
     373                idDelete((ideal *)&this->inputIdeal);
     374        if (this->rootRing!=NULL && this->rootRing!=(ip_sring *)0xfefefefefefefefe)
     375                rDelete(this->rootRing);
     376        //rDelete(this->baseRing);
    373377        facet *fAct;
    374378        facet *fDel;
     
    493497int gcone::getUCN()
    494498{
    495         if(this!=NULL && ( this!=(gcone *)0xfbfbfbfb || this!=(gcone *)0xfbfbfbfbfbfbfbfb) )
     499        if( this!=NULL && ( this!=(gcone * const)0xfbfbfbfbfbfbfbfb && this!=(gcone * const)0xfbfbfbfb ) )
    496500                return this->UCN;
    497501        else
     
    749753               
    750754                //Clean up but don't delete the return value! (Whatever it will turn out to be)                 
    751                 //dd_FreeMatrix(ddineq);
    752                 //set_free(ddredrows);
     755                dd_FreeMatrix(ddineq);
     756                set_free(ddredrows);
    753757                //free(ddnewpos);
    754758                //set_free(ddlinset);
     
    797801                ddpolyh=dd_DDMatrix2Poly(ddakt, &err);
    798802                P=dd_CopyGenerators(ddpolyh);                           
    799 #ifdef gfan_DEBUG
     803#ifdef gfan_DEBUG 
    800804//              cout << "Codim2 facet:" << endl;
    801805//                      dd_WriteMatrix(stdout,P);
     
    852856                fAct = fAct->next;     
    853857                dd_FreeMatrix(ddakt);
     858//              dd_FreeMatrix(ddineq);
    854859                dd_FreePolyhedra(ddpolyh);
    855860                delete iv_intPoint;
     
    17051710        };
    17061711        heuristic h;
    1707         h=hdd;
     1712        h=ram;
    17081713       
    17091714#ifdef gfan_DEBUG
     
    17301735        for(int ii=0;ii<this->numFacets;ii++)
    17311736        {
    1732                 //only copy flippable facets!
     1737                //only copy flippable facets! NOTE: We do not need flipRing or any such information.
    17331738                if(fAct->isFlippable==TRUE)
    17341739                {
     
    18061811                        gcAct->flip(gcAct->gcBasis,fAct);
    18071812                        ring rTmp=rCopy(fAct->flipRing);
    1808                         rComplete(rTmp);
     1813                        rComplete(rTmp);                       
    18091814                        rChangeCurrRing(rTmp);
    18101815                        gcone *gcTmp = new gcone::gcone(*gcAct,*fAct);
    1811                         /* Now gcTmp->gcBasis and gcTmp->baseRing are set from fAct->flipGB and fAct->flipRing,
    1812                          * therefore we can delete them.
     1816                        /* Now gcTmp->gcBasis and gcTmp->baseRing are set from fAct->flipGB and fAct->flipRing.
     1817                         * Since we come at most once across a given facet from gcAct->facetPtr we can delete them.
     1818                         * NOTE: Can this cause trouble with the destructor?
     1819                         * Answer: Yes it bloody well does!
     1820                         * However I'd like to delete this data here, since if we have a cone with many many facets it
     1821                         * should pay to get rid of the flipGB as soon as possible.
     1822                         * Destructor must be equipped with necessary checks.
    18131823                        */
    1814                         idDelete((ideal *)&fAct->flipGB);
    1815                         rDelete(fAct->flipRing);
     1824//                      idDelete((ideal *)&fAct->flipGB);
     1825//                      rDelete(fAct->flipRing);
    18161826                        gcTmp->getConeNormals(gcTmp->gcBasis, FALSE);                                   
    18171827                        gcTmp->getCodim2Normals(*gcTmp);                                       
     
    18201830                        gcTmp->showFacets(1);
    18211831#endif
    1822                         if(h==hdd)
    1823                         {
     1832                        if(h==hdd)
     1833                        {
    18241834                                gcTmp->writeConeToFile(*gcTmp);
    1825                         }
     1835                        }
    18261836                        /*add facets to SLA here*/
    18271837                        SearchListRoot=gcTmp->enqueueNewFacets(*SearchListRoot);
     
    18471857                deleteMarker=gcAct;             
    18481858//              delete deleteMarker;
    1849                 deleteMarker=NULL;
     1859//              deleteMarker=NULL;
    18501860                //Search for cone with smallest UCN
    18511861                gcNext = gcHead;
    1852                 while(gcNext!=NULL)
     1862                while(gcNext!=NULL && SearchListRoot!=NULL && gcNext!=(gcone * const)0xfbfbfbfbfbfbfbfb && gcNext!=(gcone * const)0xfbfbfbfb)
    18531863                {                       
    18541864                        /*NOTE if gcNext->getUCN is smaller than SearchListRoot->getUCN it follows, that the cone
     
    18571867                        if (gcNext->getUCN() < SearchListRoot->getUCN() )
    18581868                        {
    1859                                 idDelete((ideal *)&gcNext->gcBasis);    //at least drop huge gröbner bases
     1869                                //idDelete((ideal *)&gcNext->gcBasis);  //at least drop huge gröbner bases
     1870                                if(gcNext == gcHead)
     1871                                {
     1872                                        deleteMarker = gcHead;
     1873                                        gcHead = gcNext->next;
     1874                                        //gcNext->next->prev = NULL;
     1875                                }
     1876                                else
     1877                                {
     1878                                        deleteMarker = gcNext;
     1879                                        gcNext->prev->next = gcNext->next;
     1880                                        gcNext->next->prev = gcNext->prev;
     1881                                }
     1882//                              gcNext = gcNext->next;
     1883//                              delete deleteMarker;
     1884//                              deleteMarker = NULL;
    18601885                        }
    1861                         if( gcNext->getUCN() == SearchListRoot->getUCN() )
    1862                         {
    1863                                 gcAct = gcNext;
    1864                                 rAct=rCopy(gcAct->baseRing);
    1865                                 rComplete(rAct);
    1866                                 rChangeCurrRing(rAct);                                         
    1867                                 break;                                         
    1868                         }
    1869                        
    1870 //                      if (gcNext->getUCN() < SearchListRoot->getUCN() )
    1871 //                      {
    1872 //                              idDelete((ideal *)&gcAct->gcBasis);
    1873 //                              rDelete(gcAct->baseRing);
    1874 //                      }
    1875                         gcNext = gcNext->next;
     1886                        else if( gcNext->getUCN() == SearchListRoot->getUCN() )
     1887                        {//NOTE: Implement heuristic to be used!
     1888                                if(h==ram)
     1889                                {
     1890                                        gcAct = gcNext;
     1891                                        rAct=rCopy(gcAct->baseRing);
     1892                                        rComplete(rAct);
     1893                                        rChangeCurrRing(rAct);                                         
     1894                                        break;
     1895                                }
     1896                                else if(h==hdd)
     1897                                {
     1898                                        //Read st00f from file
     1899                                        gcAct = gcNext;
     1900                                        //implant the GB into gcAct
     1901                                        readConeFromFile(gcNext->getUCN(), gcAct);
     1902                                        break;
     1903                                }                               
     1904                        }                       
     1905                        gcNext = gcNext->next;
     1906//                      if(deleteMarker!=NULL && deleteMarker!=(gcone *)0xfbfbfbfbfbfbfbfb)
     1907                        if(this->getUCN()!=1)   //workaround to avoid unpredictable behaviour towards end of program
     1908                                delete deleteMarker;
     1909//                      deleteMarker = NULL;
     1910//                      gcNext = gcNext->next;
    18761911                }
    18771912                UCNcounter++;
     
    20592094                        slAct = slHead;
    20602095                        notParallelCtr=0;
    2061 //                                      delete deleteMarker;
    2062 //                                      deleteMarker=NULL;
    2063                                         /*If slAct==NULL and fAct!=NULL
     2096//                      delete deleteMarker;
     2097//                      deleteMarker=NULL;
     2098                        /*If slAct==NULL and fAct!=NULL
    20642099                        we just copy all remaining facets into SLA*/
    20652100                        if(slAct==NULL)
     
    21082143                                break;
    21092144                        }
    2110                         /*End of */
     2145                        /*End of dumping into SLA*/
    21112146                        while(slAct!=NULL)
    21122147                                        //while(slAct!=slEndStatic->next)
    21132148                        {
    2114 //                                              if(deleteMarker!=NULL)
    2115 //                                              {
    2116 //                                                      delete deleteMarker;
    2117 //                                                      deleteMarker=NULL;
    2118 //                                              }
     2149//                              if(deleteMarker!=NULL)
     2150//                              {
     2151//                                      delete deleteMarker;
     2152//                                      deleteMarker=NULL;
     2153//                              }
    21192154                                removalOccured=FALSE;
    21202155                                slNormal = slAct->getFacetNormal();
     
    21952230                                                }
    21962231                                                               
    2197                                                                 //update lengthOfSearchList                                     
     2232                                                //update lengthOfSearchList                                     
    21982233                                                lengthOfSearchList--;
    2199                                                                 //delete slAct;
    2200                                                                 //slAct=NULL;
    2201                                                                 //slAct = slAct->next; //not needed, since facets are equal
    2202                                                                 //delete deleteMarker;
    2203                                                                 //deleteMarker=NULL;
    2204                                                                 //fAct = fAct->next;
     2234                                                //delete slAct;
     2235                                                //slAct=NULL;
     2236                                                //slAct = slAct->next; //not needed, since facets are equal
     2237                                                //delete deleteMarker;
     2238                                                //deleteMarker=NULL;
     2239                                                //fAct = fAct->next;
    22052240                                                break;
    22062241                                        }//if(ctr==fAct->numCodim2Facets)
    22072242                                        else    //facets are parallel but NOT equal. But this does not imply that there
    2208                                                                 //is no other facet later in SLA that might be equal.
     2243                                                //is no other facet later in SLA that might be equal.
    22092244                                        {
    22102245                                                maybe=TRUE;
     
    22272262                                }
    22282263                                slAct = slAct->next;
    2229                                                 /* NOTE The following lines must not be here but rather called inside the if-block above.
     2264                                /* NOTE The following lines must not be here but rather called inside the if-block above.
    22302265                                Otherwise results get crappy. Unfortunately there are two slAct=slAct->next calls now,
    22312266                                (not nice!) but since they are in seperate branches of the if-statement there should not
    2232                                                 be a way it gets called twice thus ommiting one facet:
     2267                                be a way it gets called twice thus ommiting one facet:
    22332268                                slAct = slAct->next;*/                                         
    22342269                                                //delete deleteMarker;
     
    22612296                                slEnd->setFacetNormal(fNormal);
    22622297                                slEnd->prev = marker;
    2263                                                 //Copy codim2-facets
     2298                                //Copy codim2-facets
    22642299                                intvec *f2Normal;// = new intvec(this->numVars);
    22652300                                while(f2Act!=NULL)
     
    22812316                                        f2Act = f2Act->next;
    22822317                                }
    2283                                 lengthOfSearchList++;
    2284                                                 //delete f2Normal;                                             
     2318                                lengthOfSearchList++;                           
    22852319                        }//if( (notParallelCtr==lengthOfSearchList && removalOccured==FALSE) ||
    22862320                        fAct = fAct->next;
     
    23332367                       
    23342368        int jj=0;
    2335                         //while(fAct->next!=NULL)
     2369       
    23362370        while(fAct!=NULL)
    23372371        {
     
    23902424                gcOutputFile << this->UCN << endl;
    23912425                gcOutputFile << "RING" << endl;
    2392                 gcOutputFile << ringString << endl;                     
     2426                gcOutputFile << ringString << endl;
     2427                gcOutputFile << "GCBASISLENGTH" << endl;
     2428                gcOutputFile << IDELEMS(gc.gcBasis) << endl;                   
    23932429                //Write this->gcBasis into file
    23942430                gcOutputFile << "GCBASIS" << endl;                             
     
    24462482/** \brief Reads a cone from a file identified by its number
    24472483 */
    2448 void gcone::readConeFromFile(int UCN)
     2484void gcone::readConeFromFile(int UCN, gcone *gc)
    24492485{
    24502486        //int UCN=gc.UCN;
    24512487        stringstream ss;
    24522488        ss << UCN;
    2453         string UCNstr = ss.str();               
    2454                        
     2489        string UCNstr = ss.str();
     2490        string line;
     2491        string modLine;
     2492        string strMonom, strCoeff;             
     2493        int gcBasisLength=0;
     2494        int intCoeff=1;
     2495        bool hasCoeffInQ = FALSE;       //does the polynomial have rational coeff?
     2496               
    24552497        char prefix[]="/tmp/cone";
    2456         char *UCNstring;
    2457         strcpy(UCNstring,UCNstr.c_str());
     2498        const char *UCNstring = UCNstr.c_str();
     2499        //strcpy(UCNstring,UCNstr.c_str());
     2500       
    24582501        char suffix[]=".sg";
    24592502        char *filename=strcat(prefix,UCNstring);
     
    24622505        ifstream gcInputFile(filename, ifstream::in);
    24632506       
     2507        ring saveRing=currRing;
     2508        rChangeCurrRing(gc->baseRing);
     2509        poly strPoly=pInit();
     2510        poly resPoly=pInit();   //The poly to be read in
     2511       
     2512        string::iterator EOL;
     2513        int terms=1;    //#Terms in the poly
     2514       
     2515        while( !gcInputFile.eof() )
     2516        {
     2517                getline(gcInputFile,line);
     2518       
     2519                if(line=="GCBASISLENGTH")
     2520                {
     2521                        getline(gcInputFile, line);
     2522                        ss << line;
     2523                        ss >> gcBasisLength;
     2524                }
     2525                if(line=="GCBASIS")
     2526                {
     2527                        for(int jj=0;jj<gcBasisLength;jj++)
     2528                        {
     2529                                getline(gcInputFile,line);
     2530                                //find out how many terms the poly consists of
     2531                                for(EOL=line.begin(); EOL!=line.end();++EOL)
     2532                                {
     2533                                        string s;
     2534                                        s=*EOL;
     2535                                        if(s=="+" || s=="-")
     2536                                                terms++;
     2537                                }
     2538                                //magically convert strings into polynomials
     2539                                //polys.cc:p_Read
     2540                                //check until first occurance of + or -
     2541                                //data or c_str
     2542//                              for(EOL=line.begin(); EOL!=line.end();++EOL)
     2543//                              {
     2544//                                      string s;
     2545//                                      s=*EOL;
     2546//                                      if(s=="+" || s=="-")
     2547//                                      {
     2548//                                              strMonom=line.substr(0,*EOL);                                           
     2549//                                              modLine=line.substr(*EOL,line.length());        //Truncate
     2550//                                              line=modLine;
     2551//                                              const char* monom = strMonom.c_str();
     2552//                                              p_Read(monom,strPoly,currRing);
     2553//                                              resPoly=pAdd(resPoly,strPoly);                                         
     2554//                                      }
     2555//                                             
     2556//                              }
     2557                                int start,stop;
     2558                                start=0;
     2559                                stop=0;
     2560                                for(int ii=0;ii<line.length();ii++)
     2561                                {
     2562                                        if(line[ii]=='+' || line[ii]=='-')
     2563                                        {
     2564                                                stop=ii;
     2565                                                if(start==0)
     2566                                                        strMonom = line.substr(start,stop);
     2567                                                else
     2568                                                        strMonom = line.substr(start,stop-1);
     2569                                                start=stop+1; //forget + or - between monomials
     2570                                                //Check for coeff != 1
     2571                                                int coeffStop=0;                                               
     2572                                                if(strMonom[0] == '1' ||
     2573                                                                        strMonom[jj] == 2 || strMonom[jj] == 3 ||
     2574                                                                        strMonom[jj] == 4 || strMonom[jj] == 5 ||
     2575                                                                        strMonom[jj] == 6 || strMonom[jj] == 7 ||
     2576                                                                        strMonom[jj] == 8 || strMonom[jj] == 9 ||
     2577                                                                        strMonom[jj] == 0  )
     2578                                                {
     2579                                                        for(int jj=1;jj<strMonom.length();jj++)
     2580                                                        {
     2581                                                                if(strMonom[jj] != 1 &&
     2582                                                                                strMonom[jj] != 2 && strMonom[jj] != 3 &&
     2583                                                                                strMonom[jj] != 4 && strMonom[jj] != 5 &&
     2584                                                                                strMonom[jj] != 6 && strMonom[jj] != 7 &&
     2585                                                                                strMonom[jj] != 8 && strMonom[jj] != 9 &&
     2586                                                                                strMonom[jj] != 0 )
     2587                                                                {
     2588                                                                        coeffStop=jj-1;
     2589                                                                }
     2590                                                        }
     2591                                                        strCoeff = strMonom.substr(0,coeffStop);
     2592                                                        ss << strCoeff;
     2593                                                        ss >> intCoeff;
     2594                                                        //Trim
     2595                                                        strMonom = strMonom.substr( coeffStop,strMonom.length() );             
     2596                                                }//strMonom==1||
     2597                                                //Check for coeff from Q
     2598                                               
     2599                                                const char* monom = strMonom.c_str();
     2600                                               
     2601                                                p_Read(monom,strPoly,currRing);
     2602                                                pSetCoeff(strPoly, (number) intCoeff);//Why is this set to zero instead of 1???
     2603                                                if(pIsConstantComp(resPoly))
     2604                                                        resPoly=pCopy(strPoly);                                                 
     2605                                                else
     2606                                                        resPoly=pAdd(resPoly,strPoly);                                                 
     2607                                        }
     2608                                }                               
     2609                                gcBasis->m[jj]=pCopy(resPoly);
     2610                                resPoly=NULL;   //reset
     2611                        }
     2612                        break;
     2613                }               
     2614        }//while(!gcInputFile.eof())
     2615       
    24642616        gcInputFile.close();
     2617        rChangeCurrRing(saveRing);
    24652618}       
    24662619
     
    25462699                res = inputIdeal;
    25472700        }
     2701        dd_free_global_constants();
    25482702        /*As of now extra.cc expects gfan to return type ideal. Probably this will change in near future.
    25492703        The return type will then be of type LIST_CMD
  • kernel/gfan.h

    r609fa7 rbec3b0  
    33
    44$Author: monerjan $
    5 $Date: 2009-10-01 16:50:22 $
    6 $Header: /exports/cvsroot-2/cvsroot/kernel/gfan.h,v 1.9 2009-10-01 16:50:22 monerjan Exp $
    7 $Id: gfan.h,v 1.9 2009-10-01 16:50:22 monerjan Exp $
     5$Date: 2009-10-13 14:35:18 $
     6$Header: /exports/cvsroot-2/cvsroot/kernel/gfan.h,v 1.10 2009-10-13 14:35:18 monerjan Exp $
     7$Id: gfan.h,v 1.10 2009-10-13 14:35:18 monerjan Exp $
    88*/
    99#ifdef HAVE_GFAN
     
    177177                dd_MatrixPtr facets2Matrix(gcone const &gc);
    178178                void writeConeToFile(gcone const &gc, bool usingIntPoints=FALSE);
    179                 void readConeFromFile(int gcNum);
     179                void readConeFromFile(int gcNum, gcone *gc);
    180180                friend class facet;     
    181181};
Note: See TracChangeset for help on using the changeset viewer.