Changeset e2e3ad in git for kernel/gfan.cc
- Timestamp:
- Nov 20, 2009, 6:01:20 PM (14 years ago)
- Branches:
- (u'spielwiese', 'e7cc1ebecb61be8b9ca6c18016352af89940b21a')
- Children:
- 1d77dffe7911bafa212ddec6401c158b5357fe6c
- Parents:
- 68b081826cda1d5edc4a5c9adb3f9ead2a95c338
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/gfan.cc
r68b081 re2e3ad 205 205 intvec *facet::getFacetNormal() 206 206 { 207 return this->fNormal;207 return ivCopy(this->fNormal); 208 208 } 209 209 … … 321 321 * This constructor takes the root ring and the root ideal as parameters and stores 322 322 * them in the private members gcone::rootRing and gcone::inputIdeal 323 * This constructor is only called once in the computation of the Gröbner fan, 324 * namely for the very first cone. Therefore pred is set to 1. 325 * Might set it to this->UCN though... 323 326 * Since knowledge of the root ring is only needed when using reverse search, 324 327 * this constructor is not needed when using the "second" method … … 329 332 this->prev=NULL; 330 333 this->facetPtr=NULL; 331 this->rootRing=r;334 // this->rootRing=r; 332 335 this->inputIdeal=I; 333 336 this->baseRing=currRing; 334 337 this->counter++; 335 this->UCN=this->counter; 338 this->UCN=this->counter; 339 this->pred=1; 336 340 this->numFacets=0; 337 341 this->ivIntPt=NULL; … … 350 354 this->numVars=gc.numVars; 351 355 this->counter++; 352 this->UCN=this->counter; 356 this->UCN=this->counter; 357 this->pred=gc.UCN; 353 358 this->facetPtr=NULL; 354 359 this->gcBasis=idCopy(f.flipGB); … … 357 362 this->numFacets=0; 358 363 this->ivIntPt=NULL; 359 this->rootRing=NULL;364 // this->rootRing=NULL; 360 365 //rComplete(this->baseRing); 361 366 //rChangeCurrRing(this->baseRing); … … 370 375 if(this->inputIdeal!=NULL) 371 376 idDelete((ideal *)&this->inputIdeal); 372 if (this->rootRing!=NULL && this->rootRing!=(ip_sring *)0xfefefefefefefefe)373 rDelete(this->rootRing);377 // if (this->rootRing!=NULL && this->rootRing!=(ip_sring *)0xfefefefefefefefe) 378 // rDelete(this->rootRing); 374 379 //rDelete(this->baseRing); 375 380 facet *fAct; … … 532 537 return -1; 533 538 } 539 540 int gcone::getPredUCN() 541 { 542 return this->pred; 543 } 544 534 545 /** \brief Compute the normals of the cone 535 546 * … … 547 558 void gcone::getConeNormals(ideal const &I, bool compIntPoint) 548 559 { 549 #ifdef gfan_DEBUG550 std::cout << "*** Computing Inequalities... ***" << std::endl;551 #endif552 //All variables go here - except ineq matrix and *v, see below553 int lengthGB=IDELEMS(I); // # of polys in the groebner basis554 int pCompCount; // # of terms in a poly555 560 poly aktpoly; 556 int numvar = pVariables; // # of variables in currRing 557 // int leadexp[numvar]; // dirty hack of exp.vects 558 // int aktexp[numvar]; 559 int cols,rows; // will contain the dimensions of the ineq matrix - deprecated by 561 int rows; // will contain the dimensions of the ineq matrix - deprecated by 560 562 dd_rowrange ddrows; 561 563 dd_colrange ddcols; … … 564 566 dd_rowindex ddnewpos; // all to make dd_Canonicalize happy 565 567 dd_NumberType ddnumb=dd_Integer; //Number type 566 dd_ErrorType dderr=dd_NoError; // 567 // End of var declaration 568 #ifdef gfan_DEBUG 569 // cout << "The Groebner basis has " << lengthGB << " elements" << endl; 570 // cout << "The current ring has " << numvar << " variables" << endl; 571 #endif 572 cols = numvar; 573 568 dd_ErrorType dderr=dd_NoError; 574 569 //Compute the # inequalities i.e. rows of the matrix 575 570 rows=0; //Initialization … … 579 574 rows=rows+pLength(aktpoly)-1; 580 575 } 581 #ifdef gfan_DEBUG 582 // cout << "rows=" << rows << endl; 583 // cout << "Will create a " << rows << " x " << cols << " matrix to store inequalities" << endl; 584 #endif 576 585 577 dd_rowrange aktmatrixrow=0; // needed to store the diffs of the expvects in the rows of ddineq 586 578 dd_set_global_constants(); 587 579 ddrows=rows; 588 ddcols= cols;580 ddcols=this->numVars; 589 581 dd_MatrixPtr ddineq; //Matrix to store the inequalities 590 582 ddineq=dd_CreateMatrix(ddrows,ddcols+1); //The first col has to be 0 since cddlib checks for additive consts there … … 594 586 { 595 587 aktpoly=(poly)I->m[i]; //get aktpoly as i-th component of I 596 pCompCount=pLength(aktpoly); //How many terms does aktpoly consist of? 597 #ifdef gfan_DEBUG 598 // cout << "Poly No. " << i << " has " << pCompCount << " components" << endl; 599 #endif 600 601 // int *v=(int *)omAlloc((numvar+1)*sizeof(int)); 602 // pGetExpV(aktpoly,v); //find the exp.vect in v[1],...,v[n], use pNext(p) 603 // 604 // //Store leadexp for aktpoly 605 // for (int kk=0;kk<numvar;kk++) 606 // { 607 // leadexp[kk]=v[kk+1]; 608 // //Since we need to know the difference of leadexp with the other expvects we do nothing here 609 // //but compute the diff below 610 // } 611 // 612 // 613 // while (pNext(aktpoly)!=NULL) //move to next term until NULL 614 // { 615 // aktpoly=pNext(aktpoly); 616 // pSetm(aktpoly); //doesn't seem to help anything 617 // pGetExpV(aktpoly,v); 618 // 619 // for (int kk=0;kk<numvar;kk++) 620 // { 621 // aktexp[kk]=v[kk+1]; 622 // //ineq[aktmatrixrow][kk]=leadexp[kk]-aktexp[kk]; //dito 623 // dd_set_si(ddineq->matrix[(dd_rowrange)aktmatrixrow][kk+1],leadexp[kk]-aktexp[kk]); //because of the 1st col being const 0 624 // } 625 // aktmatrixrow=aktmatrixrow+1; 626 // }//while 627 // omFree(v); 628 629 //simpler version of the above 630 int *leadexpv=(int*)omAlloc((numvar+1)*sizeof(int)); 631 int *tailexpv=(int*)omAlloc((numvar+1)*sizeof(int)); 588 //simpler version of storing expvect diffs 589 int *leadexpv=(int*)omAlloc(((this->numVars)+1)*sizeof(int)); 590 int *tailexpv=(int*)omAlloc(((this->numVars)+1)*sizeof(int)); 632 591 pGetExpV(aktpoly,leadexpv); 633 592 while(pNext(aktpoly)!=NULL) … … 635 594 aktpoly=pNext(aktpoly); 636 595 pGetExpV(aktpoly,tailexpv); 637 for(int kk=1;kk<= numvar;kk++)596 for(int kk=1;kk<=this->numVars;kk++) 638 597 { 639 598 dd_set_si(ddineq->matrix[(dd_rowrange)aktmatrixrow][kk],leadexpv[kk]-tailexpv[kk]); … … 642 601 } 643 602 omFree(tailexpv); 644 omFree(leadexpv); 645 603 omFree(leadexpv); 646 604 } //for 647 648 605 #if true 649 606 /*Let's make the preprocessing here. This could already be done in the above for-loop, … … 666 623 tmp=mpq_get_d(ddineq->matrix[ii][jj]); 667 624 (*gamma)[jj-1]=(int)tmp; 668 // (*gamma)[jj]=(ddineq->matrix[ii][jj]);669 625 } 670 626 computeInv((ideal&)I,initialForm,*gamma); … … 751 707 //Maybe add another row to contain the constraints of the standard simplex? 752 708 753 #ifdef gfan_DEBUG 754 // cout << "The inequality matrix is" << endl; 755 // dd_WriteMatrix(stdout, ddineq); 756 #endif 757 758 // The inequalities are now stored in ddineq 759 // Next we check for superflous rows 760 // time_t canonicalizeTic, canonicalizeTac; 761 // time(&canonicalizeTic); 762 // ddredrows = dd_RedundantRows(ddineq, &dderr); 763 // if (dderr!=dd_NoError) // did an error occur? 764 // { 765 // dd_WriteErrorMessages(stderr,dderr); //if so tell us 766 // } 767 #ifdef gfan_DEBUG 768 // else 769 // { 770 // cout << "Redundant rows: "; 771 // set_fwrite(stdout, ddredrows); //otherwise print the redundant rows 772 // }//if dd_Error 773 #endif 774 //Remove reduntant rows here! 775 //Necessary check here! C.f. FJT p18 776 709 710 //Remove redundant rows here! 711 //Necessary check here! C.f. FJT p18 777 712 dd_MatrixCanonicalize(&ddineq, &ddlinset, &ddredrows, &ddnewpos, &dderr); 778 //time(&canonicalizeTac);779 //cout << "dd_MatrixCanonicalize time: " << difftime(canonicalizeTac,canonicalizeTic) << "sec" << endl;713 //time(&canonicalizeTac); 714 //cout << "dd_MatrixCanonicalize time: " << difftime(canonicalizeTac,canonicalizeTic) << "sec" << endl; 780 715 ddrows = ddineq->rowsize; //Size of the matrix with redundancies removed 781 716 ddcols = ddineq->colsize; … … 783 718 //ddCreateMatrix(ddrows,ddcols+1); 784 719 ddFacets = dd_CopyMatrix(ddineq); 785 #ifdef gfan_DEBUG786 // cout << "Having removed redundancies, the normals now read:" << endl;787 // dd_WriteMatrix(stdout,ddineq);788 // cout << "Rows = " << ddrows << endl;789 // cout << "Cols = " << ddcols << endl;790 #endif791 720 792 721 /*Write the normals into class facet*/ 793 #ifdef gfan_DEBUG794 // cout << "Creating list of normals" << endl;795 #endif796 722 /*The pointer *fRoot should be the return value of this function*/ 797 798 799 723 //facet *fRoot = new facet(); //instantiate new facet 724 //fRoot->setUCN(this->getUCN()); 725 //this->facetPtr = fRoot; //set variable facetPtr of class gcone to first facet 800 726 facet *fAct; //pointer to active facet 801 727 //fAct = fRoot; //Seems to do the trick. fRoot and fAct have to point to the same adress! … … 809 735 double foo; 810 736 foo = mpq_get_d(ddineq->matrix[kk][jj]); 811 #ifdef gfan_DEBUG 812 // std::cout << "fAct is " << foo << " at " << fAct << std::endl; 813 #endif 814 (*load)[jj-1] = (int)foo; //store typecasted entry at pos jj-1 of load 737 (*load)[jj-1] = (int)foo; //store typecasted entry at pos jj-1 of load 815 738 }//for (int jj = 1; jj <ddcols; jj++) 816 739 817 740 /*Quick'n'dirty hack for flippability*/ 818 bool isFlip=FALSE; 819 741 bool isFlip=FALSE; 820 742 for (int jj = 0; jj<load->length(); jj++) 821 743 { … … 829 751 break; //URGHS 830 752 } 831 } 753 delete ivCanonical; 754 }/*End of check for flippability*/ 832 755 if (isFlip==FALSE) 833 756 { … … 873 796 fAct->setUCN(this->getUCN()); 874 797 }//if (isFlippable==FALSE) 875 //delete load;798 delete load; 876 799 }//for (int kk = 0; kk<ddrows; kk++) 877 800 … … 879 802 if(numNonFlip==this->numFacets) 880 803 { 881 cerr << "Only non-flippable facets. Terminating..." << endl;804 WerrorS ("Only non-flippable facets. Terminating...\n"); 882 805 } 883 806 … … 902 825 interiorPoint(ddineq, *iv); //NOTE ddineq contains non-flippable facets 903 826 this->setIntPoint(iv); //stores the interior point in gcone::ivIntPt 904 //delete iv;827 delete iv; 905 828 } 906 829 … … 913 836 dd_FreeMatrix(ddineq); 914 837 set_free(ddredrows); 838 set_free(ddlinset); 915 839 //free(ddnewpos); 916 840 //set_free(ddlinset); … … 952 876 set_addelem(ddakt->linset,ii+1); 953 877 dd_MatrixCanonicalize(&ddakt, &impl_linset, &redset, &newpos, &err); 954 955 #ifdef gfan_DEBUG956 // cout << "Codim2 matrix"<<endl;957 // dd_WriteMatrix(stdout,ddakt);958 #endif959 878 ddpolyh=dd_DDMatrix2Poly(ddakt, &err); 960 879 P=dd_CopyGenerators(ddpolyh); 961 #ifdef gfan_DEBUG 962 // cout << "Codim2 facet:" << endl; 963 // dd_WriteMatrix(stdout,P); 964 // cout << endl; 965 #endif 966 967 /* We loop through each row of P 968 * normalize it by making all entries integer ones 969 * and add the resulting vector to the int matrix facet::codim2Facets 970 */ 880 /* We loop through each row of P normalize it by making all 881 * entries integer ones and add the resulting vector to the 882 * int matrix facet::codim2Facets */ 971 883 for (int jj=1;jj<=P->rowsize;jj++) 972 884 { … … 1000 912 dd_set_si(shiftMatrix->matrix[kk][kk+1],1); 1001 913 } 1002 intPointMatrix=dd_MatrixAppend(ddakt,shiftMatrix); 1003 //dd_WriteMatrix(stdout,intPointMatrix); 914 intPointMatrix=dd_MatrixAppend(ddakt,shiftMatrix); 1004 915 interiorPoint(intPointMatrix,*iv_intPoint); 1005 916 for(int ll=0;ll<this->numVars;ll++) … … 1014 925 fAct = fAct->next; 1015 926 dd_FreeMatrix(ddakt); 1016 // dd_FreeMatrix(ddineq); 927 // dd_FreeMatrix(ddineq); 928 dd_FreeMatrix(shiftMatrix); 929 dd_FreeMatrix(intPointMatrix); 1017 930 dd_FreePolyhedra(ddpolyh); 1018 931 delete iv_intPoint; 1019 }//while 932 }//for 933 dd_FreeMatrix(ddineq); 1020 934 } 1021 935 … … 1037 951 intvec *fNormal = new intvec(this->numVars); //facet normal, check for parallelity 1038 952 fNormal = f->getFacetNormal(); //read this->fNormal; 1039 //#ifdef gfan_DEBUG 1040 //std::cout << "===" << std::endl; 953 1041 954 std::cout << "running gcone::flip" << std::endl; 1042 955 std::cout << "flipping UCN " << this->getUCN() << endl; 1043 // for(int ii=0;ii<IDELEMS(gb);ii++) //not very handy with large examples1044 // {1045 // pWrite((poly)gb->m[ii]);1046 // }1047 956 cout << "over facet ("; 1048 957 fNormal->show(1,0); 1049 958 cout << ") with UCN " << f->getUCN(); 1050 959 std::cout << std::endl; 1051 //#endif 960 1052 961 /*1st step: Compute the initial ideal*/ 1053 962 /*poly initialFormElement[IDELEMS(gb)];*/ //array of #polys in GB to store initial form 1054 963 ideal initialForm=idInit(IDELEMS(gb),this->gcBasis->rank); 1055 poly aktpoly; 1056 /*intvec *check = new intvec(this->numVars);*/ //array to store the difference of LE and v 964 poly aktpoly; 1057 965 computeInv(gb,initialForm,*fNormal); 1058 966 //NOTE The code below went into gcone::computeInv … … 1062 970 //f->printFlipGB();*/ 1063 971 // cout << "===" << endl; 1064 #endif 1065 //delete check; 1066 972 #endif 1067 973 /*2nd step: lift initial ideal to a GB of the neighbouring cone using minus alpha as weight*/ 1068 974 /*Substep 2.1 … … 1093 999 rComplete(tmpRing); 1094 1000 } 1001 delete fNormal; //NOTE: Why does this crash? 1095 1002 rChangeCurrRing(tmpRing); 1096 1003 … … 1266 1173 // NOTE May assume that at this point srcRing already has 3 blocks of orderins, starting with a 1267 1174 // Thus: 1268 //ring dstRing=rCopyAndChangeWeight(srcRing,iv_weight); 1269 //cout << "PLING" << endl; 1270 /*ring dstRing=rCopy0(srcRing); 1271 for (int ii=0;ii<this->numVars;ii++) 1272 { 1273 dstRing->wvhdl[0][ii]=(*iv_weight)[ii]; 1274 }*/ 1175 //ring dstRing=rCopyAndChangeWeight(srcRing,iv_weight); 1275 1176 ring dstRing=rCopy0(tmpRing); 1276 1177 int length=iv_weight->length(); … … 1285 1186 //rDelete(tmpRing); 1286 1187 delete iv_weight; 1287 //#ifdef gfan_DEBUG 1288 rWrite(dstRing); cout << endl;1289 //#endif 1188 1189 //rWrite(dstRing); cout << endl; 1190 1290 1191 ideal dstRing_I; 1291 1192 dstRing_I=idrCopyR(srcRing_HH,srcRing); 1292 1293 1193 //dstRing_I=idrCopyR(inputIdeal,srcRing); 1194 //validOpts<1>=TRUE; 1294 1195 #ifdef gfan_DEBUG 1295 1196 //idShow(dstRing_I); 1296 1197 #endif 1297 1198 BITSET save=test; … … 1316 1217 //#ifdef gfan_DEBUG 1317 1218 cout << "Flipped GB is UCN " << counter+1 << ":" << endl; 1318 // f->printFlipGB(); 1319 this->idDebugPrint(dstRing_I); 1320 cout << endl; 1219 // this->idDebugPrint(dstRing_I); 1220 // cout << endl; 1321 1221 //#endif 1322 1222 rChangeCurrRing(srcRing); //return to the ring we started the computation of flipGB in … … 1438 1338 intvec *gcone::ivNeg(const intvec *iv) 1439 1339 { 1340 //NOTE: Can't this be done without new? 1440 1341 intvec *res = new intvec(iv->length()); 1441 1342 res=ivCopy(iv); … … 1790 1691 We always choose the first facet from fListPtr as facet to be flipped 1791 1692 */ 1792 time_t tic, tac;1693 // time_t tic, tac; 1793 1694 while((SearchListAct!=NULL))// && counter<10) 1794 1695 {//NOTE See to it that the cone is only changed after ALL facets have been flipped! … … 1804 1705 rComplete(rTmp); 1805 1706 rChangeCurrRing(rTmp); 1806 gcone *gcTmp = new gcone::gcone(*gcAct,*fAct); 1707 gcone *gcTmp = new gcone::gcone(*gcAct,*fAct);//copy constructor! 1807 1708 /* Now gcTmp->gcBasis and gcTmp->baseRing are set from fAct->flipGB and fAct->flipRing. 1808 1709 * Since we come at most once across a given facet from gcAct->facetPtr we can delete them. … … 2679 2580 res->m[ii].rtyp=LIST_CMD; 2680 2581 lists l=(lists)omAllocBin(slists_bin); 2681 l->Init( 5);2582 l->Init(6); 2682 2583 l->m[0].rtyp=INT_CMD; 2683 2584 l->m[0].data=(void*)gcAct->getUCN(); … … 2708 2609 l->m[4].rtyp=RING_CMD; 2709 2610 l->m[4].data=(void*)(gcAct->getBaseRing()); 2710 2611 l->m[5].rtyp=INT_CMD; 2612 l->m[5].data=(void*)gcAct->getPredUCN(); 2711 2613 res->m[ii].data=(void*)l; 2712 2614 gcAct = gcAct->next;
Note: See TracChangeset
for help on using the changeset viewer.