Changeset f26ea0 in git
- Timestamp:
- Jun 9, 2009, 5:23:08 PM (14 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- 3231f3dc7a66f525efae0e24ca084a7703a2bb7f
- Parents:
- 44ab6bc29303a0aa0c6a2c8d1708d78ac34d6f28
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/gfan.cc
r44ab6b rf26ea0 2 2 Compute the Groebner fan of an ideal 3 3 $Author: monerjan $ 4 $Date: 2009-0 5-29 07:52:12$5 $Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.5 7 2009-05-29 07:52:12monerjan Exp $6 $Id: gfan.cc,v 1.5 7 2009-05-29 07:52:12monerjan Exp $4 $Date: 2009-06-09 15:23:08 $ 5 $Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.58 2009-06-09 15:23:08 monerjan Exp $ 6 $Id: gfan.cc,v 1.58 2009-06-09 15:23:08 monerjan Exp $ 7 7 */ 8 8 … … 239 239 /* TODO in order to save memory use pointers to rootRing and inputIdeal instead */ 240 240 intvec *ivIntPt; //an interior point of the cone 241 int UCN; //unique number of the cone241 static int UCN; //unique number of the cone 242 242 243 243 public: … … 264 264 { 265 265 this->next=NULL; 266 this->facetPtr=NULL; //maybe this->facetPtr = new facet(); 266 this->facetPtr=NULL; //maybe this->facetPtr = new facet(); 267 267 this->baseRing=currRing; 268 this->UCN =1;268 this->UCN++; 269 269 this->numFacets=0; 270 270 } … … 280 280 { 281 281 this->next=NULL; 282 this->facetPtr=NULL; 282 this->facetPtr=NULL; 283 283 this->rootRing=r; 284 284 this->inputIdeal=I; 285 285 this->baseRing=currRing; 286 this->UCN =1;286 this->UCN++; 287 287 this->numFacets=0; 288 288 } … … 290 290 /** \brief Copy constructor 291 291 * 292 * Copies onecone, sets this->gcBasis to the flipped GB and reverses the292 * Copies a cone, sets this->gcBasis to the flipped GB and reverses the 293 293 * direction of the according facet normal 294 * Call this only after a successfull call to gcone::flip which sets facet::flipGB 294 295 */ 295 296 //NOTE Prolly need to specify the facet to flip over … … 302 303 this->facetPtr=fAct; 303 304 304 intvec *ivtmp = new intvec(this->numVars); 305 intvec *ivtmp = new intvec(this->numVars); 306 //NOTE ivtmp = f->getFacetNormal(); 305 307 ivtmp = gc.facetPtr->getFacetNormal(); 306 308 307 309 ideal gb; 310 //NOTE gb=f->getFlipGB(); 308 311 gb=gc.facetPtr->getFlipGB(); 309 312 this->gcBasis=gb; //this cone's GB is the flipped GB … … 345 348 } 346 349 347 void showFacets() 348 { 349 facet *f = new facet(); 350 f = this->facetPtr; 350 void showFacets(short codim=1) 351 { 352 facet *f; 353 switch(codim) 354 { 355 case 1: 356 f = this->facetPtr; 357 break; 358 case 2: 359 f = this->facetPtr->codim2Ptr; 360 break; 361 } 362 351 363 intvec *iv = new intvec(this->numVars); 352 364 … … 357 369 f=f->next; 358 370 } 359 //delete iv; 360 //delete f; 361 } 371 //delete iv; 372 } 362 373 363 374 /** \brief Set gcone::numFacets */ … … 586 597 }//method getConeNormals(ideal I) 587 598 599 /** \brief Compute the (codim-2)-facets of a given cone 600 * This method is used during noRevS 601 */ 602 void getCodim2Normals(gcone const &gc) 603 { 604 this->facetPtr->codim2Ptr = new facet(2); //instantiate a (codim-2)-facet 605 facet *codim2Act; 606 codim2Act = this->facetPtr->codim2Ptr; 607 608 dd_set_global_constants(); 609 610 dd_MatrixPtr ddineq,P,ddakt; 611 dd_rowset impl_linset, redset; 612 dd_ErrorType err; 613 dd_rowindex newpos; 614 615 ddineq = facets2Matrix(gc); //get a matrix representation of the cone 616 617 /*Now set appropriate linearity*/ 618 dd_PolyhedraPtr ddpolyh; 619 for (int ii=0; ii<this->numFacets; ii++) 620 { 621 ddakt = dd_CopyMatrix(ddineq); 622 set_addelem(ddakt->linset,ii+1); 623 624 dd_MatrixCanonicalize(&ddakt, &impl_linset, &redset, &newpos, &err); 625 626 //dd_WriteMatrix(stdout,ddakt); 627 ddpolyh=dd_DDMatrix2Poly(ddakt, &err); 628 P=dd_CopyGenerators(ddpolyh); 629 dd_WriteMatrix(stdout,P); 630 631 /* We loop through each row of P 632 * normalize it by making all entries integer ones 633 * and add the resulting vector to the int matrix facet::codim2Facets 634 */ 635 for (int jj=1;jj<=P->rowsize;jj++) 636 { 637 intvec *n = new intvec(this->numVars); 638 makeInt(P,jj,*n); 639 codim2Act->setFacetNormal(n); 640 codim2Act->next = new facet(2); 641 codim2Act = codim2Act->next; 642 delete n; 643 } 644 645 dd_FreeMatrix(ddakt); 646 dd_FreePolyhedra(ddpolyh); 647 } 648 } 588 649 589 650 /** \brief Compute the Groebner Basis on the other side of a shared facet … … 1375 1436 { 1376 1437 facet *fListPtr = new facet(); //The list containing ALL facets we come across 1377 facet *fAct = new facet();1438 facet *fAct;// = new facet(); 1378 1439 fAct = gc.facetPtr; 1379 1440 fListPtr = gc.facetPtr; 1380 1441 #ifdef gfan_DEBUG 1381 1442 cout << "NoRevs" << endl; 1382 1443 cout << "Facets are:" << endl; 1383 1444 gc.showFacets(); 1384 #endif 1385 1386 dd_set_global_constants(); 1445 #endif 1446 //dd_set_global_constants(); 1387 1447 dd_rowrange ddrows; 1388 1448 dd_colrange ddcols; … … 1420 1480 else/*Facets of facets*/ 1421 1481 { 1422 dd_MatrixPtr ddineq,P,ddakt;1423 dd_rowset impl_linset, redset;1424 dd_ErrorType err;1425 dd_rowindex newpos;1426 1482 1427 fAct = fListPtr; 1428 1429 #ifdef gfan_DEBUG 1430 cout << "before f2M" << endl; 1431 gc.showFacets(); 1432 ddineq = facets2Matrix(gc); 1433 cout << "after f2M" << endl; 1434 gc.showFacets(); 1435 #endif 1483 this->getCodim2Normals(gc); 1436 1484 1437 /*Now set appropriate linearity*/ 1438 dd_PolyhedraPtr ddpolyh; 1439 for (int ii=0; ii<this->numFacets; ii++) 1440 { 1441 cout << endl << "------------" << endl; 1442 ddakt = dd_CopyMatrix(ddineq); 1443 set_addelem(ddakt->linset,ii+1); 1444 1445 dd_MatrixCanonicalize(&ddakt, &impl_linset, &redset, &newpos, &err); 1446 1447 //dd_WriteMatrix(stdout,ddakt); 1448 ddpolyh=dd_DDMatrix2Poly(ddakt, &err); 1449 P=dd_CopyGenerators(ddpolyh); 1450 dd_WriteMatrix(stdout,P); 1451 1452 /* We loop through each row of P 1453 * normalize it by making all entries integer ones 1454 * and add the resulting vector to the int matrix facet::codim2Facets 1455 */ 1456 this->facetPtr->codim2Ptr = new facet(2); //construct a (codim-2)-facet 1457 facet *codim2Act; 1458 codim2Act = this->facetPtr->codim2Ptr; 1459 for (int jj=1;jj<=P->rowsize;jj++) 1460 { 1461 intvec *n = new intvec(this->numVars); 1462 normalize(P,jj,*n); 1463 codim2Act->setFacetNormal(n); 1464 codim2Act->next = new facet(2); 1465 codim2Act = codim2Act->next; 1466 n->show(); 1467 delete n; 1468 } 1469 1470 dd_FreeMatrix(ddakt); 1471 dd_FreePolyhedra(ddpolyh); 1472 } 1473 } 1485 //Compute unique representation of codim-2-facets 1486 this->normalize(); 1487 1488 gc.writeConeToFile(gc); 1489 1490 /*2nd step 1491 Choose a facet from fListPtr, flip it and forget the previous cone 1492 We always choose the first facet from fListPtr as facet to be flipped 1493 */ 1494 1495 1496 1497 }//else usingIntPoint 1498 1499 1474 1500 1475 1501 1476 1502 //NOTE Hm, comment in and get a crash for free... 1477 1503 //dd_free_global_constants(); 1478 gc.writeConeToFile(gc); 1479 1480 /*2nd step 1481 Choose a facet from fListPtr, flip it and forget the previous cone 1482 */ 1483 fAct = fListPtr; 1504 //gc.writeConeToFile(gc); 1505 1506 1507 //fAct = fListPtr; 1484 1508 //gcone *gcTmp = new gcone(gc); //copy 1485 1509 //gcTmp->flip(gcTmp->gcBasis,fAct); … … 1491 1515 /** \brief Make a set of rational vectors into integers 1492 1516 * 1493 * We compute the lcm of the denominators and multiply with this to get integer values 1517 * We compute the lcm of the denominators and multiply with this to get integer values. 1494 1518 * \param dd_MatrixPtr,intvec 1495 1519 */ 1496 void normalize(dd_MatrixPtr const &M, int const line, intvec &n)1520 void makeInt(dd_MatrixPtr const &M, int const line, intvec &n) 1497 1521 { 1498 1522 mpz_t denom[this->numVars]; … … 1545 1569 1546 1570 } 1571 /** 1572 * We compute the gcd of the components of the codim-2-facets and 1573 * multiply the each codim-2facet by it. Thus we get a normalized representation of each 1574 * (codim-2)-facet normal. 1575 */ 1576 void normalize() 1577 { 1578 int ggT=1; 1579 facet *codim2Act; 1580 codim2Act = this->facetPtr->codim2Ptr; 1581 intvec *n = new intvec(this->numVars); 1582 1583 while(codim2Act->next!=NULL) 1584 { 1585 n=codim2Act->getFacetNormal(); 1586 for(int ii=0;ii<this->numVars;ii++) 1587 { 1588 ggT = intgcd(ggT,(*n)[ii]); 1589 } 1590 codim2Act = codim2Act->next; 1591 } 1592 //delete n; 1593 codim2Act = this->facetPtr->codim2Ptr; //reset to start of linked list 1594 while(codim2Act->next!=NULL) 1595 { 1596 //intvec *n = new intvec(this->numVars); 1597 n=codim2Act->getFacetNormal(); 1598 intvec *new_n = new intvec(this->numVars); 1599 for(int ii=0;ii<this->numVars;ii++) 1600 { 1601 (*new_n)[ii] = (*n)[ii]*ggT; 1602 } 1603 codim2Act->setFacetNormal(new_n); 1604 codim2Act = codim2Act->next; 1605 //delete n; 1606 //delete new_n; 1607 } 1608 } 1609 1610 /** \brief Compute the gcd of two ints 1611 */ 1612 int intgcd(int a, int b) 1613 { 1614 int r, p=a, q=b; 1615 if(p < 0) 1616 p = -p; 1617 if(q < 0) 1618 q = -q; 1619 while(q != 0) 1620 { 1621 r = p % q; 1622 p = q; 1623 q = r; 1624 } 1625 return p; 1626 } 1547 1627 1548 1628 /** \brief Construct a dd_MatrixPtr from a cone's list of facets … … 1551 1631 dd_MatrixPtr facets2Matrix(gcone const &gc) 1552 1632 { 1553 facet *fAct = new facet();1633 facet *fAct; 1554 1634 fAct = gc.facetPtr; 1555 1635 … … 1564 1644 //dd_set_global_constants(); 1565 1645 1566 intvec *comp = new intvec(this->numVars); 1567 1568 for (int jj=0; jj<M->rowsize; jj++) 1569 { 1646 //intvec *comp = new intvec(this->numVars); 1647 1648 /*for (int jj=0; jj<M->rowsize; jj++) 1649 { 1650 intvec *comp = new intvec(this->numVars); 1570 1651 comp = fAct->getFacetNormal(); 1571 1652 for (int ii=0; ii<this->numVars; ii++) … … 1577 1658 fAct = fAct->next; 1578 1659 } 1660 delete comp; 1579 1661 }//jj 1580 1581 //delete fAct; 1582 //delete comp; 1662 */ 1663 int jj=0; 1664 while(fAct->next!=NULL) 1665 { 1666 intvec *comp; 1667 comp = fAct->getFacetNormal(); 1668 for(int ii=0;ii<this->numVars;ii++) 1669 { 1670 dd_set_si(M->matrix[jj][ii+1],(*comp)[ii]); 1671 } 1672 jj++; 1673 fAct=fAct->next; 1674 } 1675 1583 1676 return M; 1584 1677 } … … 1649 1742 friend class facet; 1650 1743 };//class gcone 1744 1745 int gcone::UCN=0; 1651 1746 1652 1747 ideal gfan(ideal inputIdeal)
Note: See TracChangeset
for help on using the changeset viewer.