Changeset bec3b0 in git
- Timestamp:
- Oct 13, 2009, 4:35:18 PM (14 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- 6666eaa6f8a2ff004dc43a60643801895ec2db11
- Parents:
- 609fa72729d2369c950c0cd27105be8ec0e7d420
- Location:
- kernel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/gfan.cc
r609fa7 rbec3b0 2 2 Compute the Groebner fan of an ideal 3 3 $Author: monerjan $ 4 $Date: 2009-10- 01 16:50:22$5 $Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.9 5 2009-10-01 16:50:22monerjan Exp $6 $Id: gfan.cc,v 1.9 5 2009-10-01 16:50:22monerjan 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 $ 7 7 */ 8 8 … … 359 359 this->numFacets=0; 360 360 this->ivIntPt=NULL; 361 this->rootRing=NULL; 361 362 //rComplete(this->baseRing); 362 363 //rChangeCurrRing(this->baseRing); … … 367 368 gcone::~gcone() 368 369 { 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); 373 377 facet *fAct; 374 378 facet *fDel; … … 493 497 int gcone::getUCN() 494 498 { 495 if( this!=NULL && ( this!=(gcone *)0xfbfbfbfb || this!=(gcone *)0xfbfbfbfbfbfbfbfb) )499 if( this!=NULL && ( this!=(gcone * const)0xfbfbfbfbfbfbfbfb && this!=(gcone * const)0xfbfbfbfb ) ) 496 500 return this->UCN; 497 501 else … … 749 753 750 754 //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); 753 757 //free(ddnewpos); 754 758 //set_free(ddlinset); … … 797 801 ddpolyh=dd_DDMatrix2Poly(ddakt, &err); 798 802 P=dd_CopyGenerators(ddpolyh); 799 #ifdef gfan_DEBUG 803 #ifdef gfan_DEBUG 800 804 // cout << "Codim2 facet:" << endl; 801 805 // dd_WriteMatrix(stdout,P); … … 852 856 fAct = fAct->next; 853 857 dd_FreeMatrix(ddakt); 858 // dd_FreeMatrix(ddineq); 854 859 dd_FreePolyhedra(ddpolyh); 855 860 delete iv_intPoint; … … 1705 1710 }; 1706 1711 heuristic h; 1707 h= hdd;1712 h=ram; 1708 1713 1709 1714 #ifdef gfan_DEBUG … … 1730 1735 for(int ii=0;ii<this->numFacets;ii++) 1731 1736 { 1732 //only copy flippable facets! 1737 //only copy flippable facets! NOTE: We do not need flipRing or any such information. 1733 1738 if(fAct->isFlippable==TRUE) 1734 1739 { … … 1806 1811 gcAct->flip(gcAct->gcBasis,fAct); 1807 1812 ring rTmp=rCopy(fAct->flipRing); 1808 rComplete(rTmp); 1813 rComplete(rTmp); 1809 1814 rChangeCurrRing(rTmp); 1810 1815 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. 1813 1823 */ 1814 idDelete((ideal *)&fAct->flipGB);1815 rDelete(fAct->flipRing);1824 // idDelete((ideal *)&fAct->flipGB); 1825 // rDelete(fAct->flipRing); 1816 1826 gcTmp->getConeNormals(gcTmp->gcBasis, FALSE); 1817 1827 gcTmp->getCodim2Normals(*gcTmp); … … 1820 1830 gcTmp->showFacets(1); 1821 1831 #endif 1822 if(h==hdd)1823 {1832 if(h==hdd) 1833 { 1824 1834 gcTmp->writeConeToFile(*gcTmp); 1825 }1835 } 1826 1836 /*add facets to SLA here*/ 1827 1837 SearchListRoot=gcTmp->enqueueNewFacets(*SearchListRoot); … … 1847 1857 deleteMarker=gcAct; 1848 1858 // delete deleteMarker; 1849 deleteMarker=NULL;1859 // deleteMarker=NULL; 1850 1860 //Search for cone with smallest UCN 1851 1861 gcNext = gcHead; 1852 while(gcNext!=NULL )1862 while(gcNext!=NULL && SearchListRoot!=NULL && gcNext!=(gcone * const)0xfbfbfbfbfbfbfbfb && gcNext!=(gcone * const)0xfbfbfbfb) 1853 1863 { 1854 1864 /*NOTE if gcNext->getUCN is smaller than SearchListRoot->getUCN it follows, that the cone … … 1857 1867 if (gcNext->getUCN() < SearchListRoot->getUCN() ) 1858 1868 { 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; 1860 1885 } 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; 1876 1911 } 1877 1912 UCNcounter++; … … 2059 2094 slAct = slHead; 2060 2095 notParallelCtr=0; 2061 // 2062 // 2063 2096 // delete deleteMarker; 2097 // deleteMarker=NULL; 2098 /*If slAct==NULL and fAct!=NULL 2064 2099 we just copy all remaining facets into SLA*/ 2065 2100 if(slAct==NULL) … … 2108 2143 break; 2109 2144 } 2110 /*End of */2145 /*End of dumping into SLA*/ 2111 2146 while(slAct!=NULL) 2112 2147 //while(slAct!=slEndStatic->next) 2113 2148 { 2114 // 2115 // 2116 // 2117 // 2118 // 2149 // if(deleteMarker!=NULL) 2150 // { 2151 // delete deleteMarker; 2152 // deleteMarker=NULL; 2153 // } 2119 2154 removalOccured=FALSE; 2120 2155 slNormal = slAct->getFacetNormal(); … … 2195 2230 } 2196 2231 2197 2232 //update lengthOfSearchList 2198 2233 lengthOfSearchList--; 2199 2200 2201 2202 2203 2204 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; 2205 2240 break; 2206 2241 }//if(ctr==fAct->numCodim2Facets) 2207 2242 else //facets are parallel but NOT equal. But this does not imply that there 2208 2243 //is no other facet later in SLA that might be equal. 2209 2244 { 2210 2245 maybe=TRUE; … … 2227 2262 } 2228 2263 slAct = slAct->next; 2229 2264 /* NOTE The following lines must not be here but rather called inside the if-block above. 2230 2265 Otherwise results get crappy. Unfortunately there are two slAct=slAct->next calls now, 2231 2266 (not nice!) but since they are in seperate branches of the if-statement there should not 2232 2267 be a way it gets called twice thus ommiting one facet: 2233 2268 slAct = slAct->next;*/ 2234 2269 //delete deleteMarker; … … 2261 2296 slEnd->setFacetNormal(fNormal); 2262 2297 slEnd->prev = marker; 2263 2298 //Copy codim2-facets 2264 2299 intvec *f2Normal;// = new intvec(this->numVars); 2265 2300 while(f2Act!=NULL) … … 2281 2316 f2Act = f2Act->next; 2282 2317 } 2283 lengthOfSearchList++; 2284 //delete f2Normal; 2318 lengthOfSearchList++; 2285 2319 }//if( (notParallelCtr==lengthOfSearchList && removalOccured==FALSE) || 2286 2320 fAct = fAct->next; … … 2333 2367 2334 2368 int jj=0; 2335 //while(fAct->next!=NULL)2369 2336 2370 while(fAct!=NULL) 2337 2371 { … … 2390 2424 gcOutputFile << this->UCN << endl; 2391 2425 gcOutputFile << "RING" << endl; 2392 gcOutputFile << ringString << endl; 2426 gcOutputFile << ringString << endl; 2427 gcOutputFile << "GCBASISLENGTH" << endl; 2428 gcOutputFile << IDELEMS(gc.gcBasis) << endl; 2393 2429 //Write this->gcBasis into file 2394 2430 gcOutputFile << "GCBASIS" << endl; … … 2446 2482 /** \brief Reads a cone from a file identified by its number 2447 2483 */ 2448 void gcone::readConeFromFile(int UCN )2484 void gcone::readConeFromFile(int UCN, gcone *gc) 2449 2485 { 2450 2486 //int UCN=gc.UCN; 2451 2487 stringstream ss; 2452 2488 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 2455 2497 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 2458 2501 char suffix[]=".sg"; 2459 2502 char *filename=strcat(prefix,UCNstring); … … 2462 2505 ifstream gcInputFile(filename, ifstream::in); 2463 2506 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 2464 2616 gcInputFile.close(); 2617 rChangeCurrRing(saveRing); 2465 2618 } 2466 2619 … … 2546 2699 res = inputIdeal; 2547 2700 } 2701 dd_free_global_constants(); 2548 2702 /*As of now extra.cc expects gfan to return type ideal. Probably this will change in near future. 2549 2703 The return type will then be of type LIST_CMD -
kernel/gfan.h
r609fa7 rbec3b0 3 3 4 4 $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:22monerjan Exp $7 $Id: gfan.h,v 1. 9 2009-10-01 16:50:22monerjan 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 $ 8 8 */ 9 9 #ifdef HAVE_GFAN … … 177 177 dd_MatrixPtr facets2Matrix(gcone const &gc); 178 178 void writeConeToFile(gcone const &gc, bool usingIntPoints=FALSE); 179 void readConeFromFile(int gcNum );179 void readConeFromFile(int gcNum, gcone *gc); 180 180 friend class facet; 181 181 };
Note: See TracChangeset
for help on using the changeset viewer.