Changeset 87d8d5 in git
- Timestamp:
- Mar 16, 2011, 8:05:04 PM (12 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- a513d10db695283b0b6578322ae02304f8cf82d2
- Parents:
- 950214e56df8e233d791b1abc2c8674661d285d0
- Location:
- kernel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/gfan.cc
r950214e r87d8d5 13 13 #include <kernel/kstd1.h> 14 14 #include <kernel/kutil.h> 15 //#include "int64vec.h"15 #include "int64vec.h" 16 16 #include <kernel/polys.h> 17 17 #include <kernel/ideals.h> 18 18 #include <kernel/kmatrix.h> 19 19 #include <kernel/GMPrat.h> 20 //#include "fast_maps.h" //Mapping of ideals21 //#include "maps.h"22 #include "ring.h" //apparently not needed23 //#include "structs.h"20 #include "fast_maps.h" //Mapping of ideals 21 #include "maps.h" 22 #include "ring.h" apparently not needed 23 #include "structs.h" 24 24 #include <Singular/lists.h> 25 25 #include <kernel/prCopy.h> 26 26 #include <kernel/stairc.h> 27 //#include <bitset>28 #include <fstream> //read-write cones to files29 //#include <gmp.h>27 #include <bitset> 28 #include <fstream> read-write cones to files 29 #include <gmp.h> 30 30 #include <string> 31 31 #include <sstream> 32 //#include <time.h>32 #include <time.h> 33 33 #include <stdlib.h> 34 //#include <gmpxx.h>35 //#include <vector>34 #include <gmpxx.h> 35 #include <vector> 36 36 #include <assert.h> 37 37 … … 42 42 #endif 43 43 44 //Hacks for different working places44 Hacks for different working places 45 45 #define p800 46 46 … … 68 68 69 69 #ifndef gfan_DEBUG 70 //#define gfan_DEBUG70 #define gfan_DEBUG 71 71 #ifndef gfan_DEBUGLEVEL 72 72 #define gfan_DEBUGLEVEL 1 … … 74 74 #endif 75 75 76 //NOTE Defining this will slow things down!77 //Only good for very coarse profiling78 //#define gfanp76 NOTE Defining this will slow things down! 77 Only good for very coarse profiling 78 #define gfanp 79 79 #ifdef gfanp 80 80 #include <sys/time.h> … … 96 96 * 97 97 */ 98 98 99 99 /** \brief The default constructor for facets 100 100 */ 101 facet::facet() 102 { 103 //Pointer to next facet. */101 facet::facet() 102 { 103 Pointer to next facet. */ 104 104 /* Defaults to NULL. This way there is no need to check explicitly */ 105 105 this->fNormal=NULL; 106 this->interiorPoint=NULL; 106 this->interiorPoint=NULL; 107 107 this->UCN=0; 108 108 this->codim2Ptr=NULL; 109 this->codim=1; //default for (codim-1)-facets109 this->codim=1; default for (codim-1)-facets 110 110 this->numCodim2Facets=0; 111 111 this->numRays=0; 112 112 this->flipGB=NULL; 113 113 this->next=NULL; 114 this->prev=NULL; 115 this->flipRing=NULL; //the ring on the other side114 this->prev=NULL; 115 this->flipRing=NULL; the ring on the other side 116 116 this->isFlippable=FALSE; 117 117 } 118 118 119 119 /** \brief Constructor for facets of codim == 2 120 120 * Note that as of now the code of the constructors is only for facets and codim2-faces. One … … 124 124 { 125 125 this->fNormal=NULL; 126 this->interiorPoint=NULL; 126 this->interiorPoint=NULL; 127 127 this->UCN=0; 128 128 this->codim2Ptr=NULL; … … 130 130 { 131 131 this->codim=n; 132 } //NOTE Handle exception here!132 }NOTE Handle exception here! 133 133 this->numCodim2Facets=0; 134 134 this->numRays=0; … … 139 139 this->isFlippable=FALSE; 140 140 } 141 141 142 142 /** \brief The copy constructor 143 143 * By default only copies the fNormal, f2Normals and UCN … … 148 148 this->UCN=f.UCN; 149 149 this->isFlippable=f.isFlippable; 150 //Needed for flip2151 //NOTE ONLY REFERENCE152 this->interiorPoint=iv64Copy(f.interiorPoint); //only referencing is prolly not the best thing to do in a copy constructor150 Needed for flip2 151 NOTE ONLY REFERENCE 152 this->interiorPoint=iv64Copy(f.interiorPoint);only referencing is prolly not the best thing to do in a copy constructor 153 153 facet* f2Copy; 154 154 f2Copy=f.codim2Ptr; … … 168 168 { 169 169 f2Act=new facet(2); 170 this->codim2Ptr=f2Act; 170 this->codim2Ptr=f2Act; 171 171 } 172 172 else … … 180 180 int64vec *f2Normal; 181 181 f2Normal = f2Copy->getFacetNormal(); 182 //f2Act->setFacetNormal(f2Copy->getFacetNormal());182 f2Act->setFacetNormal(f2Copy->getFacetNormal()); 183 183 f2Act->setFacetNormal(f2Normal); 184 184 delete f2Normal; 185 185 f2Act->setUCN(f2Copy->getUCN()); 186 186 f2Copy = f2Copy->next; 187 } 187 } 188 188 } 189 189 … … 209 209 { 210 210 #ifdef gfan_DEBUG 211 //printf("shallowdel@UCN %i\n", this->getUCN());211 printf("shallowdel@UCN %i\n", this->getUCN()); 212 212 #endif 213 213 this->fNormal=NULL; 214 //this->UCN=0;214 this->UCN=0; 215 215 this->interiorPoint=NULL; 216 216 this->codim2Ptr=NULL; … … 219 219 this->flipGB=NULL; 220 220 this->flipRing=NULL; 221 assert(this->fNormal==NULL); 222 //delete(this);223 } 224 221 assert(this->fNormal==NULL); 222 delete(this); 223 } 224 225 225 /** The default destructor */ 226 226 facet::~facet() 227 227 { 228 228 #ifdef gfan_DEBUG 229 //printf("~facet@UCN %i\n",this->getUCN());229 printf("~facet@UCN %i\n",this->getUCN()); 230 230 #endif 231 231 if(this->fNormal!=NULL) … … 234 234 delete this->interiorPoint; 235 235 /* Cleanup the codim2-structure */ 236 //if(this->codim==2)237 //{238 //facet *codim2Ptr;239 //codim2Ptr = this->codim2Ptr;240 //while(codim2Ptr!=NULL)241 //{242 //if(codim2Ptr->fNormal!=NULL)243 //{244 //delete codim2Ptr->fNormal;//NOTE Do not want this anymore since the rays are now in gcone!245 //codim2Ptr = codim2Ptr->next;246 //}247 //}248 //}249 //The rays are stored in the cone!236 if(this->codim==2) 237 { 238 facet *codim2Ptr; 239 codim2Ptr = this->codim2Ptr; 240 while(codim2Ptr!=NULL) 241 { 242 if(codim2Ptr->fNormal!=NULL) 243 { 244 delete codim2Ptr->fNormal;//NOTE Do not want this anymore since the rays are now in gcone! 245 codim2Ptr = codim2Ptr->next; 246 } 247 } 248 } 249 The rays are stored in the cone! 250 250 if(this->flipGB!=NULL) 251 251 idDelete((ideal *)&this->flipGB); 252 //if(this->flipRing!=NULL && this->flipRing->idroot!=(idhdl)0xfbfbfbfbfbfbfbfb)253 //rDelete(this->flipRing); //See vol II/134254 //this->flipRing=NULL;252 if(this->flipRing!=NULL && this->flipRing->idroot!=(idhdl)0xfbfbfbfbfbfbfbfb) 253 rDelete(this->flipRing); //See vol II/134 254 this->flipRing=NULL; 255 255 this->prev=NULL; 256 256 this->next=NULL; 257 257 } 258 258 259 259 inline const int64vec *facet::getRef2FacetNormal() const 260 260 { 261 261 return(this->fNormal); 262 } 262 } 263 263 264 264 /** Equality check for facets based on unique interior points*/ … … 281 281 } 282 282 } 283 //if( fIntP->compare(gIntP)!=0) res=FALSE;283 if( fIntP->compare(gIntP)!=0) res=FALSE; 284 284 #ifdef gfanp 285 285 gettimeofday(&end, 0); 286 286 gcone::t_areEqual += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec)); 287 #endif 287 #endif 288 288 return res; 289 289 } … … 308 308 int notParallelCtr=0; 309 309 int ctr=0; 310 const int64vec* fNormal; //No new since iv64Copy and therefore getFacetNormal return a new310 const int64vec* fNormal; No new since iv64Copy and therefore getFacetNormal return a new 311 311 const int64vec* sNormal; 312 fNormal = f->getRef2FacetNormal(); //->getFacetNormal();313 sNormal = s->getRef2FacetNormal(); //->getFacetNormal();314 //Do not need parallelity. Too time consuming315 //if(!isParallel(*fNormal,*sNormal))316 //if(fNormal->compare(ivNeg(sNormal))!=0)//This results in a Mandelbug317 //notParallelCtr++;318 //else//parallelity, so we check the codim2-facets312 fNormal = f->getRef2FacetNormal();->getFacetNormal(); 313 sNormal = s->getRef2FacetNormal();->getFacetNormal(); 314 Do not need parallelity. Too time consuming 315 if(!isParallel(*fNormal,*sNormal)) 316 if(fNormal->compare(ivNeg(sNormal))!=0)//This results in a Mandelbug 317 notParallelCtr++; 318 else//parallelity, so we check the codim2-facets 319 319 int64vec *fNRef=const_cast<int64vec*>(fNormal); 320 320 int64vec *sNRef=const_cast<int64vec*>(sNormal); 321 // if(isParallel(*fNormal,*sNormal)) 321 if(isParallel(*fNormal,*sNormal)) 322 322 if(isParallel(*fNRef,*sNRef)) 323 //if(fNormal->compare((sNormal))!=0)//Behold! Teh definitive Mandelbug323 if(fNormal->compare((sNormal))!=0)//Behold! Teh definitive Mandelbug 324 324 { 325 325 facet* f2Act; 326 326 facet* s2Act; 327 f2Act = f->codim2Ptr; 327 f2Act = f->codim2Ptr; 328 328 ctr=0; 329 329 while(f2Act!=NULL) 330 330 { 331 331 const int64vec* f2Normal; 332 f2Normal = f2Act->getRef2FacetNormal(); //->getFacetNormal();333 //int64vec *f2Ref=const_cast<int64vec*>(f2Normal);332 f2Normal = f2Act->getRef2FacetNormal();->getFacetNormal(); 333 int64vec *f2Ref=const_cast<int64vec*>(f2Normal); 334 334 s2Act = s->codim2Ptr; 335 335 while(s2Act!=NULL) 336 336 { 337 337 const int64vec* s2Normal; 338 s2Normal = s2Act->getRef2FacetNormal(); //->getFacetNormal();339 //bool foo=areEqual(f2Normal,s2Normal);340 //int64vec *s2Ref=const_cast<int64vec*>(s2Normal);338 s2Normal = s2Act->getRef2FacetNormal();->getFacetNormal(); 339 bool foo=areEqual(f2Normal,s2Normal); 340 int64vec *s2Ref=const_cast<int64vec*>(s2Normal); 341 341 int foo=f2Normal->compare(s2Normal); 342 342 if(foo==0) 343 343 ctr++; 344 344 s2Act = s2Act->next; 345 //delete s2Normal;346 } 347 //delete f2Normal;345 delete s2Normal; 346 } 347 delete f2Normal; 348 348 f2Act = f2Act->next; 349 } 350 } 351 //delete fNormal;352 //delete sNormal;349 } 350 } 351 delete fNormal; 352 delete sNormal; 353 353 if(ctr==f->numCodim2Facets) 354 354 res=TRUE; … … 365 365 #endif 366 366 return res; 367 //int64vec *foo=ivNeg(sNormal);368 //if(fNormal->compare(foo)!=0) //facet normals369 //{370 //delete foo;371 //res=FALSE;372 //}373 //else374 //{375 //facet* f2Act;376 //facet* s2Act;377 // f2Act = f->codim2Ptr; 378 //ctr=0;379 //while(f2Act!=NULL)380 //{381 //int64vec* f2Normal;382 //f2Normal = f2Act->getFacetNormal();383 //s2Act = s->codim2Ptr;384 //while(s2Act!=NULL)385 //{386 //int64vec* s2Normal;387 //s2Normal = s2Act->getFacetNormal();388 //// bool foo=areEqual(f2Normal,s2Normal);389 //int foo=f2Normal->compare(s2Normal);390 //if(foo==0)391 //ctr++;392 //s2Act = s2Act->next;393 //delete s2Normal;394 //}395 //delete f2Normal;396 //f2Act = f2Act->next;397 //}398 // } 399 //delete fNormal;400 //delete sNormal;401 //if(ctr==f->numCodim2Facets)402 //res=TRUE;403 //return res;404 } 405 367 int64vec *foo=ivNeg(sNormal); 368 if(fNormal->compare(foo)!=0) //facet normals 369 { 370 delete foo; 371 res=FALSE; 372 } 373 else 374 { 375 facet* f2Act; 376 facet* s2Act; 377 f2Act = f->codim2Ptr; 378 ctr=0; 379 while(f2Act!=NULL) 380 { 381 int64vec* f2Normal; 382 f2Normal = f2Act->getFacetNormal(); 383 s2Act = s->codim2Ptr; 384 while(s2Act!=NULL) 385 { 386 int64vec* s2Normal; 387 s2Normal = s2Act->getFacetNormal(); 388 // bool foo=areEqual(f2Normal,s2Normal); 389 int foo=f2Normal->compare(s2Normal); 390 if(foo==0) 391 ctr++; 392 s2Act = s2Act->next; 393 delete s2Normal; 394 } 395 delete f2Normal; 396 f2Act = f2Act->next; 397 } 398 } 399 delete fNormal; 400 delete sNormal; 401 if(ctr==f->numCodim2Facets) 402 res=TRUE; 403 return res; 404 } 405 406 406 /** Stores the facet normal \param int64vec*/ 407 407 inline void facet::setFacetNormal(int64vec *iv) … … 409 409 if(this->fNormal!=NULL) 410 410 delete this->fNormal; 411 this->fNormal = iv64Copy(iv); 412 } 413 414 /** Hopefully returns the facet normal 411 this->fNormal = iv64Copy(iv); 412 } 413 414 /** Hopefully returns the facet normal 415 415 * Mind: iv64Copy returns a new int64vec, so use this in the following way: 416 416 * int64vec *iv; … … 420 420 */ 421 421 inline int64vec *facet::getFacetNormal() const 422 { 422 { 423 423 return iv64Copy(this->fNormal); 424 //return this->fNormal;424 return this->fNormal; 425 425 } 426 426 … … 430 430 fNormal->show(); 431 431 } 432 432 433 433 /** Store the flipped GB*/ 434 434 inline void facet::setFlipGB(ideal I) … … 436 436 this->flipGB=idCopy(I); 437 437 } 438 438 439 439 /** Returns a pointer to the flipped GB 440 440 Seems not be used … … 445 445 return this->flipGB; 446 446 } 447 447 448 448 /** Print the flipped GB*/ 449 449 inline void facet::printFlipGB() … … 453 453 #endif 454 454 } 455 455 456 456 /** Set the UCN */ 457 457 inline void facet::setUCN(int n) … … 459 459 this->UCN=n; 460 460 } 461 462 /** \brief Get the UCN 461 462 /** \brief Get the UCN 463 463 * Returns the UCN iff this != NULL, else -1 464 464 */ … … 474 474 #ifdef NDEBUG 475 475 if(this!=NULL) 476 #endif 476 #endif 477 477 return this->UCN; 478 478 else 479 479 return -1; 480 480 } 481 481 482 482 /** Store an interior point of the facet */ 483 483 inline void facet::setInteriorPoint(int64vec *iv) … … 487 487 this->interiorPoint = iv64Copy(iv); 488 488 } 489 489 490 490 /** Returns a pointer to this->interiorPoint 491 491 * MIND: iv64Copy returns a new int64vec … … 501 501 return (this->interiorPoint); 502 502 } 503 503 504 504 /** \brief Debugging function 505 505 * prints the facet normal an all (codim-2)-facets that belong to it 506 506 */ 507 507 volatile void facet::fDebugPrint() 508 { 509 facet *codim2Act; 508 { 509 facet *codim2Act; 510 510 codim2Act = this->codim2Ptr; 511 511 int64vec *fNormal; 512 fNormal = this->getFacetNormal(); 512 fNormal = this->getFacetNormal(); 513 513 printf("=======================\n"); 514 514 printf("Facet normal = (");fNormal->show(1,1);printf(")\n"); … … 524 524 } 525 525 printf("=======================\n"); 526 delete fNormal; 527 } 528 529 //friend class gcone; //Bad style526 delete fNormal; 527 } 528 529 friend class gcone; //Bad style 530 530 531 531 … … 538 538 539 539 540 /** \brief Default constructor. 540 /** \brief Default constructor. 541 541 * 542 542 * Initialises this->next=NULL and this->facetPtr=NULL … … 546 546 this->next=NULL; 547 547 this->prev=NULL; 548 this->facetPtr=NULL; //maybe this->facetPtr = new facet();548 this->facetPtr=NULL; maybe this->facetPtr = new facet(); 549 549 this->baseRing=currRing; 550 550 this->counter++; 551 this->UCN=this->counter; 551 this->UCN=this->counter; 552 552 this->numFacets=0; 553 553 this->ivIntPt=NULL; 554 554 this->gcRays=NULL; 555 555 } 556 556 557 557 /** \brief Constructor with ring and ideal 558 558 * 559 * This constructor takes the root ring and the root ideal as parameters and stores 559 * This constructor takes the root ring and the root ideal as parameters and stores 560 560 * them in the private members gcone::rootRing and gcone::inputIdeal 561 561 * This constructor is only called once in the computation of the Gröbner fan, … … 569 569 this->next=NULL; 570 570 this->prev=NULL; 571 this->facetPtr=NULL; 571 this->facetPtr=NULL; 572 572 this->inputIdeal=I; 573 573 this->baseRing=currRing; … … 579 579 this->gcRays=NULL; 580 580 } 581 582 /** \brief Copy constructor 581 582 /** \brief Copy constructor 583 583 * 584 584 * Copies a cone, sets this->gcBasis to the flipped GB 585 585 * Call this only after a successful call to gcone::flip which sets facet::flipGB 586 */ 586 */ 587 587 gcone::gcone(const gcone& gc, const facet &f) 588 588 { 589 589 this->next=NULL; 590 //this->prev=(gcone *)&gc; //comment in to get a tree590 this->prev=(gcone *)&gc; //comment in to get a tree 591 591 this->prev=NULL; 592 this->numVars=gc.numVars; 592 this->numVars=gc.numVars; 593 593 this->counter++; 594 594 this->UCN=this->counter; … … 596 596 this->facetPtr=NULL; 597 597 this->gcBasis=idrCopyR(f.flipGB, f.flipRing); 598 //this->inputIdeal=idCopy(this->gcBasis);598 this->inputIdeal=idCopy(this->gcBasis); 599 599 this->baseRing=rCopy(f.flipRing); 600 600 this->numFacets=0; … … 602 602 this->gcRays=NULL; 603 603 } 604 605 /** \brief Default destructor 604 605 /** \brief Default destructor 606 606 */ 607 607 gcone::~gcone() … … 619 619 idDelete((ideal *)&this->gcBasis); 620 620 #endif 621 //idDelete((ideal *)&this->gcBasis);622 //if(this->inputIdeal!=NULL)623 //idDelete((ideal *)&this->inputIdeal);624 //if (this->rootRing!=NULL && this->rootRing!=(ip_sring *)0xfefefefefefefefe)625 //rDelete(this->rootRing);621 idDelete((ideal *)&this->gcBasis); 622 if(this->inputIdeal!=NULL) 623 idDelete((ideal *)&this->inputIdeal); 624 if (this->rootRing!=NULL && this->rootRing!=(ip_sring *)0xfefefefefefefefe) 625 rDelete(this->rootRing); 626 626 if(this->UCN!=1 && this->baseRing!=NULL) 627 627 rDelete(this->baseRing); … … 638 638 } 639 639 this->counter--; 640 //should be deleted in noRevS641 //dd_FreeMatrix(this->ddFacets);642 //dd_FreeMatrix(this->ddFacets);640 should be deleted in noRevS 641 dd_FreeMatrix(this->ddFacets); 642 dd_FreeMatrix(this->ddFacets); 643 643 for(int ii=0;ii<this->numRays;ii++) 644 644 delete(gcRays[ii]); 645 645 omFree(gcRays); 646 } 646 } 647 647 648 648 /** Returns the number of cones existing at the time*/ … … 651 651 return this->counter; 652 652 } 653 653 654 654 /** \brief Set the interior point of a cone */ 655 655 inline void gcone::setIntPoint(int64vec *iv) … … 659 659 this->ivIntPt=iv64Copy(iv); 660 660 } 661 661 662 662 /** \brief Returns either a physical copy the interior point of a cone or just a reference to it.*/ 663 663 inline int64vec *gcone::getIntPoint(bool shallow) … … 668 668 return iv64Copy(this->ivIntPt); 669 669 } 670 670 671 671 /** \brief Print the interior point */ 672 672 inline void gcone::showIntPoint() … … 674 674 ivIntPt->show(); 675 675 } 676 676 677 677 /** \brief Print facets 678 678 * This is mainly for debugging purposes. Usually called from within gdb … … 708 708 printf("\n"); 709 709 } 710 710 711 711 /** For debugging purposes only */ 712 712 static volatile void showSLA(facet &f) … … 718 718 facet *codim2Act; 719 719 codim2Act = fAct->codim2Ptr; 720 720 721 721 printf("\n"); 722 722 while(fAct!=NULL) 723 723 { 724 int64vec *fNormal; 724 int64vec *fNormal; 725 725 fNormal=fAct->getFacetNormal(); 726 726 printf("(");fNormal->show(1,0); … … 745 745 } 746 746 } 747 747 748 748 static void idDebugPrint(const ideal &I) 749 749 { … … 761 761 static void invPrint(const ideal &I) 762 762 { 763 //int numElts=IDELEMS(I);764 //cout << "inv = ";765 //for(int ii=0;ii<numElts;ii++);766 //{767 //pWrite0(pHead(I->m[ii]));768 //cout << ",";769 //}770 //cout << endl;763 int numElts=IDELEMS(I); 764 cout << "inv = "; 765 for(int ii=0;ii<numElts;ii++); 766 { 767 pWrite0(pHead(I->m[ii])); 768 cout << ","; 769 } 770 cout << endl; 771 771 } 772 772 … … 784 784 return res; 785 785 } 786 786 787 787 /** \brief Set gcone::numFacets */ 788 788 inline void gcone::setNumFacets() 789 789 { 790 790 } 791 791 792 792 /** \brief Get gcone::numFacets */ 793 793 inline int gcone::getNumFacets() … … 795 795 return this->numFacets; 796 796 } 797 797 798 798 inline int gcone::getUCN() 799 799 { 800 if( this!=NULL) //&& ( this!=(gcone * const)0xfbfbfbfbfbfbfbfb && this!=(gcone * const)0xfbfbfbfb ) )800 if( this!=NULL) && ( this!=(gcone * const)0xfbfbfbfbfbfbfbfb && this!=(gcone * const)0xfbfbfbfb ) ) 801 801 return this->UCN; 802 802 else … … 829 829 * as its input. Redundancies are automatically removed using cddlib's dd_MatrixCanonicalize. 830 830 * Other methods for redundancy checkings might be implemented later. See Anders' diss p.44. 831 * Note that in order to use cddlib a 0-th column has to be added to the matrix since cddlib expects 831 * Note that in order to use cddlib a 0-th column has to be added to the matrix since cddlib expects 832 832 * each row to represent an inequality of type const+x1+...+xn <= 0. While computing the normals we come across 833 833 * the set \f$ \partial\mathcal{G} \f$ which we might store for later use. C.f p71 of journal … … 844 844 #endif 845 845 poly aktpoly; 846 int rows; //will contain the dimensions of the ineq matrix - deprecated by846 int rows; will contain the dimensions of the ineq matrix - deprecated by 847 847 dd_rowrange ddrows; 848 848 dd_colrange ddcols; 849 dd_rowset ddredrows; //# of redundant rows in ddineq850 dd_rowset ddlinset; //the opposite851 dd_rowindex ddnewpos=NULL; //all to make dd_Canonicalize happy852 dd_NumberType ddnumb=dd_Integer; //Number type853 dd_ErrorType dderr=dd_NoError; 854 //Compute the # inequalities i.e. rows of the matrix855 rows=0; //Initialization849 dd_rowset ddredrows; # of redundant rows in ddineq 850 dd_rowset ddlinset; the opposite 851 dd_rowindex ddnewpos=NULL; all to make dd_Canonicalize happy 852 dd_NumberType ddnumb=dd_Integer; Number type 853 dd_ErrorType dderr=dd_NoError; 854 Compute the # inequalities i.e. rows of the matrix 855 rows=0; Initialization 856 856 for (int ii=0;ii<IDELEMS(I);ii++) 857 857 { 858 //aktpoly=(poly)I->m[ii];859 //rows=rows+pLength(aktpoly)-1;858 aktpoly=(poly)I->m[ii]; 859 rows=rows+pLength(aktpoly)-1; 860 860 rows=rows+pLength((poly)I->m[ii])-1; 861 861 } 862 862 863 dd_rowrange aktmatrixrow=0; //needed to store the diffs of the expvects in the rows of ddineq863 dd_rowrange aktmatrixrow=0; needed to store the diffs of the expvects in the rows of ddineq 864 864 ddrows=rows; 865 865 ddcols=this->numVars; 866 dd_MatrixPtr ddineq; //Matrix to store the inequalities867 ddineq=dd_CreateMatrix(ddrows,ddcols+1); //The first col has to be 0 since cddlib checks for additive consts there868 869 //We loop through each g\in GB and compute the resulting inequalities866 dd_MatrixPtr ddineq; Matrix to store the inequalities 867 ddineq=dd_CreateMatrix(ddrows,ddcols+1); The first col has to be 0 since cddlib checks for additive consts there 868 869 We loop through each g\in GB and compute the resulting inequalities 870 870 for (int i=0; i<IDELEMS(I); i++) 871 871 { 872 aktpoly=(poly)I->m[i]; //get aktpoly as i-th component of I873 //simpler version of storing expvect diffs872 aktpoly=(poly)I->m[i]; get aktpoly as i-th component of I 873 simpler version of storing expvect diffs 874 874 int *leadexpv=(int*)omAlloc(((this->numVars)+1)*sizeof(int)); 875 875 pGetExpV(aktpoly,leadexpv); … … 879 879 pNextTerm/*aktpoly*/=pNext(pNextTerm); 880 880 int *tailexpv=(int*)omAlloc(((this->numVars)+1)*sizeof(int)); 881 pGetExpV(pNextTerm,tailexpv); 881 pGetExpV(pNextTerm,tailexpv); 882 882 for(int kk=1;kk<=this->numVars;kk++) 883 { 883 { 884 884 dd_set_si(ddineq->matrix[(dd_rowrange)aktmatrixrow][kk],leadexpv[kk]-tailexpv[kk]); 885 885 } 886 886 aktmatrixrow += 1; 887 887 omFree(tailexpv); 888 } 889 omFree(leadexpv); 890 } //for888 } 889 omFree(leadexpv); 890 } for 891 891 #if true 892 892 /*Let's make the preprocessing here. This could already be done in the above for-loop, … … 895 895 * Quote: [...] every non-zero spoly should have at least one of its terms in inv(G) 896 896 */ 897 //ideal initialForm=idInit(IDELEMS(I),1);898 //int64vec *gamma=new int64vec(this->numVars);897 ideal initialForm=idInit(IDELEMS(I),1); 898 int64vec *gamma=new int64vec(this->numVars); 899 899 int falseGammaCounter=0; 900 900 int *redRowsArray=NULL; 901 901 int num_alloc=0; 902 int num_elts=0; 902 int num_elts=0; 903 903 for(int ii=0;ii<ddineq->rowsize;ii++) 904 904 { 905 905 ideal initialForm=idInit(IDELEMS(I),I->rank); 906 //read row ii into gamma907 //int64 tmp;906 read row ii into gamma 907 int64 tmp; 908 908 int64vec *gamma=new int64vec(this->numVars); 909 909 for(int jj=1;jj<=this->numVars;jj++) … … 915 915 computeInv((ideal&)I,initialForm,*gamma); 916 916 delete gamma; 917 //Create leading ideal917 Create leading ideal 918 918 ideal L=idInit(IDELEMS(initialForm),1); 919 919 for(int jj=0;jj<IDELEMS(initialForm);jj++) … … 922 922 L->m[jj]=pCopy(/*pHead(initialForm->m[jj]))*/p); 923 923 pDelete(&p); 924 } 925 926 LObject *P = new sLObject(); //TODO What's the difference between sLObject and LObject?924 } 925 926 LObject *P = new sLObject();TODO What's the difference between sLObject and LObject? 927 927 memset(P,0,sizeof(LObject)); 928 928 … … 930 930 { 931 931 bool isMaybeFacet=FALSE; 932 P->p1=initialForm->m[jj]; //build spolys of initialForm in_v932 P->p1=initialForm->m[jj]; build spolys of initialForm in_v 933 933 934 934 for(int kk=jj+1;kk<=IDELEMS(initialForm)-1;kk++) 935 935 { 936 936 P->p2=initialForm->m[kk]; 937 ksCreateSpoly(P); 938 if(P->p!=NULL) //spoly non zero=?939 { 940 poly p; //NOTE Don't use pInit here. Evil memleak will follow937 ksCreateSpoly(P); 938 if(P->p!=NULL) spoly non zero=? 939 { 940 poly p;NOTE Don't use pInit here. Evil memleak will follow 941 941 poly q; 942 942 poly pDel,qDel; 943 943 p=pCopy(P->p); 944 q=pHead(p); //Monomial q944 q=pHead(p); Monomial q 945 945 pDelete(&q); 946 946 pDel=p; qDel=q; 947 947 isMaybeFacet=FALSE; 948 //TODO: Suffices to check LTs here948 TODO: Suffices to check LTs here 949 949 while(p!=NULL) 950 { 950 { 951 951 q=pHead(p); 952 952 for(int ll=0;ll<IDELEMS(L);ll++) 953 953 { 954 954 if(pLmEqual(L->m[ll],q) || pDivisibleBy(L->m[ll],q)) 955 { 955 { 956 956 isMaybeFacet=TRUE; 957 break; //for957 break;for 958 958 } 959 959 } … … 961 961 if(isMaybeFacet==TRUE) 962 962 { 963 break; //while(p!=NULL)963 break;while(p!=NULL) 964 964 } 965 965 p=pNext(p); 966 } //while967 //pDelete(&p);//NOTE Better to use pDel and qDel. Commenting in this line will not work!966 }while 967 pDelete(&p);//NOTE Better to use pDel and qDel. Commenting in this line will not work! 968 968 if(q!=NULL) pDelete(&q); 969 969 pDelete(&pDel); … … 971 971 if(isMaybeFacet==FALSE) 972 972 { 973 dd_set_si(ddineq->matrix[ii][0],1); 974 //if(num_alloc==0)975 //num_alloc += 1;976 // else 977 //num_alloc += 1;973 dd_set_si(ddineq->matrix[ii][0],1); 974 if(num_alloc==0) 975 num_alloc += 1; 976 else 977 num_alloc += 1; 978 978 if(num_alloc==num_elts) num_alloc==0 ? num_alloc=1 : num_alloc*=2; 979 979 980 980 void *tmp = realloc(redRowsArray,(num_alloc*sizeof(int))); 981 981 if(!tmp) … … 987 987 redRowsArray[num_elts]=ii; 988 988 num_elts++; 989 //break;//for(int kk, since we have found one that is not in L990 goto _start; //mea culpa, mea culpa, mea maxima culpa989 break;//for(int kk, since we have found one that is not in L 990 goto _start; mea culpa, mea culpa, mea maxima culpa 991 991 } 992 } //if(P->p!=NULL)992 }if(P->p!=NULL) 993 993 pDelete(&(P->p)); 994 } //for k995 } //for jj994 }for k 995 }for jj 996 996 _start:; 997 997 idDelete(&L); 998 998 delete P; 999 999 idDelete(&initialForm); 1000 } //for(ii<ddineq-rowsize1001 //delete gamma;1002 int offset=0; //needed for correction of redRowsArray[ii]1000 }for(ii<ddineq-rowsize 1001 delete gamma; 1002 int offset=0;needed for correction of redRowsArray[ii] 1003 1003 #ifdef gfan_DEBUG 1004 1004 printf("Removed %i of %i in preprocessing step\n",num_elts,ddineq->rowsize); … … 1006 1006 for( int ii=0;ii<num_elts;ii++ ) 1007 1007 { 1008 dd_MatrixRowRemove(&ddineq,redRowsArray[ii]+1-offset); //cddlib sucks at enumeration1008 dd_MatrixRowRemove(&ddineq,redRowsArray[ii]+1-offset);cddlib sucks at enumeration 1009 1009 offset++; 1010 } 1011 free(redRowsArray); //NOTE May crash on some machines.1010 } 1011 free(redRowsArray);NOTE May crash on some machines. 1012 1012 /*And now for the strictly positive rows 1013 1013 * Doesn't gain significant speedup … … 1022 1022 (*ivPos)[jj]=(int)mpq_get_d(ddineq->matrix[ii][jj+1]); 1023 1023 bool isStrictlyPos=FALSE; 1024 int posCtr=0; 1024 int posCtr=0; 1025 1025 for(int jj=0;jj<this->numVars;jj++) 1026 1026 { … … 1030 1030 { 1031 1031 if ((*ivPos)[jj]>=0) 1032 { 1033 posCtr++; 1032 { 1033 posCtr++; 1034 1034 } 1035 } 1035 } 1036 1036 delete ivCanonical; 1037 1037 } … … 1052 1052 posRowsArray = (int*)tmp; 1053 1053 posRowsArray[num_elts]=ii; 1054 num_elts++; 1054 num_elts++; 1055 1055 } 1056 1056 delete ivPos; … … 1065 1065 #endif 1066 1066 1067 dd_MatrixCanonicalize(&ddineq, &ddlinset, &ddredrows, &ddnewpos, &dderr); 1068 ddrows = ddineq->rowsize; //Size of the matrix with redundancies removed1067 dd_MatrixCanonicalize(&ddineq, &ddlinset, &ddredrows, &ddnewpos, &dderr); 1068 ddrows = ddineq->rowsize; Size of the matrix with redundancies removed 1069 1069 ddcols = ddineq->colsize; 1070 1070 1071 1071 this->ddFacets = dd_CopyMatrix(ddineq); 1072 1073 /*Write the normals into class facet*/ 1074 facet *fAct; //pointer to active facet1072 1073 /*Write the normals into class facet*/ 1074 facet *fAct; pointer to active facet 1075 1075 int numNonFlip=0; 1076 1076 for (int kk = 0; kk<ddrows; kk++) 1077 1077 { 1078 int64 ggT=1; //NOTE Why does (int)mpq_get_d(ddineq->matrix[kk][1]) not work?1079 int64vec *load = new int64vec(this->numVars); //int64vec to store a single facet normal that will then be stored via setFacetNormal1078 int64 ggT=1;NOTE Why does (int)mpq_get_d(ddineq->matrix[kk][1]) not work? 1079 int64vec *load = new int64vec(this->numVars);int64vec to store a single facet normal that will then be stored via setFacetNormal 1080 1080 for (int jj = 1; jj <ddcols; jj++) 1081 1081 { 1082 1082 int64 val; 1083 1083 val = (int64)mpq_get_d(ddineq->matrix[kk][jj]); 1084 (*load)[jj-1] = val; //store typecasted entry at pos jj-1 of load1084 (*load)[jj-1] = val; store typecasted entry at pos jj-1 of load 1085 1085 ggT = int64gcd(ggT,/*(int64&)foo*/val); 1086 } //for (int jj = 1; jj <ddcols; jj++)1086 }for (int jj = 1; jj <ddcols; jj++) 1087 1087 if(ggT>1) 1088 1088 { 1089 1089 for(int ll=0;ll<this->numVars;ll++) 1090 (*load)[ll] /= ggT; //make primitive vector1090 (*load)[ll] /= ggT;make primitive vector 1091 1091 } 1092 1092 /*Quick'n'dirty hack for flippability. Executed only if gcone::hasHomInput==FALSE 1093 1093 * Otherwise every facet intersects the positive orthant 1094 */ 1094 */ 1095 1095 if(gcone::hasHomInput==FALSE) 1096 1096 { 1097 //TODO: No dP needed1097 TODO: No dP needed 1098 1098 bool isFlip=FALSE; 1099 1099 for(int jj = 0; jj<load->length(); jj++) 1100 1100 { 1101 //int64vec *ivCanonical = new int64vec(load->length());1102 //(*ivCanonical)[jj]=1;1103 // if (dotProduct(*load,*ivCanonical)<0) 1104 //{1105 //isFlip=TRUE;1106 //break; //URGHS1107 //}1108 //delete ivCanonical;1101 int64vec *ivCanonical = new int64vec(load->length()); 1102 (*ivCanonical)[jj]=1; 1103 if (dotProduct(*load,*ivCanonical)<0) 1104 { 1105 isFlip=TRUE; 1106 break; //URGHS 1107 } 1108 delete ivCanonical; 1109 1109 if((*load)[jj]<0) 1110 1110 { 1111 1111 isFlip=TRUE; 1112 1112 break; 1113 } 1113 } 1114 1114 }/*End of check for flippability*/ 1115 //if(iv64isStrictlyPositive(load))1116 //isFlip=TRUE;1115 if(iv64isStrictlyPositive(load)) 1116 isFlip=TRUE; 1117 1117 if(isFlip==FALSE) 1118 1118 { … … 1123 1123 facet *fRoot = new facet(); 1124 1124 this->facetPtr = fRoot; 1125 fAct = fRoot; 1125 fAct = fRoot; 1126 1126 } 1127 1127 else … … 1134 1134 fAct->setUCN(this->getUCN()); 1135 1135 #ifdef gfan_DEBUG 1136 printf("Marking facet (");load->show(1,0);printf(") as non flippable\n"); 1136 printf("Marking facet (");load->show(1,0);printf(") as non flippable\n"); 1137 1137 #endif 1138 1138 } … … 1153 1153 fAct->isFlippable=TRUE; 1154 1154 fAct->setFacetNormal(load); 1155 fAct->setUCN(this->getUCN()); 1156 } 1157 } //hasHomInput==FALSE1158 else //Every facet is flippable1159 { /*Now load should be full and we can call setFacetNormal*/ 1155 fAct->setUCN(this->getUCN()); 1156 } 1157 }hasHomInput==FALSE 1158 else Every facet is flippable 1159 { /*Now load should be full and we can call setFacetNormal*/ 1160 1160 this->numFacets++; 1161 1161 if(this->numFacets==1) … … 1172 1172 fAct->isFlippable=TRUE; 1173 1173 fAct->setFacetNormal(load); 1174 fAct->setUCN(this->getUCN()); 1175 } //if (isFlippable==FALSE)1176 delete load; 1177 } //for (int kk = 0; kk<ddrows; kk++)1178 1179 //In cases like I=<x-1,y-1> there are only non-flippable facets...1174 fAct->setUCN(this->getUCN()); 1175 }if (isFlippable==FALSE) 1176 delete load; 1177 }for (int kk = 0; kk<ddrows; kk++) 1178 1179 In cases like I=<x-1,y-1> there are only non-flippable facets... 1180 1180 if(numNonFlip==this->numFacets) 1181 { 1181 { 1182 1182 WerrorS ("Only non-flippable facets. Terminating...\n"); 1183 //exit(-1);//Bit harsh maybe...1184 } 1185 1183 exit(-1);//Bit harsh maybe... 1184 } 1185 1186 1186 /* 1187 1187 Now we should have a linked list containing the facet normals of those facets that are … … 1189 1189 -flipable 1190 1190 Adressing is done via *facetPtr 1191 */ 1191 */ 1192 1192 if (compIntPoint==TRUE) 1193 1193 { … … 1198 1198 { 1199 1199 dd_set_si(posRestr->matrix[ii][jj],1); 1200 jj++; 1200 jj++; 1201 1201 } 1202 1202 dd_MatrixAppendTo(&ddineq,posRestr); 1203 interiorPoint(ddineq, *iv); //NOTE ddineq contains non-flippable facets1204 this->setIntPoint(iv); //stores the interior point in gcone::ivIntPt1203 interiorPoint(ddineq, *iv); NOTE ddineq contains non-flippable facets 1204 this->setIntPoint(iv); stores the interior point in gcone::ivIntPt 1205 1205 delete iv; 1206 1206 dd_FreeMatrix(posRestr); 1207 } 1208 //Clean up but don't delete the return value!1209 //dd_FreeMatrix(ddineq);1210 set_free(ddredrows); //check1211 set_free(ddlinset); //check1212 //free(ddnewpos);//<-- NOTE Here the crash occurs omAlloc issue?1207 } 1208 Clean up but don't delete the return value! 1209 dd_FreeMatrix(ddineq); 1210 set_free(ddredrows);check 1211 set_free(ddlinset);check 1212 free(ddnewpos);//<-- NOTE Here the crash occurs omAlloc issue? 1213 1213 #ifdef gfanp 1214 1214 gettimeofday(&end, 0); … … 1216 1216 #endif 1217 1217 1218 } //gcone::getConeNormals(ideal I)1219 1218 }gcone::getConeNormals(ideal I) 1219 1220 1220 /** \brief Compute the (codim-2)-facets of a given cone 1221 1221 * This method is used during noRevS … … 1229 1229 gettimeofday(&start, 0); 1230 1230 #endif 1231 //this->facetPtr->codim2Ptr = new facet(2); //instantiate a (codim-2)-facet1231 this->facetPtr->codim2Ptr = new facet(2); //instantiate a (codim-2)-facet 1232 1232 facet *fAct; 1233 fAct = this->facetPtr; 1233 fAct = this->facetPtr; 1234 1234 facet *codim2Act; 1235 //codim2Act = this->facetPtr->codim2Ptr;1236 dd_MatrixPtr ddineq; //,P,ddakt;1235 codim2Act = this->facetPtr->codim2Ptr; 1236 dd_MatrixPtr ddineq;,P,ddakt; 1237 1237 dd_ErrorType err; 1238 //ddineq = facets2Matrix(gc); //get a matrix representation of the cone1238 ddineq = facets2Matrix(gc); //get a matrix representation of the cone 1239 1239 ddineq = dd_CopyMatrix(gc.ddFacets); 1240 1240 /*Now set appropriate linearity*/ 1241 for (int ii=0; ii<this->numFacets; ii++) 1242 { 1241 for (int ii=0; ii<this->numFacets; ii++) 1242 { 1243 1243 dd_rowset impl_linset, redset; 1244 1244 dd_rowindex newpos; 1245 1245 dd_MatrixPtr ddakt; 1246 1246 ddakt = dd_CopyMatrix(ddineq); 1247 //ddakt->representation=dd_Inequality; //Not using this makes it faster. But why does the quick check below still work?1248 //ddakt->representation=dd_Generator;1247 ddakt->representation=dd_Inequality; //Not using this makes it faster. But why does the quick check below still work? 1248 ddakt->representation=dd_Generator; 1249 1249 set_addelem(ddakt->linset,ii+1);/*Now set appropriate linearity*/ 1250 1250 #ifdef gfanp 1251 1251 timeval t_ddMC_start, t_ddMC_end; 1252 1252 gettimeofday(&t_ddMC_start,0); 1253 #endif 1254 //dd_MatrixCanonicalize(&ddakt, &impl_linset, &redset, &newpos, &err);1253 #endif 1254 dd_MatrixCanonicalize(&ddakt, &impl_linset, &redset, &newpos, &err); 1255 1255 dd_PolyhedraPtr ddpolyh; 1256 1256 ddpolyh=dd_DDMatrix2Poly(ddakt, &err); 1257 //ddpolyh=dd_DDMatrix2Poly2(ddakt, dd_MaxCutoff, &err);1257 ddpolyh=dd_DDMatrix2Poly2(ddakt, dd_MaxCutoff, &err); 1258 1258 dd_MatrixPtr P; 1259 P=dd_CopyGenerators(ddpolyh); 1259 P=dd_CopyGenerators(ddpolyh); 1260 1260 dd_FreePolyhedra(ddpolyh); 1261 //TODO Call for one cone , normalize - check equalities - plus lineality -done1261 TODO Call for one cone , normalize - check equalities - plus lineality -done 1262 1262 #ifdef gfanp 1263 1263 gettimeofday(&t_ddMC_end,0); 1264 1264 t_ddMC += (t_ddMC_end.tv_sec - t_ddMC_start.tv_sec + 1e-6*(t_ddMC_end.tv_usec - t_ddMC_start.tv_usec)); 1265 #endif 1265 #endif 1266 1266 /* We loop through each row of P normalize it by making all 1267 1267 * entries integer ones and add the resulting vector to the 1268 1268 * int matrix facet::codim2Facets */ 1269 1269 for (int jj=1;jj<=/*ddakt*/P->rowsize;jj++) 1270 { 1270 { 1271 1271 fAct->numCodim2Facets++; 1272 if(fAct->numCodim2Facets==1) 1273 { 1274 fAct->codim2Ptr = new facet(2); 1272 if(fAct->numCodim2Facets==1) 1273 { 1274 fAct->codim2Ptr = new facet(2); 1275 1275 codim2Act = fAct->codim2Ptr; 1276 1276 } … … 1297 1297 #endif 1298 1298 codim2Act->setFacetNormal(n); 1299 delete n; 1300 } 1299 delete n; 1300 } 1301 1301 /*We check whether the facet spanned by the codim-2 facets 1302 1302 * intersects with the positive orthant. Otherwise we define this 1303 * facet to be non-flippable. Works since we set the appropriate 1303 * facet to be non-flippable. Works since we set the appropriate 1304 1304 * linearity for ddakt above. 1305 1305 */ 1306 //TODO It might be faster to compute jus the implied equations instead of a relative interior point1307 //int64vec *iv_intPoint = new int64vec(this->numVars);1308 //dd_MatrixPtr shiftMatrix;1309 //dd_MatrixPtr intPointMatrix;1310 //shiftMatrix = dd_CreateMatrix(this->numVars,this->numVars+1);1311 //for(int kk=0;kk<this->numVars;kk++)1312 //{1313 //dd_set_si(shiftMatrix->matrix[kk][0],1);1314 //dd_set_si(shiftMatrix->matrix[kk][kk+1],1);1315 //}1316 //intPointMatrix=dd_MatrixAppend(ddakt,shiftMatrix);1317 //#ifdef gfanp1318 //timeval t_iP_start, t_iP_end;1319 //gettimeofday(&t_iP_start, 0);1320 // #endif 1321 //interiorPoint(intPointMatrix,*iv_intPoint);1322 //// dd_rowset impl_linste,lbasis;1323 //// dd_LPSolutionPtr lps=NULL;1324 //// dd_ErrorType err;1325 //// dd_FindRelativeInterior(intPointMatrix, &impl_linset, &lbasis, &lps, &err);1326 //#ifdef gfanp1327 //gettimeofday(&t_iP_end, 0);1328 //t_iP += (t_iP_end.tv_sec - t_iP_start.tv_sec + 1e-6*(t_iP_end.tv_usec - t_iP_start.tv_usec));1329 //#endif1330 //for(int ll=0;ll<this->numVars;ll++)1331 //{1332 //if( (*iv_intPoint)[ll] < 0 )1333 //{1334 //fAct->isFlippable=FALSE;1335 //break;1336 //}1337 //}1306 TODO It might be faster to compute jus the implied equations instead of a relative interior point 1307 int64vec *iv_intPoint = new int64vec(this->numVars); 1308 dd_MatrixPtr shiftMatrix; 1309 dd_MatrixPtr intPointMatrix; 1310 shiftMatrix = dd_CreateMatrix(this->numVars,this->numVars+1); 1311 for(int kk=0;kk<this->numVars;kk++) 1312 { 1313 dd_set_si(shiftMatrix->matrix[kk][0],1); 1314 dd_set_si(shiftMatrix->matrix[kk][kk+1],1); 1315 } 1316 intPointMatrix=dd_MatrixAppend(ddakt,shiftMatrix); 1317 #ifdef gfanp 1318 timeval t_iP_start, t_iP_end; 1319 gettimeofday(&t_iP_start, 0); 1320 #endif 1321 interiorPoint(intPointMatrix,*iv_intPoint); 1322 // dd_rowset impl_linste,lbasis; 1323 // dd_LPSolutionPtr lps=NULL; 1324 // dd_ErrorType err; 1325 // dd_FindRelativeInterior(intPointMatrix, &impl_linset, &lbasis, &lps, &err); 1326 #ifdef gfanp 1327 gettimeofday(&t_iP_end, 0); 1328 t_iP += (t_iP_end.tv_sec - t_iP_start.tv_sec + 1e-6*(t_iP_end.tv_usec - t_iP_start.tv_usec)); 1329 #endif 1330 for(int ll=0;ll<this->numVars;ll++) 1331 { 1332 if( (*iv_intPoint)[ll] < 0 ) 1333 { 1334 fAct->isFlippable=FALSE; 1335 break; 1336 } 1337 } 1338 1338 /*End of check*/ 1339 1339 /*This test should be way less time consuming*/ … … 1358 1358 } 1359 1359 if(containsStrictlyPosRay==FALSE) 1360 //TODO Not sufficient. Intersect with pos orthant for pos int1360 TODO Not sufficient. Intersect with pos orthant for pos int 1361 1361 fAct->isFlippable=FALSE; 1362 1362 #ifdef gfanp … … 1365 1365 #endif 1366 1366 /**/ 1367 fAct = fAct->next; 1367 fAct = fAct->next; 1368 1368 dd_FreeMatrix(ddakt); 1369 1369 dd_FreeMatrix(P); 1370 } //for1370 }for 1371 1371 dd_FreeMatrix(ddineq); 1372 1372 #ifdef gfanp … … 1375 1375 #endif 1376 1376 } 1377 1377 1378 1378 /** Really extremal rays this time ;) 1379 1379 * Extremal rays are unique modulo the homogeneity space. … … 1383 1383 * checking whether the inner product of the ray with the normal is zero. 1384 1384 * We use ivAdd here which returns a new int64vec. Therefore we need to avoid 1385 * a memory leak which would be cause by the line 1385 * a memory leak which would be cause by the line 1386 1386 * iv=ivAdd(iv,b) 1387 * So we keep pointer tmp to iv and delete(tmp), so there should not occur a 1387 * So we keep pointer tmp to iv and delete(tmp), so there should not occur a 1388 1388 * memleak 1389 1389 * TODO normalization … … 1397 1397 gettimeofday(&poly_start,0); 1398 1398 #endif 1399 //Add lineality space - dd_LinealitySpace1399 Add lineality space - dd_LinealitySpace 1400 1400 dd_MatrixPtr ddineq; 1401 dd_ErrorType err; 1402 //if(dd_LinealitySpace->rowsize>0)//The linspace might be 01403 //ddineq = dd_AppendMatrix(gc.ddFacets,gcone::dd_LinealitySpace);1404 //else1405 //ddineq = dd_CopyMatrix(gc.ddFacets);1401 dd_ErrorType err; 1402 if(dd_LinealitySpace->rowsize>0)//The linspace might be 0 1403 ddineq = dd_AppendMatrix(gc.ddFacets,gcone::dd_LinealitySpace); 1404 else 1405 ddineq = dd_CopyMatrix(gc.ddFacets); 1406 1406 ddineq = (dd_LinealitySpace->rowsize>0) ? dd_AppendMatrix(gc.ddFacets,gcone::dd_LinealitySpace) : dd_CopyMatrix(gc.ddFacets); 1407 1407 /* In case the input is non-homogeneous we add constrains for the positive orthant. 1408 * This is justified by the fact that for non-homog ideals we only consider the 1408 * This is justified by the fact that for non-homog ideals we only consider the 1409 1409 * restricted fan. This way we can be sure to find strictly positive interior points. 1410 1410 * This in turn makes life easy when checking for flippability! … … 1421 1421 assert(ddineq); 1422 1422 dd_FreeMatrix(ddPosRestr); 1423 } 1423 } 1424 1424 dd_PolyhedraPtr ddPolyh; 1425 1425 ddPolyh = dd_DDMatrix2Poly(ddineq, &err); … … 1434 1434 /* Compute interior point on the fly*/ 1435 1435 int64vec *ivIntPointOfCone = new int64vec(this->numVars); 1436 //mpq_t *colSum = new mpq_t[this->numVars];1437 //int denom[this->numVars];//denominators of colSum1438 //NOTE TODO need to gcd of rows and factor out! -> makeInt1436 mpq_t *colSum = new mpq_t[this->numVars]; 1437 int denom[this->numVars];//denominators of colSum 1438 NOTE TODO need to gcd of rows and factor out! -> makeInt 1439 1439 /*for(int jj=0;jj<this->numVars;jj++) 1440 1440 { 1441 mpq_init(colSum[jj]); 1441 mpq_init(colSum[jj]); 1442 1442 for(int ii=0;ii<P->rowsize;ii++) 1443 1443 { … … 1455 1455 mpz_clear(den); 1456 1456 } 1457 //Now compute lcm of denominators of colSum[jj]1458 //NOTE gcd as well and normalise instantly?1457 Now compute lcm of denominators of colSum[jj] 1458 NOTE gcd as well and normalise instantly? 1459 1459 mpz_t kgV; mpz_init(kgV); 1460 1460 mpz_set_str(kgV,"1",10); … … 1477 1477 for(int ii=0;ii<P->rowsize;ii++) 1478 1478 { 1479 //int64vec *foo = new int64vec(this->numVars);1479 int64vec *foo = new int64vec(this->numVars); 1480 1480 int64vec *tmp = ivIntPointOfCone; 1481 1481 makeInt(P,ii+1,*foo); 1482 1482 ivIntPointOfCone = iv64Add(ivIntPointOfCone,foo); 1483 1483 delete tmp; 1484 //delete foo;1484 delete foo; 1485 1485 } 1486 1486 delete foo; … … 1488 1488 for (int ii=0;ii<(this->numVars);ii++) 1489 1489 { 1490 //mpq_t product;1491 //mpq_init(product);1492 //mpq_mul(product,qkgV,colSum[ii]);1493 //(*ivIntPointOfCone)[ii]=(int64)mpz_get_d(mpq_numref(product));1494 if( (*ivIntPointOfCone)[ii]>INT_MAX ) 1490 mpq_t product; 1491 mpq_init(product); 1492 mpq_mul(product,qkgV,colSum[ii]); 1493 (*ivIntPointOfCone)[ii]=(int64)mpz_get_d(mpq_numref(product)); 1494 if( (*ivIntPointOfCone)[ii]>INT_MAX ) 1495 1495 WarnS("Interior point exceeds INT_MAX!\n"); 1496 //mpq_clear(product);1497 //Compute intgcd1496 mpq_clear(product); 1497 Compute intgcd 1498 1498 ggT=int64gcd(ggT,(*ivIntPointOfCone)[ii]); 1499 1499 } 1500 1501 //Divide out a common gcd > 11500 1501 Divide out a common gcd > 1 1502 1502 if(ggT>1) 1503 1503 { … … 1508 1508 } 1509 1509 } 1510 //mpq_clear(qkgV);1511 //delete [] colSum;1510 mpq_clear(qkgV); 1511 delete [] colSum; 1512 1512 /*For homogeneous input (like Det3,3,5) the int points may be negative. So add a suitable multiple of (1,_,1)*/ 1513 1513 if(hasHomInput==TRUE && iv64isStrictlyPositive(ivIntPointOfCone)==FALSE) … … 1517 1517 for(int ii=0;ii<this->numVars;ii++) 1518 1518 { 1519 //(*ivOne)[ii]=1;1519 (*ivOne)[ii]=1; 1520 1520 if ((*ivIntPointOfCone)[ii]<maxNegEntry) maxNegEntry=(*ivIntPointOfCone)[ii]; 1521 1521 } 1522 1522 maxNegEntry *= -1; 1523 maxNegEntry++; //To be on the safe side1523 maxNegEntry++;To be on the safe side 1524 1524 for(int ii=0;ii<this->numVars;ii++) 1525 1525 (*ivOne)[ii]=maxNegEntry; … … 1527 1527 ivIntPointOfCone=iv64Add(ivIntPointOfCone,ivOne); 1528 1528 delete(tmp); 1529 //while( !iv64isStrictlyPositive(ivIntPointOfCone) )1530 //{1531 //int64vec *tmp = ivIntPointOfCone;1532 //for(int jj=0;jj<this->numVars;jj++)1533 //(*ivOne)[jj] = (*ivOne)[jj] << 1; //times 21534 //ivIntPointOfCone = ivAdd(ivIntPointOfCone,ivOne);1535 // delete tmp; 1536 //}1529 while( !iv64isStrictlyPositive(ivIntPointOfCone) ) 1530 { 1531 int64vec *tmp = ivIntPointOfCone; 1532 for(int jj=0;jj<this->numVars;jj++) 1533 (*ivOne)[jj] = (*ivOne)[jj] << 1; //times 2 1534 ivIntPointOfCone = ivAdd(ivIntPointOfCone,ivOne); 1535 delete tmp; 1536 } 1537 1537 delete ivOne; 1538 1538 int64 ggT=(*ivIntPointOfCone)[0]; … … 1545 1545 } 1546 1546 } 1547 //assert(iv64isStrictlyPositive(ivIntPointOfCone));1548 1547 assert(iv64isStrictlyPositive(ivIntPointOfCone)); 1548 1549 1549 this->setIntPoint(ivIntPointOfCone); 1550 1550 delete(ivIntPointOfCone); 1551 1551 /* end of interior point computation*/ 1552 1553 //Loop through the rows of P and check whether fNormal*row[i]=0 => row[i] belongs to fNormal1552 1553 Loop through the rows of P and check whether fNormal*row[i]=0 => row[i] belongs to fNormal 1554 1554 int rows=P->rowsize; 1555 1555 facet *fAct=gc.facetPtr; 1556 //Construct an array to hold the extremal rays of the cone1557 this->gcRays = (int64vec**)omAlloc0(sizeof(int64vec*)*P->rowsize); 1556 Construct an array to hold the extremal rays of the cone 1557 this->gcRays = (int64vec**)omAlloc0(sizeof(int64vec*)*P->rowsize); 1558 1558 for(int ii=0;ii<P->rowsize;ii++) 1559 1559 { 1560 1560 int64vec *rowvec = new int64vec(this->numVars); 1561 makeInt(P,ii+1,*rowvec); //get an integer entry instead of rational, rowvec is primitve1561 makeInt(P,ii+1,*rowvec);get an integer entry instead of rational, rowvec is primitve 1562 1562 this->gcRays[ii] = iv64Copy(rowvec); 1563 1563 delete rowvec; 1564 } 1564 } 1565 1565 this->numRays=P->rowsize; 1566 //Check which rays belong to which facet1566 Check which rays belong to which facet 1567 1567 while(fAct!=NULL) 1568 1568 { 1569 const int64vec *fNormal; //= new int64vec(this->numVars);1570 fNormal = fAct->getRef2FacetNormal(); //->getFacetNormal();1569 const int64vec *fNormal; = new int64vec(this->numVars); 1570 fNormal = fAct->getRef2FacetNormal();->getFacetNormal(); 1571 1571 int64vec *ivIntPointOfFacet = new int64vec(this->numVars); 1572 1572 for(int ii=0;ii<rows;ii++) 1573 { 1573 { 1574 1574 if(dotProduct(*fNormal,this->gcRays[ii])==0) 1575 1575 { 1576 int64vec *tmp = ivIntPointOfFacet; //Prevent memleak1576 int64vec *tmp = ivIntPointOfFacet;Prevent memleak 1577 1577 fAct->numCodim2Facets++; 1578 1578 facet *codim2Act; 1579 if(fAct->numCodim2Facets==1) 1580 { 1581 fAct->codim2Ptr = new facet(2); 1579 if(fAct->numCodim2Facets==1) 1580 { 1581 fAct->codim2Ptr = new facet(2); 1582 1582 codim2Act = fAct->codim2Ptr; 1583 1583 } … … 1587 1587 codim2Act = codim2Act->next; 1588 1588 } 1589 //codim2Act->setFacetNormal(rowvec);1590 //Rather just let codim2Act point to the corresponding int64vec of gcRays1589 codim2Act->setFacetNormal(rowvec); 1590 Rather just let codim2Act point to the corresponding int64vec of gcRays 1591 1591 codim2Act->fNormal=this->gcRays[ii]; 1592 fAct->numRays++; 1593 //Memleak avoided via tmp1592 fAct->numRays++; 1593 Memleak avoided via tmp 1594 1594 ivIntPointOfFacet=iv64Add(ivIntPointOfFacet,this->gcRays[ii]); 1595 //Now tmp still points to the OLD address of ivIntPointOfFacet1595 Now tmp still points to the OLD address of ivIntPointOfFacet 1596 1596 delete(tmp); 1597 1598 } 1599 } //For non-homog input ivIntPointOfFacet should already be >0 here1600 //if(!hasHomInput) {assert(iv64isStrictlyPositive(ivIntPointOfFacet));}1601 //if we have no strictly pos ray but the input is homogeneous1602 //then add a suitable multiple of (1,...,1)1597 1598 } 1599 }For non-homog input ivIntPointOfFacet should already be >0 here 1600 if(!hasHomInput) {assert(iv64isStrictlyPositive(ivIntPointOfFacet));} 1601 if we have no strictly pos ray but the input is homogeneous 1602 then add a suitable multiple of (1,...,1) 1603 1603 if( !iv64isStrictlyPositive(ivIntPointOfFacet) && hasHomInput==TRUE) 1604 1604 { … … 1611 1611 for(int jj=0;jj<this->numVars;jj++) 1612 1612 { 1613 (*ivOne)[jj] = (*ivOne)[jj] << 1; //times 21613 (*ivOne)[jj] = (*ivOne)[jj] << 1; times 2 1614 1614 } 1615 1615 ivIntPointOfFacet = iv64Add(ivIntPointOfFacet/*diff*/,ivOne); 1616 delete tmp; 1616 delete tmp; 1617 1617 } 1618 1618 delete ivOne; … … 1625 1625 for(int ii=0;ii<this->numVars;ii++) 1626 1626 (*ivIntPointOfFacet)[ii] /= ggT; 1627 } 1627 } 1628 1628 fAct->setInteriorPoint(ivIntPointOfFacet); 1629 1629 1630 1630 delete(ivIntPointOfFacet); 1631 //Now (if we have at least 3 variables) do a bubblesort on the rays1631 Now (if we have at least 3 variables) do a bubblesort on the rays 1632 1632 /*if(this->numVars>2) 1633 1633 { … … 1643 1643 do 1644 1644 { 1645 exchanged=FALSE; //n=fAct->numRays-1;1645 exchanged=FALSE;n=fAct->numRays-1; 1646 1646 for(unsigned ii=0;ii<=n-1;ii++) 1647 { 1647 { 1648 1648 if((A[ii]->fNormal)->compare((A[ii+1]->fNormal))==1) 1649 1649 { 1650 //Swap rays1650 Swap rays 1651 1651 cout << "Swapping "; 1652 1652 A[ii]->fNormal->show(1,0); cout << " with "; A[ii+1]->fNormal->show(1,0); cout << endl; … … 1657 1657 if(ii==0) 1658 1658 fAct->codim2Ptr=A[ii+1]; 1659 //end swap1660 facet *tmp=A[ii]; //swap in list1659 end swap 1660 facet *tmp=A[ii];swap in list 1661 1661 A[ii+1]=A[ii]; 1662 1662 A[ii]=tmp; 1663 // tmp=NULL; 1664 } 1663 tmp=NULL; 1664 } 1665 1665 } 1666 n--; 1666 n--; 1667 1667 }while(exchanged==TRUE && n>=0); 1668 }*/ //if pVariables>21669 // delete fNormal; 1668 }*/if pVariables>2 1669 delete fNormal; 1670 1670 fAct = fAct->next; 1671 } //end of facet checking1671 }end of facet checking 1672 1672 dd_FreeMatrix(P); 1673 //Now all extremal rays should be set w.r.t their respective fNormal1674 //TODO Not sufficient -> vol2 II/125&1271675 //NOTE Sufficient according to cddlibs doc. These ARE rays1676 //What the hell... let's just take interior points1673 Now all extremal rays should be set w.r.t their respective fNormal 1674 TODO Not sufficient -> vol2 II/125&127 1675 NOTE Sufficient according to cddlibs doc. These ARE rays 1676 What the hell... let's just take interior points 1677 1677 if(gcone::hasHomInput==FALSE) 1678 1678 { … … 1680 1680 while(fAct!=NULL) 1681 1681 { 1682 //bool containsStrictlyPosRay=FALSE;1683 //facet *codim2Act;1684 //codim2Act = fAct->codim2Ptr;1685 //while(codim2Act!=NULL)1686 //{1687 //int64vec *rayvec;1688 //rayvec = codim2Act->getFacetNormal();//Mind this is no normal but a ray!1689 ////int negCtr=0;1690 //if(iv64isStrictlyPositive(rayvec))1691 //{1692 //containsStrictlyPosRay=TRUE;1693 //delete(rayvec);1694 //break;1695 // } 1696 //delete(rayvec);1697 //codim2Act = codim2Act->next;1698 //}1699 //if(containsStrictlyPosRay==FALSE)1700 //fAct->isFlippable=FALSE;1682 bool containsStrictlyPosRay=FALSE; 1683 facet *codim2Act; 1684 codim2Act = fAct->codim2Ptr; 1685 while(codim2Act!=NULL) 1686 { 1687 int64vec *rayvec; 1688 rayvec = codim2Act->getFacetNormal();//Mind this is no normal but a ray! 1689 //int negCtr=0; 1690 if(iv64isStrictlyPositive(rayvec)) 1691 { 1692 containsStrictlyPosRay=TRUE; 1693 delete(rayvec); 1694 break; 1695 } 1696 delete(rayvec); 1697 codim2Act = codim2Act->next; 1698 } 1699 if(containsStrictlyPosRay==FALSE) 1700 fAct->isFlippable=FALSE; 1701 1701 if(!iv64isStrictlyPositive(fAct->interiorPoint)) 1702 1702 fAct->isFlippable=FALSE; 1703 1703 fAct = fAct->next; 1704 1704 } 1705 } //hasHomInput?1705 }hasHomInput? 1706 1706 #ifdef gfanp 1707 1707 gettimeofday(&end, 0); 1708 1708 t_getExtremalRays += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec)); 1709 #endif 1709 #endif 1710 1710 } 1711 1711 … … 1713 1713 void gcone::orderRays() 1714 1714 { 1715 //qsort(gcRays,sizeof(int64vec),int64vec::compare);1716 } 1717 1715 qsort(gcRays,sizeof(int64vec),int64vec::compare); 1716 } 1717 1718 1718 inline bool gcone::iv64isStrictlyPositive(const int64vec * iv64) 1719 1719 { … … 1725 1725 res=FALSE; 1726 1726 break; 1727 } 1727 } 1728 1728 } 1729 1729 return res; 1730 1730 } 1731 1731 1732 /** \brief Compute the Groebner Basis on the other side of a shared facet 1732 /** \brief Compute the Groebner Basis on the other side of a shared facet 1733 1733 * 1734 1734 * Implements algorithm 4.3.2 from Anders' thesis. … … 1738 1738 * Parallelity is checked using basic linear algebra. See gcone::isParallel. 1739 1739 * Other possibilities include computing the rank of the matrix consisting of the vectors in question and 1740 * computing an interior point of the facet and taking all terms having the same weight with respect 1740 * computing an interior point of the facet and taking all terms having the same weight with respect 1741 1741 * to this interior point. 1742 1742 *\param ideal, facet 1743 1743 * Input: a marked,reduced Groebner basis and a facet 1744 1744 */ 1745 inline void gcone::flip(ideal gb, facet *f) //Compute "the other side"1746 { 1745 inline void gcone::flip(ideal gb, facet *f) Compute "the other side" 1746 { 1747 1747 #ifdef gfanp 1748 1748 timeval start, end; 1749 1749 gettimeofday(&start, 0); 1750 #endif 1751 int64vec *fNormal; // = new int64vec(this->numVars); //facet normal, check for parallelity1752 fNormal = f->getFacetNormal(); //read this->fNormal;1750 #endif 1751 int64vec *fNormal; = new int64vec(this->numVars); //facet normal, check for parallelity 1752 fNormal = f->getFacetNormal(); read this->fNormal; 1753 1753 #ifdef gfan_DEBUG 1754 //std::cout << "running gcone::flip" << std::endl;1754 std::cout << "running gcone::flip" << std::endl; 1755 1755 printf("flipping UCN %i over facet",this->getUCN()); 1756 1756 fNormal->show(1,0); 1757 printf(") with UCN %i\n",f->getUCN() ); 1757 printf(") with UCN %i\n",f->getUCN() ); 1758 1758 #endif 1759 1759 if(this->getUCN() != f->getUCN()) … … 1763 1763 } 1764 1764 /*1st step: Compute the initial ideal*/ 1765 /*poly initialFormElement[IDELEMS(gb)];*/ //array of #polys in GB to store initial form1765 /*poly initialFormElement[IDELEMS(gb)];*/ array of #polys in GB to store initial form 1766 1766 ideal initialForm=idInit(IDELEMS(gb),this->gcBasis->rank); 1767 1767 1768 1768 computeInv(gb,initialForm,*fNormal); 1769 1769 … … 1771 1771 /* cout << "Initial ideal is: " << endl; 1772 1772 idShow(initialForm); 1773 //f->printFlipGB();*/1774 //cout << "===" << endl;1775 #endif 1773 f->printFlipGB();*/ 1774 cout << "===" << endl; 1775 #endif 1776 1776 /*2nd step: lift initial ideal to a GB of the neighbouring cone using minus alpha as weight*/ 1777 1777 /*Substep 2.1 1778 compute $G_{-\alpha}(in_v(I)) 1778 compute $G_{-\alpha}(in_v(I)) 1779 1779 see journal p. 66 1780 1780 NOTE Check for different rings. Prolly it will not always be necessary to add a weight, if the … … 1783 1783 ring srcRing=currRing; 1784 1784 ring tmpRing; 1785 1785 1786 1786 if( (srcRing->order[0]!=ringorder_a)) 1787 1787 { 1788 int64vec *iv; //= new int64vec(this->numVars);1789 iv = ivNeg(fNormal); //ivNeg uses iv64Copy -> new1790 //tmpRing=rCopyAndAddWeight(srcRing,ivNeg(fNormal));1788 int64vec *iv; = new int64vec(this->numVars); 1789 iv = ivNeg(fNormal);ivNeg uses iv64Copy -> new 1790 tmpRing=rCopyAndAddWeight(srcRing,ivNeg(fNormal)); 1791 1791 tmpRing=rCopyAndAddWeight(srcRing,iv); 1792 1792 delete iv; … … 1805 1805 tmpRing->block1[0]=length; 1806 1806 rComplete(tmpRing); 1807 //omFree(A);1808 } 1809 delete fNormal; 1810 rChangeCurrRing(tmpRing); 1811 1812 ideal ina; 1807 omFree(A); 1808 } 1809 delete fNormal; 1810 rChangeCurrRing(tmpRing); 1811 1812 ideal ina; 1813 1813 ina=idrCopyR(initialForm,srcRing); 1814 1814 idDelete(&initialForm); 1815 1815 ideal H; 1816 //H=kStd(ina,NULL,isHomog,NULL); //we know it is homogeneous1816 H=kStd(ina,NULL,isHomog,NULL); //we know it is homogeneous 1817 1817 #ifdef gfanp 1818 1818 timeval t_kStd_start, t_kStd_end; … … 1822 1822 H=kStd(ina,NULL,isHomog,NULL/*,gcone::hilbertFunction*/); 1823 1823 else 1824 H=kStd(ina,NULL,isNotHomog,NULL); //This is \mathcal(G)_{>_-\alpha}(in_v(I))1824 H=kStd(ina,NULL,isNotHomog,NULL); This is \mathcal(G)_{>_-\alpha}(in_v(I)) 1825 1825 #ifdef gfanp 1826 1826 gettimeofday(&t_kStd_end, 0); … … 1835 1835 rChangeCurrRing(srcRing); 1836 1836 ideal srcRing_H; 1837 ideal srcRing_HH; 1837 ideal srcRing_HH; 1838 1838 srcRing_H=idrCopyR(H,tmpRing); 1839 //H is needed further below, so don't idDelete here1839 H is needed further below, so don't idDelete here 1840 1840 srcRing_HH=ffG(srcRing_H,this->gcBasis); 1841 1841 idDelete(&srcRing_H); 1842 1842 1843 1843 /*Substep 2.2.1 1844 1844 * Mark according to G_-\alpha … … 1846 1846 * we have to compute an interior point of C(srcRing_HH). For this we need to know the cone 1847 1847 * represented by srcRing_HH MARKED ACCORDING TO G_{-\alpha} 1848 * Thus we check whether the leading monomials of srcRing_HH and srcRing_H coincide. If not we 1848 * Thus we check whether the leading monomials of srcRing_HH and srcRing_H coincide. If not we 1849 1849 * compute the difference accordingly 1850 1850 */ … … 1852 1852 timeval t_markings_start, t_markings_end; 1853 1853 gettimeofday(&t_markings_start, 0); 1854 #endif 1854 #endif 1855 1855 bool markingsAreCorrect=FALSE; 1856 1856 dd_MatrixPtr intPointMatrix; 1857 1857 int iPMatrixRows=0; 1858 dd_rowrange aktrow=0; 1858 dd_rowrange aktrow=0; 1859 1859 for (int ii=0;ii<IDELEMS(srcRing_HH);ii++) 1860 1860 { 1861 poly aktpoly=(poly)srcRing_HH->m[ii]; //This is a pointer, so don't pDelete1862 iPMatrixRows = iPMatrixRows+pLength(aktpoly); 1861 poly aktpoly=(poly)srcRing_HH->m[ii];This is a pointer, so don't pDelete 1862 iPMatrixRows = iPMatrixRows+pLength(aktpoly); 1863 1863 } 1864 1864 /* additionally one row for the standard-simplex and another for a row that becomes 0 during 1865 1865 * construction of the differences 1866 1866 */ 1867 intPointMatrix = dd_CreateMatrix(iPMatrixRows+2,this->numVars+1); 1868 intPointMatrix->numbtype=dd_Integer; //NOTE: DO NOT REMOVE OR CHANGE TO dd_Rational1869 1867 intPointMatrix = dd_CreateMatrix(iPMatrixRows+2,this->numVars+1); 1868 intPointMatrix->numbtype=dd_Integer; NOTE: DO NOT REMOVE OR CHANGE TO dd_Rational 1869 1870 1870 for (int ii=0;ii<IDELEMS(srcRing_HH);ii++) 1871 1871 { 1872 markingsAreCorrect=FALSE; //crucial to initialise here1873 poly aktpoly=srcRing_HH->m[ii]; //Only a pointer, so don't pDelete1872 markingsAreCorrect=FALSE; crucial to initialise here 1873 poly aktpoly=srcRing_HH->m[ii]; Only a pointer, so don't pDelete 1874 1874 /*Comparison of leading monomials is done via exponent vectors*/ 1875 1875 for (int jj=0;jj<IDELEMS(H);jj++) … … 1878 1878 int *dst_ExpV = (int *)omAlloc((this->numVars+1)*sizeof(int)); 1879 1879 pGetExpV(aktpoly,src_ExpV); 1880 rChangeCurrRing(tmpRing); //this ring change is crucial!1880 rChangeCurrRing(tmpRing); this ring change is crucial! 1881 1881 poly p=pCopy(H->m[ii]); 1882 1882 pGetExpV(p/*pCopy(H->m[ii])*/,dst_ExpV); … … 1887 1887 { 1888 1888 #ifdef gfan_DEBUG 1889 //cout << src_ExpV[kk] << "," << dst_ExpV[kk] << endl;1889 cout << src_ExpV[kk] << "," << dst_ExpV[kk] << endl; 1890 1890 #endif 1891 1891 if (src_ExpV[kk]!=dst_ExpV[kk]) … … 1893 1893 expVAreEqual=FALSE; 1894 1894 } 1895 } 1895 } 1896 1896 if (expVAreEqual==TRUE) 1897 1897 { 1898 markingsAreCorrect=TRUE; //everything is fine1898 markingsAreCorrect=TRUE; everything is fine 1899 1899 #ifdef gfan_DEBUG 1900 //cout << "correct markings" << endl;1901 #endif 1902 } //if (pHead(aktpoly)==pHead(H->m[jj])1900 cout << "correct markings" << endl; 1901 #endif 1902 }if (pHead(aktpoly)==pHead(H->m[jj]) 1903 1903 omFree(src_ExpV); 1904 1904 omFree(dst_ExpV); 1905 } //for (int jj=0;jj<IDELEMS(H);jj++)1906 1905 }for (int jj=0;jj<IDELEMS(H);jj++) 1906 1907 1907 int *leadExpV=(int *)omAlloc((this->numVars+1)*sizeof(int)); 1908 1908 if (markingsAreCorrect==TRUE) … … 1913 1913 { 1914 1914 rChangeCurrRing(tmpRing); 1915 pGetExpV(pHead(H->m[ii]),leadExpV); //We use H->m[ii] as leading monomial1915 pGetExpV(pHead(H->m[ii]),leadExpV); We use H->m[ii] as leading monomial 1916 1916 rChangeCurrRing(srcRing); 1917 1917 } 1918 /*compute differences of the expvects*/ 1918 /*compute differences of the expvects*/ 1919 1919 while (pNext(aktpoly)!=NULL) 1920 1920 { 1921 1921 int *v=(int *)omAlloc((this->numVars+1)*sizeof(int)); 1922 /*The following if-else-block makes sure the first term (i.e. the wrongly marked term) 1922 /*The following if-else-block makes sure the first term (i.e. the wrongly marked term) 1923 1923 is not omitted when computing the differences*/ 1924 1924 if(markingsAreCorrect==TRUE) … … 1934 1934 int ctr=0; 1935 1935 for (int jj=0;jj<this->numVars;jj++) 1936 { 1937 /*Store into ddMatrix*/ 1936 { 1937 /*Store into ddMatrix*/ 1938 1938 if(leadExpV[jj+1]-v[jj+1]) 1939 1939 ctr++; … … 1941 1941 } 1942 1942 /*It ought to be more sensible to avoid 0-rows in the first place*/ 1943 //if(ctr==this->numVars)//We have a 0-row1944 //dd_MatrixRowRemove(&intPointMatrix,aktrow);1945 //else1943 if(ctr==this->numVars)//We have a 0-row 1944 dd_MatrixRowRemove(&intPointMatrix,aktrow); 1945 else 1946 1946 aktrow +=1; 1947 1947 omFree(v); 1948 1948 } 1949 1949 omFree(leadExpV); 1950 } //for (int ii=0;ii<IDELEMS(srcRing_HH);ii++)1950 }for (int ii=0;ii<IDELEMS(srcRing_HH);ii++) 1951 1951 #ifdef gfanp 1952 1952 gettimeofday(&t_markings_end, 0); … … 1960 1960 preprocessInequalities(intPointMatrix); 1961 1961 /*Now we add the constraint for the standard simplex*/ 1962 //dd_set_si(intPointMatrix->matrix[aktrow][0],-1);1963 //for (int jj=1;jj<=this->numVars;jj++)1964 //{1965 //dd_set_si(intPointMatrix->matrix[aktrow][jj],1);1966 //}1967 //Let's make sure we compute interior points from the positive orthant1968 //dd_MatrixPtr posRestr=dd_CreateMatrix(this->numVars,this->numVars+1);1969 // 1970 //int jj=1;1971 //for (int ii=0;ii<this->numVars;ii++)1972 //{1973 //dd_set_si(posRestr->matrix[ii][jj],1);1974 // jj++; 1975 //}1962 dd_set_si(intPointMatrix->matrix[aktrow][0],-1); 1963 for (int jj=1;jj<=this->numVars;jj++) 1964 { 1965 dd_set_si(intPointMatrix->matrix[aktrow][jj],1); 1966 } 1967 Let's make sure we compute interior points from the positive orthant 1968 dd_MatrixPtr posRestr=dd_CreateMatrix(this->numVars,this->numVars+1); 1969 1970 int jj=1; 1971 for (int ii=0;ii<this->numVars;ii++) 1972 { 1973 dd_set_si(posRestr->matrix[ii][jj],1); 1974 jj++; 1975 } 1976 1976 /*We create a matrix containing the standard simplex 1977 1977 * and constraints to assure a strictly positive point … … 1983 1983 { 1984 1984 dd_set_si(posRestr->matrix[ii][0],-1); 1985 for(int jj=1;jj<=this->numVars;jj++) 1986 dd_set_si(posRestr->matrix[ii][jj],1); 1985 for(int jj=1;jj<=this->numVars;jj++) 1986 dd_set_si(posRestr->matrix[ii][jj],1); 1987 1987 } 1988 1988 else … … 2005 2005 dd_rowindex newpos; 2006 2006 2007 //NOTE Here we should remove interiorPoint and instead2008 //create and ordering like (a(omega),a(fNormal),dp)2009 //if(this->ivIntPt==NULL)2010 interiorPoint(intPointMatrix, *iv_weight); //iv_weight now contains the interior point2011 //else2012 //iv_weight=this->getIntPoint();2007 NOTE Here we should remove interiorPoint and instead 2008 create and ordering like (a(omega),a(fNormal),dp) 2009 if(this->ivIntPt==NULL) 2010 interiorPoint(intPointMatrix, *iv_weight); iv_weight now contains the interior point 2011 else 2012 iv_weight=this->getIntPoint(); 2013 2013 dd_FreeMatrix(intPointMatrix); 2014 2014 /*Crude attempt for interior point */ … … 2034 2034 gettimeofday(&t_dd_end, 0); 2035 2035 t_dd += (t_dd_end.tv_sec - t_dd_start.tv_sec + 1e-6*(t_dd_end.tv_usec - t_dd_start.tv_usec)); 2036 #endif 2037 2036 #endif 2037 2038 2038 /*Step 3 2039 * turn the minimal basis into a reduced one */ 2040 //NOTE May assume that at this point srcRing already has 3 blocks of orderins, starting with a2041 // Thus:2042 //ring dstRing=rCopyAndChangeWeight(srcRing,iv_weight);2039 * turn the minimal basis into a reduced one */ 2040 NOTE May assume that at this point srcRing already has 3 blocks of orderins, starting with a 2041 Thus: 2042 ring dstRing=rCopyAndChangeWeight(srcRing,iv_weight); 2043 2043 ring dstRing=rCopy0(tmpRing); 2044 2044 int length=iv_weight->length(); … … 2054 2054 delete iv_weight; 2055 2055 2056 ideal dstRing_I; 2056 ideal dstRing_I; 2057 2057 dstRing_I=idrCopyR(srcRing_HH,srcRing); 2058 idDelete(&srcRing_HH); //Hmm.... causes trouble - no more2059 //dstRing_I=idrCopyR(inputIdeal,srcRing);2058 idDelete(&srcRing_HH); Hmm.... causes trouble - no more 2059 dstRing_I=idrCopyR(inputIdeal,srcRing); 2060 2060 BITSET save=test; 2061 2061 test|=Sy_bit(OPT_REDSB); 2062 2062 test|=Sy_bit(OPT_REDTAIL); 2063 2063 #ifdef gfan_DEBUG 2064 //test|=Sy_bit(6); //OPT_DEBUG2064 test|=Sy_bit(6); //OPT_DEBUG 2065 2065 #endif 2066 2066 ideal tmpI; 2067 //NOTE Any of the two variants of tmpI={idrCopy(),dstRing_I} does the trick2068 //tmpI = idrCopyR(this->inputIdeal,this->baseRing);2067 NOTE Any of the two variants of tmpI={idrCopy(),dstRing_I} does the trick 2068 tmpI = idrCopyR(this->inputIdeal,this->baseRing); 2069 2069 tmpI = dstRing_I; 2070 2070 #ifdef gfanp … … 2080 2080 #endif 2081 2081 idDelete(&tmpI); 2082 idNorm(dstRing_I); 2083 //kInterRed(dstRing_I);2082 idNorm(dstRing_I); 2083 kInterRed(dstRing_I); 2084 2084 idSkipZeroes(dstRing_I); 2085 2085 test=save; 2086 2086 /*End of step 3 - reduction*/ 2087 2088 f->setFlipGB(dstRing_I); //store the flipped GB2089 //idDelete(&dstRing_I);2090 f->flipRing=rCopy(dstRing); //store the ring on the other side2087 2088 f->setFlipGB(dstRing_I);store the flipped GB 2089 idDelete(&dstRing_I); 2090 f->flipRing=rCopy(dstRing); store the ring on the other side 2091 2091 #ifdef gfan_DEBUG 2092 2092 printf("Flipped GB is UCN %i:\n",counter+1); 2093 2093 idDebugPrint(dstRing_I); 2094 2094 printf("\n"); 2095 #endif 2096 idDelete(&dstRing_I); 2097 rChangeCurrRing(srcRing); //return to the ring we started the computation of flipGB in2095 #endif 2096 idDelete(&dstRing_I); 2097 rChangeCurrRing(srcRing); return to the ring we started the computation of flipGB in 2098 2098 rDelete(dstRing); 2099 2099 #ifdef gfanp … … 2101 2101 time_flip += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec)); 2102 2102 #endif 2103 } //void flip(ideal gb, facet *f)2103 }void flip(ideal gb, facet *f) 2104 2104 2105 2105 /** \brief A slightly different approach to flipping … … 2111 2111 * will be from a ring with (a(),dp,C) and our resulting cone from (a(),a(),dp,C). Hence a way 2112 2112 * must be found to circumvent the sequence of a()'s growing to a ridiculous size. 2113 * Therefore: We use (a(),a(),dp,C) for the computation of the reduced basis. But then we 2114 * do have an interior point of the cone by adding the extremal rays. So we replace 2115 * the latter cone by a cone with (a(sum_of_rays),dp,C). 2113 * Therefore: We use (a(),a(),dp,C) for the computation of the reduced basis. But then we 2114 * do have an interior point of the cone by adding the extremal rays. So we replace 2115 * the latter cone by a cone with (a(sum_of_rays),dp,C). 2116 2116 * Con: It's incredibly ugly 2117 2117 * Pro: No messing around with readConeFromFile() … … 2125 2125 #endif 2126 2126 const int64vec *fNormal; 2127 fNormal = f->getRef2FacetNormal();/*->getFacetNormal();*/ //read this->fNormal;2127 fNormal = f->getRef2FacetNormal();/*->getFacetNormal();*/ read this->fNormal; 2128 2128 #ifdef gfan_DEBUG 2129 2129 printf("flipping UCN %i over facet(",this->getUCN()); 2130 2130 fNormal->show(1,0); 2131 printf(") with UCN %i\n",f->getUCN()); 2131 printf(") with UCN %i\n",f->getUCN()); 2132 2132 #endif 2133 2133 if(this->getUCN() != f->getUCN()) … … 2137 2137 } 2138 2138 /*1st step: Compute the initial ideal*/ 2139 ideal initialForm=idInit(IDELEMS(gb),this->gcBasis->rank); 2139 ideal initialForm=idInit(IDELEMS(gb),this->gcBasis->rank); 2140 2140 computeInv( gb, initialForm, *fNormal ); 2141 2141 ring srcRing=currRing; 2142 2142 ring tmpRing; 2143 2143 2144 2144 const int64vec *intPointOfFacet; 2145 2145 intPointOfFacet=f->getInteriorPoint(); 2146 //Now we need two blocks of ringorder_a!2147 //May assume the same situation as in flip() here2146 Now we need two blocks of ringorder_a! 2147 May assume the same situation as in flip() here 2148 2148 if( (srcRing->order[0]!=ringorder_a/*64*/) && (srcRing->order[1]!=ringorder_a/*64*/) ) 2149 2149 { 2150 int64vec *iv = new int64vec(this->numVars); //init with 1s, since we do not need a 2nd block here but later2151 //int64vec *iv_foo = new int64vec(this->numVars,1);//placeholder2152 int64vec *ivw = ivNeg(const_cast<int64vec*>(fNormal)); 2150 int64vec *iv = new int64vec(this->numVars);init with 1s, since we do not need a 2nd block here but later 2151 int64vec *iv_foo = new int64vec(this->numVars,1);//placeholder 2152 int64vec *ivw = ivNeg(const_cast<int64vec*>(fNormal)); 2153 2153 tmpRing=rCopyAndAddWeight2(srcRing,ivw/*intPointOfFacet*/,iv); 2154 2154 delete iv;delete ivw; 2155 //delete iv_foo;2156 } 2157 else 2155 delete iv_foo; 2156 } 2157 else 2158 2158 { 2159 2159 int64vec *iv=new int64vec(this->numVars); … … 2168 2168 { 2169 2169 A1[jj] = -(*fNormal)[jj]; 2170 A2[jj] = 1; //-(*fNormal)[jj];//NOTE Do we need this here? This is only the facet ideal2170 A2[jj] = 1;-(*fNormal)[jj];//NOTE Do we need this here? This is only the facet ideal 2171 2171 } 2172 2172 omFree(tmpRing->wvhdl[0]); 2173 2173 if(tmpRing->wvhdl[1]!=NULL) 2174 2174 omFree(tmpRing->wvhdl[1]); 2175 tmpRing->wvhdl[0]=(int*)A1; 2175 tmpRing->wvhdl[0]=(int*)A1; 2176 2176 tmpRing->block1[0]=length; 2177 tmpRing->wvhdl[1]=(int*)A2; 2177 tmpRing->wvhdl[1]=(int*)A2; 2178 2178 tmpRing->block1[1]=length; 2179 2179 rComplete(tmpRing);*/ 2180 2180 } 2181 //delete fNormal; //NOTE Do not delete when using getRef2FacetNormal();2182 rChangeCurrRing(tmpRing); 2183 //Now currRing should have (a(),a(),dp,C)2184 ideal ina; 2181 delete fNormal; //NOTE Do not delete when using getRef2FacetNormal(); 2182 rChangeCurrRing(tmpRing); 2183 Now currRing should have (a(),a(),dp,C) 2184 ideal ina; 2185 2185 ina=idrCopyR(initialForm,srcRing); 2186 2186 idDelete(&initialForm); … … 2193 2193 test|=Sy_bit(OPT_REDSB); 2194 2194 test|=Sy_bit(OPT_REDTAIL); 2195 //if(gcone::hasHomInput==TRUE)2195 if(gcone::hasHomInput==TRUE) 2196 2196 H=kStd(ina,NULL,testHomog/*isHomog*/,NULL/*,gcone::hilbertFunction*/); 2197 //else2198 //H=kStd(ina,NULL,isNotHomog,NULL); //This is \mathcal(G)_{>_-\alpha}(in_v(I))2197 else 2198 H=kStd(ina,NULL,isNotHomog,NULL); //This is \mathcal(G)_{>_-\alpha}(in_v(I)) 2199 2199 test=save; 2200 2200 #ifdef gfanp … … 2204 2204 idSkipZeroes(H); 2205 2205 idDelete(&ina); 2206 2206 2207 2207 rChangeCurrRing(srcRing); 2208 2208 ideal srcRing_H; 2209 ideal srcRing_HH; 2209 ideal srcRing_HH; 2210 2210 srcRing_H=idrCopyR(H,tmpRing); 2211 //H is needed further below, so don't idDelete here2211 H is needed further below, so don't idDelete here 2212 2212 srcRing_HH=ffG(srcRing_H,this->gcBasis); 2213 2213 idDelete(&srcRing_H); 2214 //Now BBA(srcRing_HH) with (a(),a(),dp)2214 Now BBA(srcRing_HH) with (a(),a(),dp) 2215 2215 /* Evil modification of currRing */ 2216 2216 ring dstRing=rCopy0(tmpRing); … … 2222 2222 { 2223 2223 A1[jj] = (*intPointOfFacet)[jj]; 2224 A2[jj] = -(*ivw)[jj]; //TODO Or minus (*ivw)[ii] ??? NOTE minus2224 A2[jj] = -(*ivw)[jj];TODO Or minus (*ivw)[ii] ??? NOTE minus 2225 2225 } 2226 2226 omFree(dstRing->wvhdl[0]); 2227 2227 if(dstRing->wvhdl[1]!=NULL) 2228 2228 omFree(dstRing->wvhdl[1]); 2229 dstRing->wvhdl[0]=(int*)A1; 2229 dstRing->wvhdl[0]=(int*)A1; 2230 2230 dstRing->block1[0]=length; 2231 dstRing->wvhdl[1]=(int*)A2; 2231 dstRing->wvhdl[1]=(int*)A2; 2232 2232 dstRing->block1[1]=length; 2233 2233 rComplete(dstRing); 2234 2234 rChangeCurrRing(dstRing); 2235 ideal dstRing_I; 2235 ideal dstRing_I; 2236 2236 dstRing_I=idrCopyR(srcRing_HH,srcRing); 2237 idDelete(&srcRing_HH); //Hmm.... causes trouble - no more2237 idDelete(&srcRing_HH); Hmm.... causes trouble - no more 2238 2238 save=test; 2239 2239 test|=Sy_bit(OPT_REDSB); … … 2242 2242 tmpI = dstRing_I; 2243 2243 #ifdef gfanp 2244 //timeval t_kStd_start, t_kStd_end;2244 timeval t_kStd_start, t_kStd_end; 2245 2245 gettimeofday(&t_kStd_start,0); 2246 2246 #endif 2247 //if(gcone::hasHomInput==TRUE)2248 //dstRing_I=kStd(tmpI,NULL,isHomog,NULL/*,gcone::hilbertFunction*/);2249 //else2247 if(gcone::hasHomInput==TRUE) 2248 dstRing_I=kStd(tmpI,NULL,isHomog,NULL/*,gcone::hilbertFunction*/); 2249 else 2250 2250 dstRing_I=kStd(tmpI,NULL,testHomog,NULL); 2251 2251 #ifdef gfanp … … 2254 2254 #endif 2255 2255 idDelete(&tmpI); 2256 idNorm(dstRing_I); 2256 idNorm(dstRing_I); 2257 2257 idSkipZeroes(dstRing_I); 2258 2258 test=save; 2259 2259 /*End of step 3 - reduction*/ 2260 2260 2261 2261 f->setFlipGB(dstRing_I); 2262 2262 f->flipRing=rCopy(dstRing); 2263 2263 rDelete(tmpRing); 2264 2264 rDelete(dstRing); 2265 //Now we should have dstRing with (a(),a(),dp,C)2266 //This must be replaced with (a(),dp,C) BEFORE gcTmp is actually added to the list2267 //of cones in noRevS2265 Now we should have dstRing with (a(),a(),dp,C) 2266 This must be replaced with (a(),dp,C) BEFORE gcTmp is actually added to the list 2267 of cones in noRevS 2268 2268 rChangeCurrRing(srcRing); 2269 2269 #ifdef gfanp … … 2271 2271 time_flip2 += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec)); 2272 2272 #endif 2273 } //flip22273 }flip2 2274 2274 2275 2275 /** \brief Compute initial ideal … … 2287 2287 { 2288 2288 poly initialFormElement; 2289 poly aktpoly = (poly)gb->m[ii]; //Ptr, so don't pDelete(aktpoly)2289 poly aktpoly = (poly)gb->m[ii];Ptr, so don't pDelete(aktpoly) 2290 2290 int *leadExpV=(int *)omAlloc((this->numVars+1)*sizeof(int)); 2291 pGetExpV(aktpoly,leadExpV); //find the leading exponent in leadExpV[1],...,leadExpV[n], use pNext(p)2291 pGetExpV(aktpoly,leadExpV); find the leading exponent in leadExpV[1],...,leadExpV[n], use pNext(p) 2292 2292 initialFormElement=pHead(aktpoly); 2293 //int *v=(int *)omAlloc((this->numVars+1)*sizeof(int));2293 int *v=(int *)omAlloc((this->numVars+1)*sizeof(int)); 2294 2294 while(pNext(aktpoly)!=NULL) /*loop trough terms and check for parallelity*/ 2295 2295 { 2296 2296 int64vec *check = new int64vec(this->numVars); 2297 aktpoly=pNext(aktpoly); //next term2297 aktpoly=pNext(aktpoly); next term 2298 2298 int *v=(int *)omAlloc((this->numVars+1)*sizeof(int)); 2299 pGetExpV(aktpoly,v); 2299 pGetExpV(aktpoly,v); 2300 2300 /* Convert (int)v into (int64vec)check */ 2301 //bool notPar=FALSE;2301 bool notPar=FALSE; 2302 2302 for (int jj=0;jj<this->numVars;jj++) 2303 2303 { 2304 2304 (*check)[jj]=v[jj+1]-leadExpV[jj+1]; 2305 //register int64 foo=(fNormal)[jj];2306 // if( ( (*check)[jj] == /*fNormal[jj]*/foo ) 2307 // || ( (/*fNormal[jj]*/foo!=0) && ( ( (*check)[jj] % /*fNormal[jj]*/foo ) !=0 ) ) ) 2308 //{2309 //notPar=TRUE;2310 //break;2311 //}2305 register int64 foo=(fNormal)[jj]; 2306 if( ( (*check)[jj] == /*fNormal[jj]*/foo ) 2307 || ( (/*fNormal[jj]*/foo!=0) && ( ( (*check)[jj] % /*fNormal[jj]*/foo ) !=0 ) ) ) 2308 { 2309 notPar=TRUE; 2310 break; 2311 } 2312 2312 } 2313 2313 omFree(v); 2314 if (isParallel(*check,fNormal)) //Found a parallel vector. Add it2315 //if(notPar==FALSE)2316 { 2317 initialFormElement = pAdd((initialFormElement),(poly)pHead(aktpoly)); //pAdd = p_Add_q destroys args2314 if (isParallel(*check,fNormal))Found a parallel vector. Add it 2315 if(notPar==FALSE) 2316 { 2317 initialFormElement = pAdd((initialFormElement),(poly)pHead(aktpoly));pAdd = p_Add_q destroys args 2318 2318 } 2319 2319 delete check; 2320 } //while2321 //omFree(v);2320 }while 2321 omFree(v); 2322 2322 #ifdef gfan_DEBUG 2323 // cout << "Initial Form="; 2324 //pWrite(initialFormElement[ii]);2325 //cout << "---" << endl;2323 cout << "Initial Form="; 2324 pWrite(initialFormElement[ii]); 2325 cout << "---" << endl; 2326 2326 #endif 2327 2327 /*Now initialFormElement must be added to (ideal)initialForm */ … … 2329 2329 pDelete(&initialFormElement); 2330 2330 omFree(leadExpV); 2331 } //for2331 }for 2332 2332 #ifdef gfanp 2333 2333 gettimeofday(&end, 0); … … 2343 2343 * compute the factors \f$ a_i \f$ 2344 2344 */ 2345 //NOTE: Should be replaced by kNF or kNF22346 //NOTE: Done2347 //NOTE: removed with r122862348 2345 NOTE: Should be replaced by kNF or kNF2 2346 NOTE: Done 2347 NOTE: removed with r12286 2348 2349 2349 /** \brief Compute \f$ f-f^{\mathcal{G}} \f$ 2350 2350 */ 2351 //NOTE: use kNF or kNF2 instead of restOfDivision2351 NOTE: use kNF or kNF2 instead of restOfDivision 2352 2352 inline ideal gcone::ffG(const ideal &H, const ideal &G) 2353 2353 { … … 2356 2356 for (int ii=0;ii<size;ii++) 2357 2357 { 2358 //poly temp1;//=pInit();2359 //poly temp2;//=pInit();2360 poly temp3; //=pInit();//polys to temporarily store values for pSub2361 //res->m[ii]=pCopy(kNF(G, NULL,H->m[ii],0,0));2362 //temp1=pCopy(H->m[ii]);//TRY2363 //temp2=pCopy(res->m[ii]);2364 //NOTE if gfanHeuristic=0 (sic!) this results in dPolyErrors - mon from wrong ring2365 //temp2=pCopy(kNF(G, NULL,H->m[ii],0,0));//TRY2366 //temp3=pSub(temp1, temp2);//TRY2367 temp3=pSub(pCopy(H->m[ii]),pCopy(kNF(G,NULL,H->m[ii],0,0))); //NOTRY2358 poly temp1;//=pInit(); 2359 poly temp2;//=pInit(); 2360 poly temp3;=pInit();//polys to temporarily store values for pSub 2361 res->m[ii]=pCopy(kNF(G, NULL,H->m[ii],0,0)); 2362 temp1=pCopy(H->m[ii]);//TRY 2363 temp2=pCopy(res->m[ii]); 2364 NOTE if gfanHeuristic=0 (sic!) this results in dPolyErrors - mon from wrong ring 2365 temp2=pCopy(kNF(G, NULL,H->m[ii],0,0));//TRY 2366 temp3=pSub(temp1, temp2);//TRY 2367 temp3=pSub(pCopy(H->m[ii]),pCopy(kNF(G,NULL,H->m[ii],0,0)));NOTRY 2368 2368 res->m[ii]=pCopy(temp3); 2369 //res->m[ii]=pSub(temp1,temp2); //buggy2370 //cout << "res->m["<<ii<<"]=";pWrite(res->m[ii]);2371 //pDelete(&temp1);//TRY2372 //pDelete(&temp2);2369 res->m[ii]=pSub(temp1,temp2); //buggy 2370 cout << "res->m["<<ii<<"]=";pWrite(res->m[ii]); 2371 pDelete(&temp1);//TRY 2372 pDelete(&temp2); 2373 2373 pDelete(&temp3); 2374 2374 } 2375 2375 return res; 2376 2376 } 2377 2377 2378 2378 /** \brief Preprocessing of inequlities 2379 2379 * Do some preprocessing on the matrix of inequalities … … 2388 2388 int num_elts=0; 2389 2389 int offset=0;*/ 2390 //Remove zeroes (and strictly pos rows?)2390 Remove zeroes (and strictly pos rows?) 2391 2391 for(int ii=0;ii<ddineq->rowsize;ii++) 2392 2392 { 2393 2393 int64vec *iv = new int64vec(this->numVars); 2394 int64vec *ivNull = new int64vec(this->numVars); //Needed for intvec64::compare(*int64vec)2394 int64vec *ivNull = new int64vec(this->numVars);Needed for intvec64::compare(*int64vec) 2395 2395 int posCtr=0; 2396 2396 for(int jj=0;jj<this->numVars;jj++) 2397 2397 { 2398 2398 (*iv)[jj]=(int)mpq_get_d(ddineq->matrix[ii][jj+1]); 2399 if((*iv)[jj]>0) //check for strictly pos rows2399 if((*iv)[jj]>0)check for strictly pos rows 2400 2400 posCtr++; 2401 //Behold! This will delete the row for the standard simplex!2402 } 2403 //if( (iv->compare(0)==0) || (posCtr==iv->length()) )2404 if( (posCtr==iv->length()) || (iv->compare(ivNull)==0) ) 2401 Behold! This will delete the row for the standard simplex! 2402 } 2403 if( (iv->compare(0)==0) || (posCtr==iv->length()) ) 2404 if( (posCtr==iv->length()) || (iv->compare(ivNull)==0) ) 2405 2405 { 2406 2406 dd_MatrixRowRemove(&ddineq,ii+1); 2407 ii--; //Yes. This is on purpose2407 ii--;Yes. This is on purpose 2408 2408 } 2409 2409 delete iv; 2410 2410 delete ivNull; 2411 2411 } 2412 //Remove duplicates of rows2413 //posRowsArray=NULL;2414 //num_alloc=0;2415 //num_elts=0;2416 //offset=0;2417 //int num_newRows = ddineq->rowsize;2418 //for(int ii=0;ii<ddineq->rowsize-1;ii++)2419 //for(int ii=0;ii<num_newRows-1;ii++)2420 //{2421 //int64vec *iv = new int64vec(this->numVars);//1st vector to check against2422 //for(int jj=0;jj<this->numVars;jj++)2423 //(*iv)[jj]=(int)mpq_get_d(ddineq->matrix[ii][jj+1]);2424 //for(int jj=ii+1;jj</*ddineq->rowsize*/num_newRows;jj++)2425 //{2426 //int64vec *ivCheck = new int64vec(this->numVars);//Checked against iv2427 //for(int kk=0;kk<this->numVars;kk++)2428 //(*ivCheck)[kk]=(int)mpq_get_d(ddineq->matrix[jj][kk+1]);2429 //if (iv->compare(ivCheck)==0)2430 //{2431 //// cout << "=" << endl;2432 //// num_alloc++;2433 //// void *tmp=realloc(posRowsArray,(num_alloc*sizeof(int)));2434 //// if(!tmp)2435 //// {2436 //// WerrorS("Woah dude! Couldn't realloc memory\n");2437 //// exit(-1);2438 //// }2439 //// posRowsArray = (int*)tmp;2440 //// posRowsArray[num_elts]=jj;2441 //// num_elts++;2442 //dd_MatrixRowRemove(&ddineq,jj+1);2443 //num_newRows = ddineq->rowsize;2444 //}2445 //delete ivCheck;2446 //}2447 //delete iv;2448 //}2449 //for(int ii=0;ii<num_elts;ii++)2450 //{2451 //dd_MatrixRowRemove(&ddineq,posRowsArray[ii]+1-offset);2452 //offset++;2453 //}2454 //free(posRowsArray);2455 //Apply Thm 2.1 of JOTA Vol 53 No 1 April 1987*/2456 } //preprocessInequalities2457 2412 Remove duplicates of rows 2413 posRowsArray=NULL; 2414 num_alloc=0; 2415 num_elts=0; 2416 offset=0; 2417 int num_newRows = ddineq->rowsize; 2418 for(int ii=0;ii<ddineq->rowsize-1;ii++) 2419 for(int ii=0;ii<num_newRows-1;ii++) 2420 { 2421 int64vec *iv = new int64vec(this->numVars);//1st vector to check against 2422 for(int jj=0;jj<this->numVars;jj++) 2423 (*iv)[jj]=(int)mpq_get_d(ddineq->matrix[ii][jj+1]); 2424 for(int jj=ii+1;jj</*ddineq->rowsize*/num_newRows;jj++) 2425 { 2426 int64vec *ivCheck = new int64vec(this->numVars);//Checked against iv 2427 for(int kk=0;kk<this->numVars;kk++) 2428 (*ivCheck)[kk]=(int)mpq_get_d(ddineq->matrix[jj][kk+1]); 2429 if (iv->compare(ivCheck)==0) 2430 { 2431 // cout << "=" << endl; 2432 // num_alloc++; 2433 // void *tmp=realloc(posRowsArray,(num_alloc*sizeof(int))); 2434 // if(!tmp) 2435 // { 2436 // WerrorS("Woah dude! Couldn't realloc memory\n"); 2437 // exit(-1); 2438 // } 2439 // posRowsArray = (int*)tmp; 2440 // posRowsArray[num_elts]=jj; 2441 // num_elts++; 2442 dd_MatrixRowRemove(&ddineq,jj+1); 2443 num_newRows = ddineq->rowsize; 2444 } 2445 delete ivCheck; 2446 } 2447 delete iv; 2448 } 2449 for(int ii=0;ii<num_elts;ii++) 2450 { 2451 dd_MatrixRowRemove(&ddineq,posRowsArray[ii]+1-offset); 2452 offset++; 2453 } 2454 free(posRowsArray); 2455 Apply Thm 2.1 of JOTA Vol 53 No 1 April 1987*/ 2456 }preprocessInequalities 2457 2458 2458 /** \brief Compute a Groebner Basis 2459 2459 * … … 2462 2462 *\return void 2463 2463 */ 2464 inline void gcone::getGB(const ideal &inputIdeal) 2464 inline void gcone::getGB(const ideal &inputIdeal) 2465 2465 { 2466 2466 BITSET save=test; … … 2471 2471 idNorm(gb); 2472 2472 idSkipZeroes(gb); 2473 this->gcBasis=gb; //write the GB into gcBasis2473 this->gcBasis=gb; write the GB into gcBasis 2474 2474 test=save; 2475 } //void getGB2476 2475 }void getGB 2476 2477 2477 /** \brief Compute the negative of a given int64vec 2478 */ 2478 */ 2479 2479 static int64vec* ivNeg(/*const*/int64vec *iv) 2480 { //Hm, switching to int64vec const int64vec does no longer work2481 int64vec *res; //= new int64vec(iv->length());2480 { Hm, switching to int64vec const int64vec does no longer work 2481 int64vec *res; = new int64vec(iv->length()); 2482 2482 res=iv64Copy(iv); 2483 *res *= (int)-1; 2483 *res *= (int)-1; 2484 2484 return res; 2485 2485 } … … 2489 2489 * 2490 2490 */ 2491 static int dotProduct(const int64vec &iva, const int64vec &ivb) 2492 { 2493 int res=0; 2491 static int dotProduct(const int64vec &iva, const int64vec &ivb) 2492 { 2493 int res=0; 2494 2494 for (int i=0;i<pVariables;i++) 2495 2495 { 2496 //#ifndef NDEBUG2497 //(const_cast<int64vec*>(&iva))->show(1,0); (const_cast<int64vec*>(&ivb))->show(1,0);2498 //#endif2496 #ifndef NDEBUG 2497 (const_cast<int64vec*>(&iva))->show(1,0); (const_cast<int64vec*>(&ivb))->show(1,0); 2498 #endif 2499 2499 res = res+(iva[i]*ivb[i]); 2500 2500 } … … 2506 2506 */ 2507 2507 static bool isParallel(const int64vec &a,const int64vec &b) 2508 { 2509 /*#ifdef gfanp 2508 { 2509 /*#ifdef gfanp 2510 2510 timeval start, end; 2511 2511 gettimeofday(&start, 0); 2512 #endif*/ 2512 #endif*/ 2513 2513 bool res; 2514 2514 int lhs=dotProduct(a,b)*dotProduct(a,b); 2515 2515 int rhs=dotProduct(a,a)*dotProduct(b,b); 2516 //#ifdef gfanp2517 //gettimeofday(&end, 0);2518 //t_isParallel += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec));2519 // #endif 2520 //return res;2516 #ifdef gfanp 2517 gettimeofday(&end, 0); 2518 t_isParallel += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec)); 2519 #endif 2520 return res; 2521 2521 return res = (lhs==rhs)?TRUE:FALSE; 2522 } //bool isParallel2522 }bool isParallel 2523 2523 2524 2524 /** \brief Compute an interior point of a given cone 2525 * Result will be written into int64vec iv. 2525 * Result will be written into int64vec iv. 2526 2526 * Any rational point is automatically converted into an integer. 2527 2527 */ 2528 void gcone::interiorPoint( dd_MatrixPtr &M, int64vec &iv) //no const &M here since we want to remove redundant rows2528 void gcone::interiorPoint( dd_MatrixPtr &M, int64vec &iv) no const &M here since we want to remove redundant rows 2529 2529 { 2530 2530 dd_LPPtr lp,lpInt; … … 2532 2532 dd_LPSolverType solver=dd_DualSimplex; 2533 2533 dd_LPSolutionPtr lpSol=NULL; 2534 //dd_rowset ddlinset,ddredrows; //needed for dd_FindRelativeInterior2535 //dd_rowindex ddnewpos;2536 dd_NumberType numb; 2537 //M->representation=dd_Inequality;2538 2539 //NOTE: Make this n-dimensional!2540 //dd_set_si(M->rowvec[0],1);dd_set_si(M->rowvec[1],1);dd_set_si(M->rowvec[2],1);2541 2534 dd_rowset ddlinset,ddredrows; //needed for dd_FindRelativeInterior 2535 dd_rowindex ddnewpos; 2536 dd_NumberType numb; 2537 M->representation=dd_Inequality; 2538 2539 NOTE: Make this n-dimensional! 2540 dd_set_si(M->rowvec[0],1);dd_set_si(M->rowvec[1],1);dd_set_si(M->rowvec[2],1); 2541 2542 2542 /*NOTE: Leave the following line commented out! 2543 2543 * Otherwise it will slow down computations a great deal 2544 2544 * */ 2545 //dd_MatrixCanonicalizeLinearity(&M, &ddlinset, &ddnewpos, &err);2546 //if (err!=dd_NoError){cout << "Error during dd_MatrixCanonicalize" << endl;}2545 dd_MatrixCanonicalizeLinearity(&M, &ddlinset, &ddnewpos, &err); 2546 if (err!=dd_NoError){cout << "Error during dd_MatrixCanonicalize" << endl;} 2547 2547 dd_MatrixPtr posRestr=dd_CreateMatrix(this->numVars,this->numVars+1); 2548 2548 int jj=1; … … 2550 2550 { 2551 2551 dd_set_si(posRestr->matrix[ii][jj],1); 2552 jj++; 2552 jj++; 2553 2553 } 2554 2554 dd_MatrixAppendTo(&M,posRestr); … … 2558 2558 if (lp==NULL){WerrorS("LP is NULL");} 2559 2559 #ifdef gfan_DEBUG 2560 //dd_WriteLP(stdout,lp);2561 #endif 2562 2560 dd_WriteLP(stdout,lp); 2561 #endif 2562 2563 2563 lpInt=dd_MakeLPforInteriorFinding(lp); 2564 2564 if (err!=dd_NoError){WerrorS("Error during dd_MakeLPForInteriorFinding in gcone::interiorPoint");} 2565 2565 #ifdef gfan_DEBUG 2566 //dd_WriteLP(stdout,lpInt);2567 #endif 2568 //dd_FindRelativeInterior(M,&ddlinset,&ddredrows,&lpSol,&err);2566 dd_WriteLP(stdout,lpInt); 2567 #endif 2568 dd_FindRelativeInterior(M,&ddlinset,&ddredrows,&lpSol,&err); 2569 2569 if (err!=dd_NoError) 2570 2570 { 2571 2571 WerrorS("Error during dd_FindRelativeInterior in gcone::interiorPoint"); 2572 2572 dd_WriteErrorMessages(stdout, err); 2573 } 2574 dd_LPSolve(lpInt,solver,&err); //This will not result in a point from the relative interior2575 // if (err!=dd_NoError){WerrorS("Error during dd_LPSolve");} 2573 } 2574 dd_LPSolve(lpInt,solver,&err); This will not result in a point from the relative interior 2575 if (err!=dd_NoError){WerrorS("Error during dd_LPSolve");} 2576 2576 lpSol=dd_CopyLPSolution(lpInt); 2577 //if (err!=dd_NoError){WerrorS("Error during dd_CopyLPSolution");}2577 if (err!=dd_NoError){WerrorS("Error during dd_CopyLPSolution");} 2578 2578 #ifdef gfan_DEBUG 2579 2579 printf("Interior point: "); … … 2583 2583 } 2584 2584 printf("\n"); 2585 #endif 2586 //NOTE The following strongly resembles parts of makeInt.2587 //Maybe merge sometimes2585 #endif 2586 NOTE The following strongly resembles parts of makeInt. 2587 Maybe merge sometimes 2588 2588 mpz_t kgV; mpz_init(kgV); 2589 2589 mpz_set_str(kgV,"1",10); … … 2609 2609 } 2610 2610 #ifdef gfan_DEBUG 2611 //iv.show();2612 //cout << endl;2611 iv.show(); 2612 cout << endl; 2613 2613 #endif 2614 2614 mpq_clear(qkgV); 2615 2615 mpz_clear(tmp); 2616 2616 mpz_clear(den); 2617 mpz_clear(kgV); 2618 2617 mpz_clear(kgV); 2618 2619 2619 dd_FreeLPSolution(lpSol); 2620 2620 dd_FreeLPData(lpInt); 2621 2621 dd_FreeLPData(lp); 2622 //set_free(ddlinset);2623 // set_free(ddredrows); 2624 2625 } //void interiorPoint(dd_MatrixPtr const &M)2622 set_free(ddlinset); 2623 set_free(ddredrows); 2624 2625 }void interiorPoint(dd_MatrixPtr const &M) 2626 2626 2627 2627 /** Computes an interior point of a cone by taking two interior points a,b from two different facets 2628 2628 * and then computing b+(a-b)/2 2629 * Of course this only works for flippable facets 2630 * Two cases may occur: 2629 * Of course this only works for flippable facets 2630 * Two cases may occur: 2631 2631 * 1st: There are only two facets who share the only strictly positive ray 2632 2632 * 2nd: There are at least two facets which have a distinct positive ray … … 2637 2637 * positive => these lie in a plane and thus their sum is not from relative interior. 2638 2638 * So let's just sum up all rays, find one strictly positive and shift the point along that ray 2639 * 2639 * 2640 2640 * Used by noRevS 2641 2641 *NOTE no longer used nor maintained. MM Mar 9, 2010 2642 2642 */ 2643 //void gcone::interiorPoint2()2644 //{//idPrint(this->gcBasis);2645 //#ifdef gfan_DEBUG2646 //if(this->ivIntPt!=NULL)2647 //WarnS("Interior point already exists - ovrewriting!");2648 //#endif2649 //facet *f1 = this->facetPtr;2650 //facet *f2 = NULL;2651 //int64vec *intF1=NULL;2652 //while(f1!=NULL)2653 //{2654 //if(f1->isFlippable)2655 //{2656 //facet *f1Ray = f1->codim2Ptr;2657 //while(f1Ray!=NULL)2658 //{2659 //const int64vec *check=f1Ray->getRef2FacetNormal();2660 //if(iv64isStrictlyPositive(check))2661 //{2662 //intF1=iv64Copy(check);2663 //break;2664 // } 2665 //f1Ray=f1Ray->next;2666 //}2667 //}2668 //if(intF1!=NULL)2669 //break;2670 //f1=f1->next;2671 //}2672 //if(f1!=NULL && f1->next!=NULL)//Choose another facet, different from f12673 //f2=f1->next;2674 //else2675 //f2=this->facetPtr;2676 //if(intF1==NULL && hasHomInput==TRUE)2677 //{2678 //intF1 = new int64vec(this->numVars);2679 //for(int ii=0;ii<this->numVars;ii++)2680 //(*intF1)[ii]=1;2681 //}2682 //assert(f1); assert(f2);2683 //int64vec *intF2=f2->getInteriorPoint();2684 //mpq_t *qPosRay = new mpq_t[this->numVars];//The positive ray from above2685 //mpq_t *qIntPt = new mpq_t[this->numVars];//starting vector a+((b-a)/2)2686 //mpq_t *qPosIntPt = new mpq_t[this->numVars];//This should be >0 eventually2687 //for(int ii=0;ii<this->numVars;ii++)2688 //{2689 //mpq_init(qPosRay[ii]);2690 //mpq_init(qIntPt[ii]);2691 //mpq_init(qPosIntPt[ii]);2692 // } 2693 ////Compute a+((b-a)/2) && Convert intF1 to mpq2694 //for(int ii=0;ii<this->numVars;ii++)2695 //{2696 //mpq_t a,b;2697 //mpq_init(a); mpq_init(b);2698 //mpq_set_si(a,(*intF1)[ii],1);2699 //mpq_set_si(b,(*intF2)[ii],1);2700 //mpq_t diff;2701 //mpq_init(diff);2702 //mpq_sub(diff,b,a); //diff=b-a2703 //mpq_t quot;2704 //mpq_init(quot);2705 //mpq_div_2exp(quot,diff,1); //quot=diff/2=(b-a)/22706 //mpq_clear(diff);2707 ////Don't be clever and reuse diff here2708 //mpq_t sum; mpq_init(sum);2709 //mpq_add(sum,b,quot); //sum=b+quot=a+(b-a)/22710 //mpq_set(qIntPt[ii],sum);2711 //mpq_clear(sum);2712 //mpq_clear(quot);2713 //mpq_clear(a); mpq_clear(b);2714 ////Now for intF12715 //mpq_set_si(qPosRay[ii],(*intF1)[ii],1);2716 //}2717 ////Now add: qPosIntPt=qPosRay+qIntPt until qPosIntPt >02718 //while(TRUE)2719 // { 2720 //bool success=FALSE;2721 // int posCtr=0; 2722 //for(int ii=0;ii<this->numVars;ii++)2723 //{2724 //mpq_t sum; mpq_init(sum);2725 //mpq_add(sum,qPosRay[ii],qIntPt[ii]);2726 //mpq_set(qPosIntPt[ii],sum);2727 //mpq_clear(sum);2728 //if(mpq_sgn(qPosIntPt[ii])==1)2729 //posCtr++;2730 //}2731 // if(posCtr==this->numVars)//qPosIntPt > 0 2732 //break;2733 //else2734 //{2735 //mpq_t qTwo; mpq_init(qTwo);2736 //mpq_set_ui(qTwo,2,1);2737 //for(int jj=0;jj<this->numVars;jj++)2738 //{2739 //mpq_t tmp; mpq_init(tmp);2740 //mpq_mul(tmp,qPosRay[jj],qTwo);2741 //mpq_set( qPosRay[jj], tmp);2742 //mpq_clear(tmp);2743 //}2744 //mpq_clear(qTwo);2745 //}2746 //}//while2747 ////Now qPosIntPt ought to be >0, so convert back to int :D2748 ///*Compute lcm of the denominators*/2749 //mpz_t *denom = new mpz_t[this->numVars];2750 //mpz_t tmp,kgV;2751 //mpz_init(tmp); mpz_init(kgV);2752 //for (int ii=0;ii<this->numVars;ii++)2753 //{2754 //mpz_t z;2755 //mpz_init(z);2756 //mpq_get_den(z,qPosIntPt[ii]);2757 //mpz_init(denom[ii]);2758 //mpz_set( denom[ii], z);2759 // mpz_clear(z); 2760 //}2761 // 2762 //mpz_set(tmp,denom[0]);2763 //for (int ii=0;ii<this->numVars;ii++)2764 //{2765 //mpz_lcm(kgV,tmp,denom[ii]);2766 // mpz_set(tmp,kgV); 2767 //}2768 // mpz_clear(tmp); 2769 ///*Multiply the nominators by kgV*/2770 //mpq_t qkgV,res;2771 //mpq_init(qkgV);2772 // mpq_canonicalize(qkgV); 2773 //mpq_init(res);2774 //mpq_canonicalize(res);2775 // 2776 //mpq_set_num(qkgV,kgV);2777 //int64vec *n=new int64vec(this->numVars);2778 //for (int ii=0;ii<this->numVars;ii++)2779 //{2780 //mpq_canonicalize(qPosIntPt[ii]);2781 //mpq_mul(res,qkgV,qPosIntPt[ii]);2782 //(*n)[ii]=(int)mpz_get_d(mpq_numref(res));2783 //}2784 //this->setIntPoint(n);2785 //delete n;2786 //delete [] qPosIntPt;2787 //delete [] denom;2788 //delete [] qPosRay;2789 //delete [] qIntPt;2790 //mpz_clear(kgV);2791 //mpq_clear(qkgV); mpq_clear(res);2792 //}2793 2643 void gcone::interiorPoint2() 2644 {//idPrint(this->gcBasis); 2645 #ifdef gfan_DEBUG 2646 if(this->ivIntPt!=NULL) 2647 WarnS("Interior point already exists - ovrewriting!"); 2648 #endif 2649 facet *f1 = this->facetPtr; 2650 facet *f2 = NULL; 2651 int64vec *intF1=NULL; 2652 while(f1!=NULL) 2653 { 2654 if(f1->isFlippable) 2655 { 2656 facet *f1Ray = f1->codim2Ptr; 2657 while(f1Ray!=NULL) 2658 { 2659 const int64vec *check=f1Ray->getRef2FacetNormal(); 2660 if(iv64isStrictlyPositive(check)) 2661 { 2662 intF1=iv64Copy(check); 2663 break; 2664 } 2665 f1Ray=f1Ray->next; 2666 } 2667 } 2668 if(intF1!=NULL) 2669 break; 2670 f1=f1->next; 2671 } 2672 if(f1!=NULL && f1->next!=NULL)//Choose another facet, different from f1 2673 f2=f1->next; 2674 else 2675 f2=this->facetPtr; 2676 if(intF1==NULL && hasHomInput==TRUE) 2677 { 2678 intF1 = new int64vec(this->numVars); 2679 for(int ii=0;ii<this->numVars;ii++) 2680 (*intF1)[ii]=1; 2681 } 2682 assert(f1); assert(f2); 2683 int64vec *intF2=f2->getInteriorPoint(); 2684 mpq_t *qPosRay = new mpq_t[this->numVars];//The positive ray from above 2685 mpq_t *qIntPt = new mpq_t[this->numVars];//starting vector a+((b-a)/2) 2686 mpq_t *qPosIntPt = new mpq_t[this->numVars];//This should be >0 eventually 2687 for(int ii=0;ii<this->numVars;ii++) 2688 { 2689 mpq_init(qPosRay[ii]); 2690 mpq_init(qIntPt[ii]); 2691 mpq_init(qPosIntPt[ii]); 2692 } 2693 //Compute a+((b-a)/2) && Convert intF1 to mpq 2694 for(int ii=0;ii<this->numVars;ii++) 2695 { 2696 mpq_t a,b; 2697 mpq_init(a); mpq_init(b); 2698 mpq_set_si(a,(*intF1)[ii],1); 2699 mpq_set_si(b,(*intF2)[ii],1); 2700 mpq_t diff; 2701 mpq_init(diff); 2702 mpq_sub(diff,b,a); //diff=b-a 2703 mpq_t quot; 2704 mpq_init(quot); 2705 mpq_div_2exp(quot,diff,1); //quot=diff/2=(b-a)/2 2706 mpq_clear(diff); 2707 //Don't be clever and reuse diff here 2708 mpq_t sum; mpq_init(sum); 2709 mpq_add(sum,b,quot); //sum=b+quot=a+(b-a)/2 2710 mpq_set(qIntPt[ii],sum); 2711 mpq_clear(sum); 2712 mpq_clear(quot); 2713 mpq_clear(a); mpq_clear(b); 2714 //Now for intF1 2715 mpq_set_si(qPosRay[ii],(*intF1)[ii],1); 2716 } 2717 //Now add: qPosIntPt=qPosRay+qIntPt until qPosIntPt >0 2718 while(TRUE) 2719 { 2720 bool success=FALSE; 2721 int posCtr=0; 2722 for(int ii=0;ii<this->numVars;ii++) 2723 { 2724 mpq_t sum; mpq_init(sum); 2725 mpq_add(sum,qPosRay[ii],qIntPt[ii]); 2726 mpq_set(qPosIntPt[ii],sum); 2727 mpq_clear(sum); 2728 if(mpq_sgn(qPosIntPt[ii])==1) 2729 posCtr++; 2730 } 2731 if(posCtr==this->numVars)//qPosIntPt > 0 2732 break; 2733 else 2734 { 2735 mpq_t qTwo; mpq_init(qTwo); 2736 mpq_set_ui(qTwo,2,1); 2737 for(int jj=0;jj<this->numVars;jj++) 2738 { 2739 mpq_t tmp; mpq_init(tmp); 2740 mpq_mul(tmp,qPosRay[jj],qTwo); 2741 mpq_set( qPosRay[jj], tmp); 2742 mpq_clear(tmp); 2743 } 2744 mpq_clear(qTwo); 2745 } 2746 }//while 2747 //Now qPosIntPt ought to be >0, so convert back to int :D 2748 /*Compute lcm of the denominators*/ 2749 mpz_t *denom = new mpz_t[this->numVars]; 2750 mpz_t tmp,kgV; 2751 mpz_init(tmp); mpz_init(kgV); 2752 for (int ii=0;ii<this->numVars;ii++) 2753 { 2754 mpz_t z; 2755 mpz_init(z); 2756 mpq_get_den(z,qPosIntPt[ii]); 2757 mpz_init(denom[ii]); 2758 mpz_set( denom[ii], z); 2759 mpz_clear(z); 2760 } 2761 2762 mpz_set(tmp,denom[0]); 2763 for (int ii=0;ii<this->numVars;ii++) 2764 { 2765 mpz_lcm(kgV,tmp,denom[ii]); 2766 mpz_set(tmp,kgV); 2767 } 2768 mpz_clear(tmp); 2769 /*Multiply the nominators by kgV*/ 2770 mpq_t qkgV,res; 2771 mpq_init(qkgV); 2772 mpq_canonicalize(qkgV); 2773 mpq_init(res); 2774 mpq_canonicalize(res); 2775 2776 mpq_set_num(qkgV,kgV); 2777 int64vec *n=new int64vec(this->numVars); 2778 for (int ii=0;ii<this->numVars;ii++) 2779 { 2780 mpq_canonicalize(qPosIntPt[ii]); 2781 mpq_mul(res,qkgV,qPosIntPt[ii]); 2782 (*n)[ii]=(int)mpz_get_d(mpq_numref(res)); 2783 } 2784 this->setIntPoint(n); 2785 delete n; 2786 delete [] qPosIntPt; 2787 delete [] denom; 2788 delete [] qPosRay; 2789 delete [] qIntPt; 2790 mpz_clear(kgV); 2791 mpq_clear(qkgV); mpq_clear(res); 2792 } 2793 2794 2794 /** \brief Copy a ring and add a weighted ordering in first place 2795 * 2795 * 2796 2796 */ 2797 ring gcone::rCopyAndAddWeight(const ring &r, int64vec *ivw) 2797 ring gcone::rCopyAndAddWeight(const ring &r, int64vec *ivw) 2798 2798 { 2799 2799 ring res=rCopy0(r); 2800 2800 int jj; 2801 2801 2802 2802 omFree(res->order); 2803 2803 res->order =(int *)omAlloc0(4*sizeof(int/*64*/)); … … 2808 2808 omfree(res->wvhdl); 2809 2809 res->wvhdl =(int **)omAlloc0(4*sizeof(int/*64*/**)); 2810 2810 2811 2811 res->order[0]=ringorder_a/*64*/; 2812 2812 res->block0[0]=1; 2813 2813 res->block1[0]=res->N; 2814 res->order[1]=ringorder_dp; //basically useless, since that should never be used2814 res->order[1]=ringorder_dp; basically useless, since that should never be used 2815 2815 res->block0[1]=1; 2816 2816 res->block1[1]=res->N; … … 2820 2820 int/*64*/ *A=(int/*64*/ *)omAlloc0(length*sizeof(int/*64*/)); 2821 2821 for (jj=0;jj<length;jj++) 2822 { 2822 { 2823 2823 A[jj]=(*ivw)[jj]; 2824 2824 if((*ivw)[jj]>=INT_MAX) WarnS("A[jj] exceeds INT_MAX in gcone::rCopyAndAddWeight!\n"); 2825 } 2825 } 2826 2826 res->wvhdl[0]=(int *)A; 2827 2827 res->block1[0]=length; 2828 2828 2829 2829 rComplete(res); 2830 2830 return res; 2831 } //rCopyAndAdd2832 2833 ring gcone::rCopyAndAddWeight2(const ring &r,const int64vec *ivw, const int64vec *fNormal) 2831 }rCopyAndAdd 2832 2833 ring gcone::rCopyAndAddWeight2(const ring &r,const int64vec *ivw, const int64vec *fNormal) 2834 2834 { 2835 2835 ring res=rCopy0(r); 2836 2836 2837 2837 omFree(res->order); 2838 2838 res->order =(int *)omAlloc0(5*sizeof(int/*64*/)); … … 2843 2843 omfree(res->wvhdl); 2844 2844 res->wvhdl =(int **)omAlloc0(5*sizeof(int/*64*/**)); 2845 2845 2846 2846 res->order[0]=ringorder_a/*64*/; 2847 2847 res->block0[0]=1; … … 2850 2850 res->block0[1]=1; 2851 2851 res->block1[1]=res->N; 2852 2852 2853 2853 res->order[2]=ringorder_dp; 2854 2854 res->block0[2]=1; 2855 2855 res->block1[2]=res->N; 2856 2856 2857 2857 res->order[3]=ringorder_C; 2858 2858 … … 2861 2861 int/*64*/ *A2=(int/*64*/ *)omAlloc0(length*sizeof(int/*64*/)); 2862 2862 for (int jj=0;jj<length;jj++) 2863 { 2863 { 2864 2864 A1[jj]=(*ivw)[jj]; 2865 2865 A2[jj]=-(*fNormal)[jj]; 2866 2866 if((*ivw)[jj]>=INT_MAX || (*fNormal)[jj]>=INT_MAX) WarnS("A[jj] exceeds INT_MAX in gcone::rCopyAndAddWeight2!\n"); 2867 } 2867 } 2868 2868 res->wvhdl[0]=(int *)A1; 2869 2869 res->block1[0]=length; … … 2873 2873 return res; 2874 2874 } 2875 2876 //NOTE not needed anywhere2877 //ring rCopyAndChangeWeight(ring const &r, int64vec *ivw)2878 //{2879 //ring res=rCopy0(currRing);2880 //rComplete(res);2881 //rSetWeightVec(res,(int64*)ivw);2882 ////rChangeCurrRing(rnew);2883 //return res;2884 //}2885 2875 2876 NOTE not needed anywhere 2877 ring rCopyAndChangeWeight(ring const &r, int64vec *ivw) 2878 { 2879 ring res=rCopy0(currRing); 2880 rComplete(res); 2881 rSetWeightVec(res,(int64*)ivw); 2882 //rChangeCurrRing(rnew); 2883 return res; 2884 } 2885 2886 2886 /** \brief Checks whether a given facet is a search facet 2887 2887 * Determines whether a given facet of a cone is the search facet of a neighbouring cone … … 2890 2890 * that is first crossed during the generic walk. 2891 2891 * We then check whether the fNormal of this facet is parallel to the fNormal of our testfacet. 2892 * If this is the case, then our facet is indeed a search facet and TRUE is retuned. 2892 * If this is the case, then our facet is indeed a search facet and TRUE is retuned. 2893 2893 */ 2894 //removed with r122862895 2894 removed with r12286 2895 2896 2896 /** \brief Check for equality of two intvecs 2897 2897 */ … … 2909 2909 return res; 2910 2910 } 2911 2911 2912 2912 /** \brief The reverse search algorithm 2913 2913 */ 2914 //removed with r122862914 removed with r12286 2915 2915 /** \brief Compute the lineality/homogeneity space 2916 2916 * It is the kernel of the inequality matrix Ax=0 … … 2921 2921 dd_MatrixPtr res; 2922 2922 dd_MatrixPtr ddineq; 2923 ddineq=dd_CopyMatrix(this->ddFacets); 2924 //Add a row of 0s in 0th place2923 ddineq=dd_CopyMatrix(this->ddFacets); 2924 Add a row of 0s in 0th place 2925 2925 dd_MatrixPtr ddAppendRowOfZeroes=dd_CreateMatrix(1,this->numVars+1); 2926 2926 dd_MatrixPtr ddFoo=dd_AppendMatrix(ddAppendRowOfZeroes,ddineq); … … 2929 2929 ddineq=dd_CopyMatrix(ddFoo); 2930 2930 dd_FreeMatrix(ddFoo); 2931 //Cohen starts here2932 int dimKer=0; //Cohen calls this r2933 int m=ddineq->rowsize; //Rows2934 int n=ddineq->colsize; //Cols2931 Cohen starts here 2932 int dimKer=0;Cohen calls this r 2933 int m=ddineq->rowsize;Rows 2934 int n=ddineq->colsize;Cols 2935 2935 int c[m+1]; 2936 2936 int d[n+1]; … … 2938 2938 c[ii]=0; 2939 2939 for(int ii=0;ii<n;ii++) 2940 d[ii]=0; 2941 2940 d[ii]=0; 2941 2942 2942 for(int k=1;k<n;k++) 2943 2943 { 2944 //Let's find a j s.t. m[j][k]!=0 && c[j]=02945 int condCtr=0; //Check each row for zeroness2944 Let's find a j s.t. m[j][k]!=0 && c[j]=0 2945 int condCtr=0;Check each row for zeroness 2946 2946 for(int j=1;j<m;j++) 2947 2947 { … … 2955 2955 mpq_set(ratd,quot); 2956 2956 mpq_canonicalize(ratd); 2957 2957 2958 2958 mpq_set_str(ddineq->matrix[j][k],"-1",10); 2959 2959 for(int ss=k+1;ss<n;ss++) 2960 2960 { 2961 2961 mpq_t prod; mpq_init(prod); 2962 mpq_mul(prod, ratd, ddineq->matrix[j][ss]); 2962 mpq_mul(prod, ratd, ddineq->matrix[j][ss]); 2963 2963 mpq_set(ddineq->matrix[j][ss],prod); 2964 2964 mpq_canonicalize(ddineq->matrix[j][ss]); 2965 2965 mpq_clear(prod); 2966 } 2966 } 2967 2967 for(int ii=1;ii<m;ii++) 2968 2968 { … … 2970 2970 { 2971 2971 mpq_set(ratd,ddineq->matrix[ii][k]); 2972 mpq_set_str(ddineq->matrix[ii][k],"0",10); 2972 mpq_set_str(ddineq->matrix[ii][k],"0",10); 2973 2973 for(int ss=k+1;ss<n;ss++) 2974 2974 { … … 2984 2984 } 2985 2985 } 2986 c[j]=k; 2986 c[j]=k; 2987 2987 d[k]=j; 2988 mpq_clear(quot); mpq_clear(ratd); mpq_clear(one); 2988 mpq_clear(quot); mpq_clear(ratd); mpq_clear(one); 2989 2989 } 2990 2990 else 2991 2991 condCtr++; 2992 } 2993 if(condCtr==m-1) //Why -1 ???2992 } 2993 if(condCtr==m-1) Why -1 ??? 2994 2994 { 2995 2995 dimKer++; 2996 2996 d[k]=0; 2997 //break;//goto _4;2998 } //else{2997 break;//goto _4; 2998 }else{ 2999 2999 /*Eliminate*/ 3000 } //for(k3001 /*Output kernel, i.e. set gcone::dd_LinealitySpace here*/ 3002 //gcone::dd_LinealitySpace = dd_CreateMatrix(dimKer,this->numVars+1);3000 }for(k 3001 /*Output kernel, i.e. set gcone::dd_LinealitySpace here*/ 3002 gcone::dd_LinealitySpace = dd_CreateMatrix(dimKer,this->numVars+1); 3003 3003 res = dd_CreateMatrix(dimKer,this->numVars+1); 3004 3004 int row=-1; … … 3012 3012 if(d[ii]>0) 3013 3013 mpq_set(res->matrix[row][ii],ddineq->matrix[d[ii]][kk]); 3014 else if(ii==kk) 3014 else if(ii==kk) 3015 3015 mpq_set_str(res->matrix[row][ii],"1",10); 3016 3016 mpq_canonicalize(res->matrix[row][ii]); … … 3020 3020 dd_FreeMatrix(ddineq); 3021 3021 return(res); 3022 //Better safe than sorry:3023 //NOTE dd_LinealitySpace contains RATIONAL ENTRIES3024 //Therefore if you need integer ones: CALL gcone::makeInt(...) method3025 } 3022 Better safe than sorry: 3023 NOTE dd_LinealitySpace contains RATIONAL ENTRIES 3024 Therefore if you need integer ones: CALL gcone::makeInt(...) method 3025 } 3026 3026 3027 3027 … … 3034 3034 */ 3035 3035 void gcone::noRevS(gcone &gcRoot, bool usingIntPoint) 3036 { 3037 facet *SearchListRoot = new facet(); //The list containing ALL facets we come across3036 { 3037 facet *SearchListRoot = new facet(); The list containing ALL facets we come across 3038 3038 facet *SearchListAct; 3039 3039 SearchListAct = NULL; 3040 //SearchListAct = SearchListRoot;3040 SearchListAct = SearchListRoot; 3041 3041 gcone *gcAct; 3042 3042 gcAct = &gcRoot; 3043 gcone *gcPtr; //Pointer to end of linked list of cones3043 gcone *gcPtr; Pointer to end of linked list of cones 3044 3044 gcPtr = &gcRoot; 3045 gcone *gcNext; //Pointer to next cone to be visited3045 gcone *gcNext; Pointer to next cone to be visited 3046 3046 gcNext = &gcRoot; 3047 3047 gcone *gcHead; 3048 gcHead = &gcRoot; 3048 gcHead = &gcRoot; 3049 3049 facet *fAct; 3050 fAct = gcAct->facetPtr; 3050 fAct = gcAct->facetPtr; 3051 3051 ring rAct; 3052 3052 rAct = currRing; 3053 int UCNcounter=gcAct->getUCN(); 3053 int UCNcounter=gcAct->getUCN(); 3054 3054 #ifdef gfan_DEBUG 3055 3055 printf("NoRevs\n"); 3056 3056 printf("Facets are:\n"); 3057 3057 gcAct->showFacets(); 3058 #endif 3058 #endif 3059 3059 /*Compute lineality space here 3060 3060 * Afterwards static dd_MatrixPtr gcone::dd_LinealitySpace is set*/ 3061 3061 if(dd_LinealitySpace==NULL) 3062 3062 dd_LinealitySpace = gcAct->computeLinealitySpace(); 3063 /*End of lineality space computation*/ 3064 //gcAct->getCodim2Normals(*gcAct);3063 /*End of lineality space computation*/ 3064 gcAct->getCodim2Normals(*gcAct); 3065 3065 if(fAct->codim2Ptr==NULL) 3066 gcAct->getExtremalRays(*gcAct); 3066 gcAct->getExtremalRays(*gcAct); 3067 3067 /* Make a copy of the facet list of first cone 3068 3068 Since the operations getCodim2Normals and normalize affect the facets 3069 we must not memcpy them before these ops! */ 3070 /*facet *codim2Act; codim2Act = NULL; 3069 we must not memcpy them before these ops! */ 3070 /*facet *codim2Act; codim2Act = NULL; 3071 3071 facet *sl2Root; 3072 facet *sl2Act;*/ 3072 facet *sl2Act;*/ 3073 3073 for(int ii=0;ii<this->numFacets;ii++) 3074 3074 { 3075 //only copy flippable facets! NOTE: We do not need flipRing or any such information.3075 only copy flippable facets! NOTE: We do not need flipRing or any such information. 3076 3076 if(fAct->isFlippable==TRUE) 3077 3077 { 3078 3078 /*Using shallow copy here*/ 3079 3079 #ifdef SHALLOW 3080 if( ii==0 || (ii>0 && SearchListAct==NULL) ) //1st facet may be non-flippable3080 if( ii==0 || (ii>0 && SearchListAct==NULL) ) 1st facet may be non-flippable 3081 3081 { 3082 3082 if(SearchListRoot!=NULL) delete(SearchListRoot); 3083 3083 SearchListRoot = fAct->shallowCopy(*fAct); 3084 SearchListAct = SearchListRoot; //SearchListRoot is already 'new'ed at beginning of method!3084 SearchListAct = SearchListRoot; SearchListRoot is already 'new'ed at beginning of method! 3085 3085 } 3086 3086 else 3087 { 3087 { 3088 3088 SearchListAct->next = fAct->shallowCopy(*fAct); 3089 SearchListAct = SearchListAct->next; 3089 SearchListAct = SearchListAct->next; 3090 3090 } 3091 3091 fAct=fAct->next; … … 3094 3094 int64vec *fNormal; 3095 3095 fNormal = fAct->getFacetNormal(); 3096 if( ii==0 || (ii>0 && SearchListAct==NULL) ) //1st facet may be non-flippable3097 { 3098 SearchListAct = SearchListRoot; //SearchListRoot is already 'new'ed at beginning of method!3096 if( ii==0 || (ii>0 && SearchListAct==NULL) ) 1st facet may be non-flippable 3097 { 3098 SearchListAct = SearchListRoot; SearchListRoot is already 'new'ed at beginning of method! 3099 3099 } 3100 3100 else 3101 { 3101 { 3102 3102 SearchListAct->next = new facet(); 3103 SearchListAct = SearchListAct->next; 3103 SearchListAct = SearchListAct->next; 3104 3104 } 3105 3105 SearchListAct->setFacetNormal(fNormal); … … 3107 3107 SearchListAct->numCodim2Facets=fAct->numCodim2Facets; 3108 3108 SearchListAct->isFlippable=TRUE; 3109 //Copy int point as well3109 Copy int point as well 3110 3110 int64vec *ivIntPt; 3111 3111 ivIntPt = fAct->getInteriorPoint(); 3112 3112 SearchListAct->setInteriorPoint(ivIntPt); 3113 3113 delete(ivIntPt); 3114 //Copy codim2-facets3114 Copy codim2-facets 3115 3115 facet *codim2Act; 3116 codim2Act = NULL; 3116 codim2Act = NULL; 3117 3117 facet *sl2Root; 3118 facet *sl2Act; 3118 facet *sl2Act; 3119 3119 codim2Act=fAct->codim2Ptr; 3120 3120 SearchListAct->codim2Ptr = new facet(2); 3121 3121 sl2Root = SearchListAct->codim2Ptr; 3122 sl2Act = sl2Root; 3122 sl2Act = sl2Root; 3123 3123 for(int jj=0;jj<fAct->numCodim2Facets;jj++) 3124 //for(int jj=0;jj<fAct->numRays-1;jj++)3124 for(int jj=0;jj<fAct->numRays-1;jj++) 3125 3125 { 3126 3126 int64vec *f2Normal; 3127 3127 f2Normal = codim2Act->getFacetNormal(); 3128 3128 if(jj==0) 3129 { 3129 { 3130 3130 sl2Act = sl2Root; 3131 3131 sl2Act->setFacetNormal(f2Normal); … … 3137 3137 sl2Act->setFacetNormal(f2Normal); 3138 3138 } 3139 delete f2Normal; 3139 delete f2Normal; 3140 3140 codim2Act = codim2Act->next; 3141 3141 } … … 3143 3143 delete fNormal; 3144 3144 #endif 3145 } //if(fAct->isFlippable==TRUE)3145 }if(fAct->isFlippable==TRUE) 3146 3146 else {fAct = fAct->next;} 3147 } //End of copying facets into SLA3148 3149 SearchListAct = SearchListRoot; //Set to beginning of list3147 }End of copying facets into SLA 3148 3149 SearchListAct = SearchListRoot; Set to beginning of list 3150 3150 /*Make SearchList doubly linked*/ 3151 3151 #ifndef NDEBUG … … 3164 3164 if(SearchListAct->next!=NULL){ 3165 3165 #endif 3166 SearchListAct->next->prev = SearchListAct; 3166 SearchListAct->next->prev = SearchListAct; 3167 3167 } 3168 3168 SearchListAct = SearchListAct->next; 3169 3169 } 3170 SearchListAct = SearchListRoot; //Set to beginning of List3171 3172 //fAct = gcAct->facetPtr;//???3173 gcAct->writeConeToFile(*gcAct); 3170 SearchListAct = SearchListRoot; Set to beginning of List 3171 3172 fAct = gcAct->facetPtr;//??? 3173 gcAct->writeConeToFile(*gcAct); 3174 3174 /*End of initialisation*/ 3175 3175 3176 3176 fAct = SearchListAct; 3177 3177 /*2nd step 3178 3178 Choose a facet from SearchList, flip it and forget the previous cone 3179 3179 We always choose the first facet from SearchList as facet to be flipped 3180 */ 3181 while( (SearchListAct!=NULL)) //&& counter<490)3182 { //NOTE See to it that the cone is only changed after ALL facets have been flipped!3183 fAct = SearchListAct; 3180 */ 3181 while( (SearchListAct!=NULL))&& counter<490) 3182 {NOTE See to it that the cone is only changed after ALL facets have been flipped! 3183 fAct = SearchListAct; 3184 3184 while(fAct!=NULL) 3185 // while( (fAct->getUCN() == fAct->next->getUCN()) ) 3186 { //Since SLA should only contain flippables there should be no need to check for that3185 while( (fAct->getUCN() == fAct->next->getUCN()) ) 3186 { Since SLA should only contain flippables there should be no need to check for that 3187 3187 gcAct->flip2(gcAct->gcBasis,fAct); 3188 //NOTE rCopy needed?3188 NOTE rCopy needed? 3189 3189 ring rTmp=rCopy(fAct->flipRing); 3190 3190 rComplete(rTmp); 3191 3191 rChangeCurrRing(rTmp); 3192 gcone *gcTmp = new gcone::gcone(*gcAct,*fAct); //copy constructor!3192 gcone *gcTmp = new gcone::gcone(*gcAct,*fAct);copy constructor! 3193 3193 /* Now gcTmp->gcBasis and gcTmp->baseRing are set from fAct->flipGB and fAct->flipRing. 3194 3194 * Since we come at most once across a given facet from gcAct->facetPtr we can delete them. … … 3200 3200 */ 3201 3201 idDelete((ideal *)&fAct->flipGB); 3202 rDelete(fAct->flipRing); 3202 rDelete(fAct->flipRing); 3203 3203 gcTmp->getConeNormals(gcTmp->gcBasis/*, FALSE*/); 3204 //gcTmp->getCodim2Normals(*gcTmp);3204 gcTmp->getCodim2Normals(*gcTmp); 3205 3205 gcTmp->getExtremalRays(*gcTmp); 3206 //NOTE Order rays lex here3207 gcTmp->orderRays(); 3208 ////NOTE If flip2 is used we need to get an interior point of gcTmp3209 //// and replace gcTmp->baseRing with an appropriate ring with only3210 //// one weight3211 //gcTmp->interiorPoint2();3206 NOTE Order rays lex here 3207 gcTmp->orderRays(); 3208 //NOTE If flip2 is used we need to get an interior point of gcTmp 3209 // and replace gcTmp->baseRing with an appropriate ring with only 3210 // one weight 3211 gcTmp->interiorPoint2(); 3212 3212 gcTmp->replaceDouble_ringorder_a_ByASingleOne(); 3213 //gcTmp->ddFacets should not be needed anymore, so3213 gcTmp->ddFacets should not be needed anymore, so 3214 3214 dd_FreeMatrix(gcTmp->ddFacets); 3215 3215 #ifdef gfan_DEBUG 3216 //gcTmp->showFacets(1);3216 gcTmp->showFacets(1); 3217 3217 #endif 3218 3218 /*add facets to SLA here*/ … … 3228 3228 #endif 3229 3229 SearchListRoot=tmp; 3230 //SearchListRoot=gcTmp->enqueue2/*NewFacets*/(SearchListRoot);3231 #else 3230 SearchListRoot=gcTmp->enqueue2/*NewFacets*/(SearchListRoot); 3231 #else 3232 3232 SearchListRoot=gcTmp->enqueueNewFacets(SearchListRoot); 3233 #endif //ifdef SHALLOW3234 //gcTmp->writeConeToFile(*gcTmp);3233 #endif ifdef SHALLOW 3234 gcTmp->writeConeToFile(*gcTmp); 3235 3235 if(gfanHeuristic==1) 3236 3236 { 3237 3237 gcTmp->writeConeToFile(*gcTmp); 3238 idDelete((ideal*)&gcTmp->gcBasis); //Whonder why?3238 idDelete((ideal*)&gcTmp->gcBasis);Whonder why? 3239 3239 rDelete(gcTmp->baseRing); 3240 } 3240 } 3241 3241 #ifdef gfan_DEBUG 3242 3242 if(SearchListRoot!=NULL) 3243 3243 showSLA(*SearchListRoot); 3244 #endif 3244 #endif 3245 3245 rChangeCurrRing(gcAct->baseRing); 3246 3246 rDelete(rTmp); 3247 //doubly linked for easier removal3247 doubly linked for easier removal 3248 3248 gcTmp->prev = gcPtr; 3249 3249 gcPtr->next=gcTmp; 3250 3250 gcPtr=gcPtr->next; 3251 //Cleverly disguised exit condition follows3251 Cleverly disguised exit condition follows 3252 3252 if(fAct->getUCN() == fAct->next->getUCN()) 3253 3253 { 3254 3254 printf("Switching UCN from %i to %i\n",fAct->getUCN(),fAct->next->getUCN()); 3255 fAct=fAct->next; 3255 fAct=fAct->next; 3256 3256 } 3257 3257 else 3258 3258 { 3259 //rDelete(gcAct->baseRing);3260 //printf("break\n");3259 rDelete(gcAct->baseRing); 3260 printf("break\n"); 3261 3261 break; 3262 3262 } 3263 //fAct=fAct->next;3264 } //while( ( (fAct->next!=NULL) && (fAct->getUCN()==fAct->next->getUCN() ) ) );3265 //Search for cone with smallest UCN3263 fAct=fAct->next; 3264 }while( ( (fAct->next!=NULL) && (fAct->getUCN()==fAct->next->getUCN() ) ) ); 3265 Search for cone with smallest UCN 3266 3266 #ifndef NDEBUG 3267 #if SIZEOF_LONG==8 //64 bit3267 #if SIZEOF_LONG==8 64 bit 3268 3268 while(gcNext!=(gcone * const)0xfbfbfbfbfbfbfbfb && SearchListRoot!=NULL) 3269 3269 #elif SIZEOF_LONG == 4 … … 3272 3272 #endif 3273 3273 #ifdef NDEBUG 3274 while(gcNext!=NULL && SearchListRoot!=NULL) 3275 #endif 3276 { 3274 while(gcNext!=NULL && SearchListRoot!=NULL) 3275 #endif 3276 { 3277 3277 if( gcNext->getUCN() == SearchListRoot->getUCN() ) 3278 3278 { … … 3280 3280 { 3281 3281 gcAct = gcNext; 3282 //Seems better to not to use rCopy here3283 //rAct=rCopy(gcAct->baseRing);3282 Seems better to not to use rCopy here 3283 rAct=rCopy(gcAct->baseRing); 3284 3284 rAct=gcAct->baseRing; 3285 3285 rComplete(rAct); 3286 rChangeCurrRing(rAct); 3286 rChangeCurrRing(rAct); 3287 3287 break; 3288 3288 } … … 3290 3290 { 3291 3291 gcone *gcDel; 3292 gcDel = gcAct; 3292 gcDel = gcAct; 3293 3293 gcAct = gcNext; 3294 //Read st00f from file &3295 //implant the GB into gcAct3294 Read st00f from file & 3295 implant the GB into gcAct 3296 3296 readConeFromFile(gcAct->getUCN(), gcAct); 3297 //Kill the baseRing but ONLY if it is not the ring the computation started in!3298 //if(gcDel->getUCN()!=1)//WTF!? This causes the Mandelbug in gcone::areEqual(facet, facet)3299 //rDelete(gcDel->baseRing);3300 //rAct=rCopy(gcAct->baseRing);3301 /*The ring change occurs in readConeFromFile, so as to 3297 Kill the baseRing but ONLY if it is not the ring the computation started in! 3298 if(gcDel->getUCN()!=1)//WTF!? This causes the Mandelbug in gcone::areEqual(facet, facet) 3299 rDelete(gcDel->baseRing); 3300 rAct=rCopy(gcAct->baseRing); 3301 /*The ring change occurs in readConeFromFile, so as to 3302 3302 assure that gcAct->gcBasis belongs to the right ring*/ 3303 3303 rAct=gcAct->baseRing; … … 3305 3305 rChangeCurrRing(rAct); 3306 3306 break; 3307 } 3307 } 3308 3308 } 3309 3309 else if(gcNext->getUCN() < SearchListRoot->getUCN() ) 3310 3310 { 3311 idDelete( (ideal*)&gcNext->gcBasis ); 3312 //rDelete(gcNext->baseRing);//TODO Why does this crash?3311 idDelete( (ideal*)&gcNext->gcBasis ); 3312 rDelete(gcNext->baseRing);//TODO Why does this crash? 3313 3313 } 3314 3314 /*else … … 3320 3320 if(gcDel->getUCN()!=1) 3321 3321 rDelete(gcDel->baseRing); 3322 } 3323 }*/ 3322 } 3323 }*/ 3324 3324 gcNext = gcNext->next; 3325 3325 } 3326 3326 UCNcounter++; 3327 SearchListAct = SearchListRoot; 3327 SearchListAct = SearchListRoot; 3328 3328 } 3329 3329 printf("\nFound %i cones - terminating\n", counter); 3330 } //void noRevS(gcone &gc)3331 3332 3330 }void noRevS(gcone &gc) 3331 3332 3333 3333 /** \brief Make a set of rational vectors into integers 3334 3334 * … … 3339 3339 */ 3340 3340 void gcone::makeInt(const dd_MatrixPtr &M, const int line, int64vec &n) 3341 { 3341 { 3342 3342 mpz_t *denom = new mpz_t[this->numVars]; 3343 3343 for(int ii=0;ii<this->numVars;ii++) … … 3345 3345 mpz_init_set_str(denom[ii],"0",10); 3346 3346 } 3347 3347 3348 3348 mpz_t kgV,tmp; 3349 3349 mpz_init(kgV); 3350 3350 mpz_init(tmp); 3351 3351 3352 3352 for (int ii=0;ii<(M->colsize)-1;ii++) 3353 3353 { … … 3356 3356 mpq_get_den(z,M->matrix[line-1][ii+1]); 3357 3357 mpz_set( denom[ii], z); 3358 mpz_clear(z); 3359 } 3360 3358 mpz_clear(z); 3359 } 3360 3361 3361 /*Compute lcm of the denominators*/ 3362 3362 mpz_set(tmp,denom[0]); … … 3364 3364 { 3365 3365 mpz_lcm(kgV,tmp,denom[ii]); 3366 mpz_set(tmp,kgV); 3367 } 3368 mpz_clear(tmp); 3366 mpz_set(tmp,kgV); 3367 } 3368 mpz_clear(tmp); 3369 3369 /*Multiply the nominators by kgV*/ 3370 3370 mpq_t qkgV,res; … … 3372 3372 mpq_set_str(qkgV,"1",10); 3373 3373 mpq_canonicalize(qkgV); 3374 3374 3375 3375 mpq_init(res); 3376 3376 mpq_set_str(res,"1",10); 3377 3377 mpq_canonicalize(res); 3378 3378 3379 3379 mpq_set_num(qkgV,kgV); 3380 3381 //mpq_canonicalize(qkgV);3382 //int ggT=1;3380 3381 mpq_canonicalize(qkgV); 3382 int ggT=1; 3383 3383 for (int ii=0;ii<(M->colsize)-1;ii++) 3384 3384 { 3385 3385 mpq_mul(res,qkgV,M->matrix[line-1][ii+1]); 3386 3386 n[ii]=(int64)mpz_get_d(mpq_numref(res)); 3387 //ggT=int64gcd(ggT,n[ii]);3387 ggT=int64gcd(ggT,n[ii]); 3388 3388 } 3389 3389 int64 ggT=n[0]; 3390 3390 for(int ii=0;ii<this->numVars;ii++) 3391 ggT=int64gcd(ggT,n[ii]); 3392 //Normalisation3391 ggT=int64gcd(ggT,n[ii]); 3392 Normalisation 3393 3393 if(ggT>1) 3394 3394 { … … 3398 3398 delete [] denom; 3399 3399 mpz_clear(kgV); 3400 mpq_clear(qkgV); mpq_clear(res); 3401 3400 mpq_clear(qkgV); mpq_clear(res); 3401 3402 3402 } 3403 3403 /** 3404 * For all codim-2-facets we compute the gcd of the components of the facet normal and 3404 * For all codim-2-facets we compute the gcd of the components of the facet normal and 3405 3405 * divide it out. Thus we get a normalized representation of each 3406 3406 * (codim-2)-facet normal, i.e. a primitive vector 3407 3407 * Actually we now also normalize the facet normals. 3408 3408 */ 3409 //void gcone::normalize()3410 //{3411 //int *ggT = new int;3412 //*ggT=1;3413 //facet *fAct;3414 //facet *codim2Act;3415 //fAct = this->facetPtr;3416 //codim2Act = fAct->codim2Ptr;3417 //while(fAct!=NULL)3418 //{3419 //int64vec *fNormal;3420 //fNormal = fAct->getFacetNormal();3421 //int *ggT = new int;3422 //*ggT=1;3423 //for(int ii=0;ii<this->numVars;ii++)3424 //{3425 //*ggT=intgcd((*ggT),(*fNormal)[ii]);3426 //}3427 //if(*ggT>1)//We only need to do this if the ggT is non-trivial3428 //{3429 //// int64vec *fCopy = fAct->getFacetNormal();3430 //for(int ii=0;ii<this->numVars;ii++)3431 //(*fNormal)[ii] = ((*fNormal)[ii])/(*ggT);3432 //fAct->setFacetNormal(fNormal);3433 // } 3434 //delete fNormal;3435 //delete ggT;3436 ///*And now for the codim2*/3437 //while(codim2Act!=NULL)3438 // { 3439 //int64vec *n;3440 //n=codim2Act->getFacetNormal();3441 //int *ggT=new int;3442 //*ggT=1;3443 //for(int ii=0;ii<this->numVars;ii++)3444 //{3445 //*ggT = intgcd((*ggT),(*n)[ii]);3446 //}3447 //if(*ggT>1)3448 //{3449 //for(int ii=0;ii<this->numVars;ii++)3450 //{3451 //(*n)[ii] = ((*n)[ii])/(*ggT);3452 //}3453 //codim2Act->setFacetNormal(n);3454 //}3455 //codim2Act = codim2Act->next;3456 //delete n;3457 //delete ggT;3458 //}3459 //fAct = fAct->next;3460 //}3461 //}3462 3463 /** \brief Enqueue new facets into the searchlist 3409 void gcone::normalize() 3410 { 3411 int *ggT = new int; 3412 *ggT=1; 3413 facet *fAct; 3414 facet *codim2Act; 3415 fAct = this->facetPtr; 3416 codim2Act = fAct->codim2Ptr; 3417 while(fAct!=NULL) 3418 { 3419 int64vec *fNormal; 3420 fNormal = fAct->getFacetNormal(); 3421 int *ggT = new int; 3422 *ggT=1; 3423 for(int ii=0;ii<this->numVars;ii++) 3424 { 3425 *ggT=intgcd((*ggT),(*fNormal)[ii]); 3426 } 3427 if(*ggT>1)//We only need to do this if the ggT is non-trivial 3428 { 3429 // int64vec *fCopy = fAct->getFacetNormal(); 3430 for(int ii=0;ii<this->numVars;ii++) 3431 (*fNormal)[ii] = ((*fNormal)[ii])/(*ggT); 3432 fAct->setFacetNormal(fNormal); 3433 } 3434 delete fNormal; 3435 delete ggT; 3436 /*And now for the codim2*/ 3437 while(codim2Act!=NULL) 3438 { 3439 int64vec *n; 3440 n=codim2Act->getFacetNormal(); 3441 int *ggT=new int; 3442 *ggT=1; 3443 for(int ii=0;ii<this->numVars;ii++) 3444 { 3445 *ggT = intgcd((*ggT),(*n)[ii]); 3446 } 3447 if(*ggT>1) 3448 { 3449 for(int ii=0;ii<this->numVars;ii++) 3450 { 3451 (*n)[ii] = ((*n)[ii])/(*ggT); 3452 } 3453 codim2Act->setFacetNormal(n); 3454 } 3455 codim2Act = codim2Act->next; 3456 delete n; 3457 delete ggT; 3458 } 3459 fAct = fAct->next; 3460 } 3461 } 3462 3463 /** \brief Enqueue new facets into the searchlist 3464 3464 * The searchlist (SLA for short) is implemented as a FIFO 3465 3465 * Checks are done as follows: 3466 3466 * 1) Check facet fAct against all facets in SLA for parallelity. If it is not parallel to any one add it. 3467 * 2) If it is parallel compare the codim2 facets. If they coincide the facets are equal and we delete the 3467 * 2) If it is parallel compare the codim2 facets. If they coincide the facets are equal and we delete the 3468 3468 * facet from SLA and do not add fAct. 3469 3469 * It may very well happen, that SLA=\f$ \emptyset \f$ but we do not have checked all fActs yet. In this case we … … 3480 3480 facet *slHead; 3481 3481 slHead = f; 3482 facet *slAct; //called with f=SearchListRoot3482 facet *slAct; called with f=SearchListRoot 3483 3483 slAct = f; 3484 facet *slEnd; //Pointer to end of SLA3484 facet *slEnd; Pointer to end of SLA 3485 3485 slEnd = f; 3486 // facet *slEndStatic; //marks the end before a new facet is added 3486 facet *slEndStatic; //marks the end before a new facet is added 3487 3487 facet *fAct; 3488 3488 fAct = this->facetPtr; … … 3494 3494 volatile facet *deleteMarker; 3495 3495 deleteMarker = NULL; 3496 3496 3497 3497 /** \brief Flag to mark a facet that might be added 3498 3498 * The following case may occur: … … 3500 3500 * This does however not mean that there does not exist a facet behind the current slAct that is actually equal 3501 3501 * to fAct. In this case we set the boolean flag maybe to TRUE. If we encounter an equality lateron, it is reset to 3502 * FALSE and the according slAct is deleted. 3502 * FALSE and the according slAct is deleted. 3503 3503 * If slAct->next==NULL AND maybe==TRUE we know, that fAct must be added 3504 3504 */ 3505 3505 3506 /**A facet was removed, lengthOfSearchlist-- thus we must not rely on 3506 /**A facet was removed, lengthOfSearchlist-- thus we must not rely on 3507 3507 * if(notParallelCtr==lengthOfSearchList) but rather 3508 3508 * if( (notParallelCtr==lengthOfSearchList && removalOccured==FALSE) … … 3513 3513 slEnd=slEnd->next; 3514 3514 } 3515 /*1st step: compare facetNormals*/ 3515 /*1st step: compare facetNormals*/ 3516 3516 while(fAct!=NULL) 3517 { 3517 { 3518 3518 if(fAct->isFlippable==TRUE) 3519 3519 { 3520 3520 int64vec *fNormal=NULL; 3521 fNormal=fAct->getFacetNormal(); 3521 fNormal=fAct->getFacetNormal(); 3522 3522 slAct = slHead; 3523 /*If slAct==NULL and fAct!=NULL 3523 /*If slAct==NULL and fAct!=NULL 3524 3524 we just copy all remaining facets into SLA*/ 3525 3525 if(slAct==NULL) … … 3529 3529 while(fCopy!=NULL) 3530 3530 { 3531 if(fCopy->isFlippable==TRUE) //We must assure fCopy is also flippable3531 if(fCopy->isFlippable==TRUE)We must assure fCopy is also flippable 3532 3532 { 3533 3533 if(slAct==NULL) 3534 3534 { 3535 slAct = new facet(*fCopy/*,TRUE*/); //copy constructor3536 slHead = slAct; 3535 slAct = new facet(*fCopy/*,TRUE*/);copy constructor 3536 slHead = slAct; 3537 3537 } 3538 3538 else … … 3544 3544 fCopy = fCopy->next; 3545 3545 } 3546 break; //Where does this lead to?3546 break;Where does this lead to? 3547 3547 } 3548 3548 /*End of dumping into SLA*/ … … 3554 3554 #ifdef gfan_DEBUG 3555 3555 printf("Checking facet (");fNormal->show(1,1);printf(") against (");slNormal->show(1,1);printf(")\n"); 3556 #endif 3557 //if( (areEqual(fAct,slAct) && (!areEqual2(fAct,slAct)) ))3558 //exit(-1);3556 #endif 3557 if( (areEqual(fAct,slAct) && (!areEqual2(fAct,slAct)) )) 3558 exit(-1); 3559 3559 if(areEqual2(fAct,slAct)) 3560 { 3560 { 3561 3561 deleteMarker = slAct; 3562 3562 if(slAct==slHead) 3563 { 3564 slHead = slAct->next; 3563 { 3564 slHead = slAct->next; 3565 3565 if(slHead!=NULL) 3566 3566 slHead->prev = NULL; … … 3570 3570 slEnd=slEnd->prev; 3571 3571 slEnd->next = NULL; 3572 } 3572 } 3573 3573 else 3574 3574 { … … 3580 3580 if(deleteMarker!=NULL) 3581 3581 { 3582 //delete deleteMarker;3583 //deleteMarker=NULL;3582 delete deleteMarker; 3583 deleteMarker=NULL; 3584 3584 } 3585 3585 #ifdef gfan_DEBUG … … 3587 3587 #endif 3588 3588 delete slNormal; 3589 break; //leave the while loop, since we found fAct=slAct thus delete slAct and do not add fAct3589 break;leave the while loop, since we found fAct=slAct thus delete slAct and do not add fAct 3590 3590 } 3591 3591 slAct = slAct->next; … … 3596 3596 slAct = slAct->next;*/ 3597 3597 if(deleteMarker!=NULL) 3598 { 3599 //delete deleteMarker;3600 //deleteMarker=NULL;3598 { 3599 delete deleteMarker; 3600 deleteMarker=NULL; 3601 3601 } 3602 3602 delete slNormal; 3603 //if slAct was marked as to be deleted, delete it here!3604 } //while(slAct!=NULL)3603 if slAct was marked as to be deleted, delete it here! 3604 }while(slAct!=NULL) 3605 3605 if(removalOccured==FALSE) 3606 3606 { 3607 3607 #ifdef gfan_DEBUG 3608 //cout << "Adding facet (";fNormal->show(1,0);cout << ") to SLA " << endl;3609 #endif 3610 //Add fAct to SLA3608 cout << "Adding facet (";fNormal->show(1,0);cout << ") to SLA " << endl; 3609 #endif 3610 Add fAct to SLA 3611 3611 facet *marker; 3612 3612 marker = slEnd; … … 3615 3615 3616 3616 slEnd->next = new facet(); 3617 slEnd = slEnd->next; //Update slEnd3617 slEnd = slEnd->next;Update slEnd 3618 3618 facet *slEndCodim2Root; 3619 3619 facet *slEndCodim2Act; 3620 3620 slEndCodim2Root = slEnd->codim2Ptr; 3621 3621 slEndCodim2Act = slEndCodim2Root; 3622 3622 3623 3623 slEnd->setUCN(this->getUCN()); 3624 3624 slEnd->isFlippable = TRUE; 3625 3625 slEnd->setFacetNormal(fNormal); 3626 //NOTE Add interior point here3627 //This is ugly but needed for flip23628 //Better: have slEnd->interiorPoint point to fAct->interiorPoint3629 //NOTE Only reference -> c.f. copy constructor3630 //slEnd->setInteriorPoint(fAct->getInteriorPoint());3626 NOTE Add interior point here 3627 This is ugly but needed for flip2 3628 Better: have slEnd->interiorPoint point to fAct->interiorPoint 3629 NOTE Only reference -> c.f. copy constructor 3630 slEnd->setInteriorPoint(fAct->getInteriorPoint()); 3631 3631 slEnd->interiorPoint = fAct->interiorPoint; 3632 3632 slEnd->prev = marker; 3633 //Copy codim2-facets3634 //int64vec *f2Normal=new int64vec(this->numVars);3633 Copy codim2-facets 3634 int64vec *f2Normal=new int64vec(this->numVars); 3635 3635 while(f2Act!=NULL) 3636 3636 { … … 3640 3640 { 3641 3641 slEndCodim2Root = new facet(2); 3642 slEnd->codim2Ptr = slEndCodim2Root; 3642 slEnd->codim2Ptr = slEndCodim2Root; 3643 3643 slEndCodim2Root->setFacetNormal(f2Normal); 3644 3644 slEndCodim2Act = slEndCodim2Root; 3645 3645 } 3646 else 3646 else 3647 3647 { 3648 3648 slEndCodim2Act->next = new facet(2); … … 3653 3653 delete f2Normal; 3654 3654 } 3655 gcone::lengthOfSearchList++; 3656 } //if( (notParallelCtr==lengthOfSearchList && removalOccured==FALSE) ||3655 gcone::lengthOfSearchList++; 3656 }if( (notParallelCtr==lengthOfSearchList && removalOccured==FALSE) || 3657 3657 fAct = fAct->next; 3658 3658 delete fNormal; 3659 //delete slNormal;3660 } //if(fAct->isFlippable==TRUE)3659 delete slNormal; 3660 }if(fAct->isFlippable==TRUE) 3661 3661 else 3662 3662 { … … 3665 3665 if(gcone::maxSize<gcone::lengthOfSearchList) 3666 3666 gcone::maxSize= gcone::lengthOfSearchList; 3667 } //while(fAct!=NULL)3667 }while(fAct!=NULL) 3668 3668 #ifdef gfanp 3669 3669 gettimeofday(&end, 0); 3670 3670 time_enqueue += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec)); 3671 #endif 3671 #endif 3672 3672 return slHead; 3673 } //addC2N3673 }addC2N 3674 3674 3675 3675 /** Enqueuing using shallow copies*/ … … 3683 3683 facet *slHead; 3684 3684 slHead = f; 3685 facet *slAct; //called with f=SearchListRoot3685 facet *slAct; called with f=SearchListRoot 3686 3686 slAct = f; 3687 static facet *slEnd; //Pointer to end of SLA3687 static facet *slEnd; Pointer to end of SLA 3688 3688 if(slEnd==NULL) 3689 3689 slEnd = f; 3690 3690 3691 3691 facet *fAct; 3692 fAct = this->facetPtr; //New facets to compare3692 fAct = this->facetPtr;New facets to compare 3693 3693 facet *codim2Act; 3694 3694 codim2Act = this->facetPtr->codim2Ptr; … … 3697 3697 { 3698 3698 slEnd=slEnd->next; 3699 } 3699 } 3700 3700 while(fAct!=NULL) 3701 3701 { … … 3708 3708 printf("Zero length SLA\n"); 3709 3709 facet *fCopy; 3710 fCopy = fAct; 3710 fCopy = fAct; 3711 3711 while(fCopy!=NULL) 3712 3712 { 3713 if(fCopy->isFlippable==TRUE) //We must assure fCopy is also flippable3713 if(fCopy->isFlippable==TRUE)We must assure fCopy is also flippable 3714 3714 { 3715 3715 if(slAct==NULL) 3716 3716 { 3717 slAct = slAct->shallowCopy(*fCopy); //shallow copy constructor3718 slHead = slAct; 3717 slAct = slAct->shallowCopy(*fCopy);shallow copy constructor 3718 slHead = slAct; 3719 3719 } 3720 3720 else … … 3726 3726 fCopy = fCopy->next; 3727 3727 } 3728 break; //WTF?3728 break; WTF? 3729 3729 } 3730 3730 /*Comparison starts here*/ … … 3734 3734 #ifdef gfan_DEBUG 3735 3735 printf("Checking facet (");fAct->fNormal->show(1,1);printf(") against (");slAct->fNormal->show(1,1);printf(")\n"); 3736 #endif 3736 #endif 3737 3737 if(areEqual2(fAct,slAct)) 3738 3738 { … … 3740 3740 if(slAct==slHead) 3741 3741 { 3742 //fDeleteMarker=slHead;3743 //printf("headUCN@enq=%i\n",slHead->getUCN());3744 slHead = slAct->next; 3745 //printf("headUCN@enq=%i\n",slHead->getUCN());3742 fDeleteMarker=slHead; 3743 printf("headUCN@enq=%i\n",slHead->getUCN()); 3744 slHead = slAct->next; 3745 printf("headUCN@enq=%i\n",slHead->getUCN()); 3746 3746 if(slHead!=NULL) 3747 3747 { … … 3749 3749 } 3750 3750 fDeleteMarker->shallowDelete(); 3751 //delete fDeleteMarker;//NOTE this messes up fAct in noRevS!3752 //printf("headUCN@enq=%i\n",slHead->getUCN());3751 delete fDeleteMarker;//NOTE this messes up fAct in noRevS! 3752 printf("headUCN@enq=%i\n",slHead->getUCN()); 3753 3753 } 3754 3754 else if (slAct==slEnd) … … 3758 3758 fDeleteMarker->shallowDelete(); 3759 3759 delete(fDeleteMarker); 3760 } 3760 } 3761 3761 else 3762 3762 { … … 3771 3771 printf("Removing (");fAct->fNormal->show(1,1);printf(") from list\n"); 3772 3772 #endif 3773 break; //leave the while loop, since we found fAct=slAct thus delete slAct and do not add fAct3773 break;leave the while loop, since we found fAct=slAct thus delete slAct and do not add fAct 3774 3774 } 3775 slAct = slAct->next; 3776 } //while(slAct!=NULL)3775 slAct = slAct->next; 3776 }while(slAct!=NULL) 3777 3777 if(removalOccured==FALSE) 3778 3778 { … … 3784 3784 } 3785 3785 fAct = fAct->next; 3786 //if(fDeleteMarker!=NULL)3787 //{3788 //fDeleteMarker->shallowDelete();3789 //delete(fDeleteMarker);3790 //fDeleteMarker=NULL;3791 //}3786 if(fDeleteMarker!=NULL) 3787 { 3788 fDeleteMarker->shallowDelete(); 3789 delete(fDeleteMarker); 3790 fDeleteMarker=NULL; 3791 } 3792 3792 } 3793 3793 else 3794 3794 fAct = fAct->next; 3795 } //while(fAct!=NULL)3796 3795 }while(fAct!=NULL) 3796 3797 3797 #ifdef gfanp 3798 3798 gettimeofday(&end, 0); 3799 3799 time_enqueue += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec)); 3800 #endif 3801 //printf("headUCN@enq=%i\n",slHead->getUCN());3800 #endif 3801 printf("headUCN@enq=%i\n",slHead->getUCN()); 3802 3802 return slHead; 3803 3803 } 3804 3804 3805 /** 3805 /** 3806 3806 * During flip2 every gc->baseRing gets two ringorder_a 3807 3807 * To avoid having an awful lot of those in the end we endow … … 3824 3824 omfree(replacementRing->wvhdl); 3825 3825 replacementRing->wvhdl =(int **)omAlloc0(4*sizeof(int/*64*/**)); 3826 3826 3827 3827 replacementRing->order[0]=ringorder_a/*64*/; 3828 3828 replacementRing->block0[0]=1; 3829 3829 replacementRing->block1[0]=replacementRing->N; 3830 3830 3831 3831 replacementRing->order[1]=ringorder_dp; 3832 3832 replacementRing->block0[1]=1; 3833 3833 replacementRing->block1[1]=replacementRing->N; 3834 3834 3835 3835 replacementRing->order[2]=ringorder_C; 3836 3836 3837 int64vec *ivw = this->getIntPoint(TRUE); //returns a reference3838 // assert(this->ivIntPt); 3839 int length=ivw->length(); 3837 int64vec *ivw = this->getIntPoint(TRUE);returns a reference 3838 assert(this->ivIntPt); 3839 int length=ivw->length(); 3840 3840 int/*64*/ *A=(int/*64*/ *)omAlloc0(length*sizeof(int/*64*/)); 3841 3841 for (int jj=0;jj<length;jj++) … … 3843 3843 A[jj]=(*ivw)[jj]; 3844 3844 if((*ivw)[jj]>=INT_MAX) WarnS("A[jj] exceeds INT_MAX in gcone::replaceDouble_ringorder_a_ByASingleOne!\n"); 3845 } 3846 //delete ivw; //Not needed if this->getIntPoint(TRUE)3845 } 3846 delete ivw; //Not needed if this->getIntPoint(TRUE) 3847 3847 replacementRing->wvhdl[0]=(int *)A; 3848 3848 replacementRing->block1[0]=length; … … 3853 3853 rDelete(this->baseRing); 3854 3854 this->baseRing=rCopy(replacementRing); 3855 this->gcBasis=idCopy(temporaryGroebnerBasis); 3855 this->gcBasis=idCopy(temporaryGroebnerBasis); 3856 3856 /*And back to where we came from*/ 3857 3857 rChangeCurrRing(srcRing); 3858 3858 idDelete( (ideal*)&temporaryGroebnerBasis ); 3859 rDelete(replacementRing); 3859 rDelete(replacementRing); 3860 3860 } 3861 3861 … … 3877 3877 return p; 3878 3878 } 3879 3879 3880 3880 /** \brief Construct a dd_MatrixPtr from a cone's list of facets 3881 3881 * NO LONGER USED 3882 3882 */ 3883 //inline dd_MatrixPtr gcone::facets2Matrix(const gcone &gc)3884 //{3885 //facet *fAct;3886 //fAct = gc.facetPtr;3887 // 3888 //dd_MatrixPtr M;3889 //dd_rowrange ddrows;3890 //dd_colrange ddcols;3891 //ddcols=(this->numVars)+1;3892 //ddrows=this->numFacets;3893 //dd_NumberType numb = dd_Integer;3894 // M=dd_CreateMatrix(ddrows,ddcols); 3895 // 3896 //int jj=0;3897 // 3898 //while(fAct!=NULL)3899 //{3900 //int64vec *comp;3901 //comp = fAct->getFacetNormal();3902 //for(int ii=0;ii<this->numVars;ii++)3903 //{3904 //dd_set_si(M->matrix[jj][ii+1],(*comp)[ii]);3905 //}3906 //jj++;3907 //delete comp;3908 // fAct=fAct->next; 3909 // } 3910 //return M;3911 //}3912 3883 inline dd_MatrixPtr gcone::facets2Matrix(const gcone &gc) 3884 { 3885 facet *fAct; 3886 fAct = gc.facetPtr; 3887 3888 dd_MatrixPtr M; 3889 dd_rowrange ddrows; 3890 dd_colrange ddcols; 3891 ddcols=(this->numVars)+1; 3892 ddrows=this->numFacets; 3893 dd_NumberType numb = dd_Integer; 3894 M=dd_CreateMatrix(ddrows,ddcols); 3895 3896 int jj=0; 3897 3898 while(fAct!=NULL) 3899 { 3900 int64vec *comp; 3901 comp = fAct->getFacetNormal(); 3902 for(int ii=0;ii<this->numVars;ii++) 3903 { 3904 dd_set_si(M->matrix[jj][ii+1],(*comp)[ii]); 3905 } 3906 jj++; 3907 delete comp; 3908 fAct=fAct->next; 3909 } 3910 return M; 3911 } 3912 3913 3913 /** \brief Write information about a cone into a file on disk 3914 3914 * … … 3926 3926 stringstream ss; 3927 3927 ss << UCN; 3928 string UCNstr = ss.str(); 3929 3928 string UCNstr = ss.str(); 3929 3930 3930 string prefix="/tmp/Singular/cone"; 3931 //string prefix="./"; //crude hack -> run tests in separate directories3931 string prefix="./"; //crude hack -> run tests in separate directories 3932 3932 string suffix=".sg"; 3933 3933 string filename; … … 3935 3935 filename.append(UCNstr); 3936 3936 filename.append(suffix); 3937 3938 //int thisPID = getpid();3939 //ss << thisPID;3940 //string strPID = ss.str();3941 //string prefix="./";3942 3937 3938 int thisPID = getpid(); 3939 ss << thisPID; 3940 string strPID = ss.str(); 3941 string prefix="./"; 3942 3943 3943 ofstream gcOutputFile(filename.c_str()); 3944 3944 assert(gcOutputFile); 3945 3945 facet *fAct; 3946 fAct = gc.facetPtr; 3946 fAct = gc.facetPtr; 3947 3947 facet *f2Act; 3948 3948 f2Act=fAct->codim2Ptr; 3949 3949 3950 3950 char *ringString = rString(gc.baseRing); 3951 3951 3952 3952 if (!gcOutputFile) 3953 3953 { … … 3955 3955 } 3956 3956 else 3957 { 3957 { 3958 3958 gcOutputFile << "UCN" << endl; 3959 3959 gcOutputFile << this->UCN << endl; 3960 gcOutputFile << "RING" << endl; 3960 gcOutputFile << "RING" << endl; 3961 3961 gcOutputFile << ringString << endl; 3962 3962 gcOutputFile << "GCBASISLENGTH" << endl; 3963 gcOutputFile << IDELEMS(gc.gcBasis) << endl; 3964 //Write this->gcBasis into file3965 gcOutputFile << "GCBASIS" << endl; 3963 gcOutputFile << IDELEMS(gc.gcBasis) << endl; 3964 Write this->gcBasis into file 3965 gcOutputFile << "GCBASIS" << endl; 3966 3966 for (int ii=0;ii<IDELEMS(gc.gcBasis);ii++) 3967 { 3967 { 3968 3968 gcOutputFile << p_String((poly)gc.gcBasis->m[ii],gc.baseRing) << endl; 3969 } 3970 3971 gcOutputFile << "FACETS" << endl; 3972 3969 } 3970 3971 gcOutputFile << "FACETS" << endl; 3972 3973 3973 while(fAct!=NULL) 3974 { 3974 { 3975 3975 const int64vec *iv=fAct->getRef2FacetNormal(); 3976 //iv=fAct->getRef2FacetNormal();//->getFacetNormal();3976 iv=fAct->getRef2FacetNormal();//->getFacetNormal(); 3977 3977 f2Act=fAct->codim2Ptr; 3978 3978 for (int ii=0;ii<iv->length();ii++) 3979 3979 { 3980 //if (ii<iv->length()-1)3981 //gcOutputFile << (*iv)[ii] << ",";3982 //else3983 //gcOutputFile << (*iv)[ii] << " ";3980 if (ii<iv->length()-1) 3981 gcOutputFile << (*iv)[ii] << ","; 3982 else 3983 gcOutputFile << (*iv)[ii] << " "; 3984 3984 gcOutputFile << (*iv)[ii]; 3985 3985 (ii<iv->length()-1) ? gcOutputFile << "," : gcOutputFile << " "; 3986 3986 } 3987 //delete iv;3987 delete iv; 3988 3988 while(f2Act!=NULL) 3989 3989 { … … 3992 3992 for(int jj=0;jj<iv2->length();jj++) 3993 3993 {