Changeset 87d8d5 in git


Ignore:
Timestamp:
Mar 16, 2011, 8:05:04 PM (12 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
a513d10db695283b0b6578322ae02304f8cf82d2
Parents:
950214e56df8e233d791b1abc2c8674661d285d0
Message:
format

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

Legend:

Unmodified
Added
Removed
  • kernel/gfan.cc

    r950214e r87d8d5  
    1313#include <kernel/kstd1.h>
    1414#include <kernel/kutil.h>
    15 // #include "int64vec.h"
     15 #include "int64vec.h"
    1616#include <kernel/polys.h>
    1717#include <kernel/ideals.h>
    1818#include <kernel/kmatrix.h>
    1919#include <kernel/GMPrat.h>
    20 //#include "fast_maps.h"        //Mapping of ideals
    21 // #include "maps.h"
    22 #include "ring.h"       //apparently not needed
    23 // #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"
    2424#include <Singular/lists.h>
    2525#include <kernel/prCopy.h>
    2626#include <kernel/stairc.h>
    27 // #include <bitset>
    28 #include <fstream>      //read-write cones to files
    29 // #include <gmp.h>
     27 #include <bitset>
     28#include <fstream>      read-write cones to files
     29 #include <gmp.h>
    3030#include <string>
    3131#include <sstream>
    32 // #include <time.h>
     32 #include <time.h>
    3333#include <stdlib.h>
    34 //#include <gmpxx.h>
    35 // #include <vector>
     34#include <gmpxx.h>
     35 #include <vector>
    3636#include <assert.h>
    3737
     
    4242#endif
    4343
    44 //Hacks for different working places
     44Hacks for different working places
    4545#define p800
    4646
     
    6868
    6969#ifndef gfan_DEBUG
    70 // #define gfan_DEBUG
     70 #define gfan_DEBUG
    7171#ifndef gfan_DEBUGLEVEL
    7272#define gfan_DEBUGLEVEL 1
     
    7474#endif
    7575
    76 //NOTE Defining this will slow things down!
    77 //Only good for very coarse profiling
    78 // #define gfanp
     76NOTE Defining this will slow things down!
     77Only good for very coarse profiling
     78 #define gfanp
    7979#ifdef gfanp
    8080#include <sys/time.h>
     
    9696*
    9797*/
    98                
     98
    9999/** \brief The default constructor for facets
    100100*/
    101 facet::facet()                 
    102 {
    103         // Pointer to next facet.  */
     101facet::facet()
     102{
     103        Pointer to next facet.  */
    104104        /* Defaults to NULL. This way there is no need to check explicitly */
    105105        this->fNormal=NULL;
    106         this->interiorPoint=NULL;               
     106        this->interiorPoint=NULL;
    107107        this->UCN=0;
    108108        this->codim2Ptr=NULL;
    109         this->codim=1;          //default for (codim-1)-facets
     109        this->codim=1;          default for (codim-1)-facets
    110110        this->numCodim2Facets=0;
    111111        this->numRays=0;
    112112        this->flipGB=NULL;
    113113        this->next=NULL;
    114         this->prev=NULL;               
    115         this->flipRing=NULL;    //the ring on the other side
     114        this->prev=NULL;
     115        this->flipRing=NULL;    the ring on the other side
    116116        this->isFlippable=FALSE;
    117117}
    118                
     118
    119119/** \brief Constructor for facets of codim == 2
    120120* Note that as of now the code of the constructors is only for facets and codim2-faces. One
     
    124124{
    125125        this->fNormal=NULL;
    126         this->interiorPoint=NULL;                       
     126        this->interiorPoint=NULL;
    127127        this->UCN=0;
    128128        this->codim2Ptr=NULL;
     
    130130        {
    131131                this->codim=n;
    132         }//NOTE Handle exception here!                 
     132        }NOTE Handle exception here!
    133133        this->numCodim2Facets=0;
    134134        this->numRays=0;
     
    139139        this->isFlippable=FALSE;
    140140}
    141                
     141
    142142/** \brief The copy constructor
    143143* By default only copies the fNormal, f2Normals and UCN
     
    148148        this->UCN=f.UCN;
    149149        this->isFlippable=f.isFlippable;
    150         //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
     150        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
    153153        facet* f2Copy;
    154154        f2Copy=f.codim2Ptr;
     
    168168                {
    169169                        f2Act=new facet(2);
    170                         this->codim2Ptr=f2Act;                 
     170                        this->codim2Ptr=f2Act;
    171171                }
    172172                else
     
    180180                int64vec *f2Normal;
    181181                f2Normal = f2Copy->getFacetNormal();
    182 //              f2Act->setFacetNormal(f2Copy->getFacetNormal());
     182                f2Act->setFacetNormal(f2Copy->getFacetNormal());
    183183                f2Act->setFacetNormal(f2Normal);
    184184                delete f2Normal;
    185185                f2Act->setUCN(f2Copy->getUCN());
    186186                f2Copy = f2Copy->next;
    187         }       
     187        }
    188188}
    189189
     
    209209{
    210210#ifdef gfan_DEBUG
    211 //      printf("shallowdel@UCN %i\n", this->getUCN());
     211        printf("shallowdel@UCN %i\n", this->getUCN());
    212212#endif
    213213        this->fNormal=NULL;
    214 //      this->UCN=0;
     214        this->UCN=0;
    215215        this->interiorPoint=NULL;
    216216        this->codim2Ptr=NULL;
     
    219219        this->flipGB=NULL;
    220220        this->flipRing=NULL;
    221         assert(this->fNormal==NULL);   
    222 //      delete(this);
    223 }
    224                
     221        assert(this->fNormal==NULL);
     222        delete(this);
     223}
     224
    225225/** The default destructor */
    226226facet::~facet()
    227227{
    228228#ifdef gfan_DEBUG
    229 //      printf("~facet@UCN %i\n",this->getUCN());
     229        printf("~facet@UCN %i\n",this->getUCN());
    230230#endif
    231231        if(this->fNormal!=NULL)
     
    234234                delete this->interiorPoint;
    235235        /* 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!
    250250        if(this->flipGB!=NULL)
    251251                idDelete((ideal *)&this->flipGB);
    252 //      if(this->flipRing!=NULL && this->flipRing->idroot!=(idhdl)0xfbfbfbfbfbfbfbfb)
    253 //              rDelete(this->flipRing); //See vol II/134
    254 //      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;
    255255        this->prev=NULL;
    256256        this->next=NULL;
    257257}
    258                
     258
    259259inline const int64vec *facet::getRef2FacetNormal() const
    260260{
    261261        return(this->fNormal);
    262 }       
     262}
    263263
    264264/** Equality check for facets based on unique interior points*/
     
    281281                }
    282282        }
    283 //      if( fIntP->compare(gIntP)!=0) res=FALSE;
     283        if( fIntP->compare(gIntP)!=0) res=FALSE;
    284284#ifdef gfanp
    285285        gettimeofday(&end, 0);
    286286        gcone::t_areEqual += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec));
    287 #endif 
     287#endif
    288288        return res;
    289289}
     
    308308        int notParallelCtr=0;
    309309        int ctr=0;
    310         const int64vec* fNormal; //No new since iv64Copy and therefore getFacetNormal return a new
     310        const int64vec* fNormal; No new since iv64Copy and therefore getFacetNormal return a new
    311311        const int64vec* sNormal;
    312         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
     312        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
    319319        int64vec *fNRef=const_cast<int64vec*>(fNormal);
    320320        int64vec *sNRef=const_cast<int64vec*>(sNormal);
    321 //      if(isParallel(*fNormal,*sNormal))       
     321        if(isParallel(*fNormal,*sNormal))
    322322        if(isParallel(*fNRef,*sNRef))
    323 //      if(fNormal->compare((sNormal))!=0)//Behold! Teh definitive Mandelbug
     323        if(fNormal->compare((sNormal))!=0)//Behold! Teh definitive Mandelbug
    324324        {
    325325                facet* f2Act;
    326326                facet* s2Act;
    327                 f2Act = f->codim2Ptr;           
     327                f2Act = f->codim2Ptr;
    328328                ctr=0;
    329329                while(f2Act!=NULL)
    330330                {
    331331                        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);
    334334                        s2Act = s->codim2Ptr;
    335335                        while(s2Act!=NULL)
    336336                        {
    337337                                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);
    341341                                int foo=f2Normal->compare(s2Normal);
    342342                                if(foo==0)
    343343                                        ctr++;
    344344                                s2Act = s2Act->next;
    345 //                              delete s2Normal;
    346                         }
    347 //                      delete f2Normal;
     345                                delete s2Normal;
     346                        }
     347                        delete f2Normal;
    348348                        f2Act = f2Act->next;
    349                 }               
    350         }
    351 //      delete fNormal;
    352 //      delete sNormal;
     349                }
     350        }
     351        delete fNormal;
     352        delete sNormal;
    353353        if(ctr==f->numCodim2Facets)
    354354                res=TRUE;
     
    365365#endif
    366366        return res;
    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                
     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
    406406/** Stores the facet normal \param int64vec*/
    407407inline void facet::setFacetNormal(int64vec *iv)
     
    409409        if(this->fNormal!=NULL)
    410410                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
    415415* Mind: iv64Copy returns a new int64vec, so use this in the following way:
    416416* int64vec *iv;
     
    420420*/
    421421inline int64vec *facet::getFacetNormal() const
    422 {                               
     422{
    423423        return iv64Copy(this->fNormal);
    424 //      return this->fNormal;
     424        return this->fNormal;
    425425}
    426426
     
    430430        fNormal->show();
    431431}
    432                
     432
    433433/** Store the flipped GB*/
    434434inline void facet::setFlipGB(ideal I)
     
    436436        this->flipGB=idCopy(I);
    437437}
    438                
     438
    439439/** Returns a pointer to the flipped GB
    440440Seems not be used
     
    445445        return this->flipGB;
    446446}
    447                
     447
    448448/** Print the flipped GB*/
    449449inline void facet::printFlipGB()
     
    453453#endif
    454454}
    455                
     455
    456456/** Set the UCN */
    457457inline void facet::setUCN(int n)
     
    459459        this->UCN=n;
    460460}
    461                
    462 /** \brief Get the UCN 
     461
     462/** \brief Get the UCN
    463463* Returns the UCN iff this != NULL, else -1
    464464*/
     
    474474#ifdef NDEBUG
    475475        if(this!=NULL)
    476 #endif                 
     476#endif
    477477                return this->UCN;
    478478        else
    479479                return -1;
    480480}
    481                
     481
    482482/** Store an interior point of the facet */
    483483inline void facet::setInteriorPoint(int64vec *iv)
     
    487487        this->interiorPoint = iv64Copy(iv);
    488488}
    489                
     489
    490490/** Returns a pointer to this->interiorPoint
    491491* MIND: iv64Copy returns a new int64vec
     
    501501        return (this->interiorPoint);
    502502}
    503                
     503
    504504/** \brief Debugging function
    505505* prints the facet normal an all (codim-2)-facets that belong to it
    506506*/
    507507volatile void facet::fDebugPrint()
    508 {                       
    509         facet *codim2Act;                       
     508{
     509        facet *codim2Act;
    510510        codim2Act = this->codim2Ptr;
    511511        int64vec *fNormal;
    512         fNormal = this->getFacetNormal();       
     512        fNormal = this->getFacetNormal();
    513513        printf("=======================\n");
    514514        printf("Facet normal = (");fNormal->show(1,1);printf(")\n");
     
    524524        }
    525525        printf("=======================\n");
    526         delete fNormal; 
    527 }               
    528                
    529 //friend class gcone;   //Bad style
     526        delete fNormal;
     527}
     528
     529friend class gcone;     //Bad style
    530530
    531531
     
    538538
    539539
    540 /** \brief Default constructor. 
     540/** \brief Default constructor.
    541541 *
    542542 * Initialises this->next=NULL and this->facetPtr=NULL
     
    546546        this->next=NULL;
    547547        this->prev=NULL;
    548         this->facetPtr=NULL;    //maybe this->facetPtr = new facet();                   
     548        this->facetPtr=NULL;    maybe this->facetPtr = new facet();
    549549        this->baseRing=currRing;
    550550        this->counter++;
    551         this->UCN=this->counter;                       
     551        this->UCN=this->counter;
    552552        this->numFacets=0;
    553553        this->ivIntPt=NULL;
    554554        this->gcRays=NULL;
    555555}
    556                
     556
    557557/** \brief Constructor with ring and ideal
    558558 *
    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
    560560 * them in the private members gcone::rootRing and gcone::inputIdeal
    561561 * This constructor is only called once in the computation of the Gröbner fan,
     
    569569        this->next=NULL;
    570570        this->prev=NULL;
    571         this->facetPtr=NULL;                   
     571        this->facetPtr=NULL;
    572572        this->inputIdeal=I;
    573573        this->baseRing=currRing;
     
    579579        this->gcRays=NULL;
    580580}
    581                
    582 /** \brief Copy constructor 
     581
     582/** \brief Copy constructor
    583583 *
    584584 * Copies a cone, sets this->gcBasis to the flipped GB
    585585 * Call this only after a successful call to gcone::flip which sets facet::flipGB
    586 */             
     586*/
    587587gcone::gcone(const gcone& gc, const facet &f)
    588588{
    589589        this->next=NULL;
    590 //      this->prev=(gcone *)&gc; //comment in to get a tree
     590        this->prev=(gcone *)&gc; //comment in to get a tree
    591591        this->prev=NULL;
    592         this->numVars=gc.numVars;                                               
     592        this->numVars=gc.numVars;
    593593        this->counter++;
    594594        this->UCN=this->counter;
     
    596596        this->facetPtr=NULL;
    597597        this->gcBasis=idrCopyR(f.flipGB, f.flipRing);
    598 //      this->inputIdeal=idCopy(this->gcBasis);
     598        this->inputIdeal=idCopy(this->gcBasis);
    599599        this->baseRing=rCopy(f.flipRing);
    600600        this->numFacets=0;
     
    602602        this->gcRays=NULL;
    603603}
    604                
    605 /** \brief Default destructor 
     604
     605/** \brief Default destructor
    606606*/
    607607gcone::~gcone()
     
    619619                idDelete((ideal *)&this->gcBasis);
    620620#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);
    626626        if(this->UCN!=1 && this->baseRing!=NULL)
    627627                rDelete(this->baseRing);
     
    638638        }
    639639        this->counter--;
    640         //should be deleted in noRevS
    641 //      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);
    643643        for(int ii=0;ii<this->numRays;ii++)
    644644                delete(gcRays[ii]);
    645645        omFree(gcRays);
    646 }                       
     646}
    647647
    648648/** Returns the number of cones existing at the time*/
     
    651651        return this->counter;
    652652}
    653        
     653
    654654/** \brief Set the interior point of a cone */
    655655inline void gcone::setIntPoint(int64vec *iv)
     
    659659        this->ivIntPt=iv64Copy(iv);
    660660}
    661                
     661
    662662/** \brief Returns either a physical copy the interior point of a cone or just a reference to it.*/
    663663inline int64vec *gcone::getIntPoint(bool shallow)
     
    668668                return iv64Copy(this->ivIntPt);
    669669}
    670                
     670
    671671/** \brief Print the interior point */
    672672inline void gcone::showIntPoint()
     
    674674        ivIntPt->show();
    675675}
    676                
     676
    677677/** \brief Print facets
    678678 * This is mainly for debugging purposes. Usually called from within gdb
     
    708708        printf("\n");
    709709}
    710                
     710
    711711/** For debugging purposes only */
    712712static volatile void showSLA(facet &f)
     
    718718                facet *codim2Act;
    719719                codim2Act = fAct->codim2Ptr;
    720                
     720
    721721                printf("\n");
    722722                while(fAct!=NULL)
    723723                {
    724                         int64vec *fNormal;             
     724                        int64vec *fNormal;
    725725                        fNormal=fAct->getFacetNormal();
    726726                        printf("(");fNormal->show(1,0);
     
    745745        }
    746746}
    747                
     747
    748748static void idDebugPrint(const ideal &I)
    749749{
     
    761761static void invPrint(const ideal &I)
    762762{
    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;
    771771}
    772772
     
    784784        return res;
    785785}
    786                
     786
    787787/** \brief Set gcone::numFacets */
    788788inline void gcone::setNumFacets()
    789789{
    790790}
    791                
     791
    792792/** \brief Get gcone::numFacets */
    793793inline int gcone::getNumFacets()
     
    795795        return this->numFacets;
    796796}
    797                
     797
    798798inline int gcone::getUCN()
    799799{
    800         if( this!=NULL)// && ( this!=(gcone * const)0xfbfbfbfbfbfbfbfb && this!=(gcone * const)0xfbfbfbfb ) )
     800        if( this!=NULL) && ( this!=(gcone * const)0xfbfbfbfbfbfbfbfb && this!=(gcone * const)0xfbfbfbfb ) )
    801801                return this->UCN;
    802802        else
     
    829829 * as its input. Redundancies are automatically removed using cddlib's dd_MatrixCanonicalize.
    830830 * 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
    832832 * each row to represent an inequality of type const+x1+...+xn <= 0. While computing the normals we come across
    833833 * the set \f$ \partial\mathcal{G} \f$ which we might store for later use. C.f p71 of journal
     
    844844#endif
    845845        poly aktpoly;
    846         int rows;                       // will contain the dimensions of the ineq matrix - deprecated by
     846        int rows;                        will contain the dimensions of the ineq matrix - deprecated by
    847847        dd_rowrange ddrows;
    848848        dd_colrange ddcols;
    849         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
     849        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
    856856        for (int ii=0;ii<IDELEMS(I);ii++)
    857857        {
    858 //              aktpoly=(poly)I->m[ii];
    859 //              rows=rows+pLength(aktpoly)-1;
     858                aktpoly=(poly)I->m[ii];
     859                rows=rows+pLength(aktpoly)-1;
    860860                rows=rows+pLength((poly)I->m[ii])-1;
    861861        }
    862862
    863         dd_rowrange aktmatrixrow=0;     // needed to store the diffs of the expvects in the rows of ddineq
     863        dd_rowrange aktmatrixrow=0;      needed to store the diffs of the expvects in the rows of ddineq
    864864        ddrows=rows;
    865865        ddcols=this->numVars;
    866         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
     866        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
    870870        for (int i=0; i<IDELEMS(I); i++)
    871871        {
    872                 aktpoly=(poly)I->m[i];          //get aktpoly as i-th component of I
    873                 //simpler version of storing expvect diffs
     872                aktpoly=(poly)I->m[i];          get aktpoly as i-th component of I
     873                simpler version of storing expvect diffs
    874874                int *leadexpv=(int*)omAlloc(((this->numVars)+1)*sizeof(int));
    875875                pGetExpV(aktpoly,leadexpv);
     
    879879                        pNextTerm/*aktpoly*/=pNext(pNextTerm);
    880880                        int *tailexpv=(int*)omAlloc(((this->numVars)+1)*sizeof(int));
    881                         pGetExpV(pNextTerm,tailexpv);                   
     881                        pGetExpV(pNextTerm,tailexpv);
    882882                        for(int kk=1;kk<=this->numVars;kk++)
    883                         {                               
     883                        {
    884884                                dd_set_si(ddineq->matrix[(dd_rowrange)aktmatrixrow][kk],leadexpv[kk]-tailexpv[kk]);
    885885                        }
    886886                        aktmatrixrow += 1;
    887887                        omFree(tailexpv);
    888                 }               
    889                 omFree(leadexpv);       
    890         } //for
     888                }
     889                omFree(leadexpv);
     890        } for
    891891#if true
    892892        /*Let's make the preprocessing here. This could already be done in the above for-loop,
     
    895895        * Quote: [...] every non-zero spoly should have at least one of its terms in inv(G)
    896896        */
    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);
    899899        int falseGammaCounter=0;
    900900        int *redRowsArray=NULL;
    901901        int num_alloc=0;
    902         int num_elts=0; 
     902        int num_elts=0;
    903903        for(int ii=0;ii<ddineq->rowsize;ii++)
    904904        {
    905905                ideal initialForm=idInit(IDELEMS(I),I->rank);
    906                 //read row ii into gamma
    907 //              int64 tmp;
     906                read row ii into gamma
     907                int64 tmp;
    908908                int64vec *gamma=new int64vec(this->numVars);
    909909                for(int jj=1;jj<=this->numVars;jj++)
     
    915915                computeInv((ideal&)I,initialForm,*gamma);
    916916                delete gamma;
    917                 //Create leading ideal
     917                Create leading ideal
    918918                ideal L=idInit(IDELEMS(initialForm),1);
    919919                for(int jj=0;jj<IDELEMS(initialForm);jj++)
     
    922922                        L->m[jj]=pCopy(/*pHead(initialForm->m[jj]))*/p);
    923923                        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?
    927927                memset(P,0,sizeof(LObject));
    928928
     
    930930                {
    931931                        bool isMaybeFacet=FALSE;
    932                         P->p1=initialForm->m[jj];       //build spolys of initialForm in_v
     932                        P->p1=initialForm->m[jj];       build spolys of initialForm in_v
    933933
    934934                        for(int kk=jj+1;kk<=IDELEMS(initialForm)-1;kk++)
    935935                        {
    936936                                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 follow
     937                                ksCreateSpoly(P);
     938                                if(P->p!=NULL)  spoly non zero=?
     939                                {
     940                                        poly p;NOTE Don't use pInit here. Evil memleak will follow
    941941                                        poly q;
    942942                                        poly pDel,qDel;
    943943                                        p=pCopy(P->p);
    944                                         q=pHead(p);     //Monomial q
     944                                        q=pHead(p);     Monomial q
    945945                                        pDelete(&q);
    946946                                        pDel=p; qDel=q;
    947947                                        isMaybeFacet=FALSE;
    948                                         //TODO: Suffices to check LTs here
     948                                        TODO: Suffices to check LTs here
    949949                                        while(p!=NULL)
    950                                         {                                               
     950                                        {
    951951                                                q=pHead(p);
    952952                                                for(int ll=0;ll<IDELEMS(L);ll++)
    953953                                                {
    954954                                                        if(pLmEqual(L->m[ll],q) || pDivisibleBy(L->m[ll],q))
    955                                                         {                                                       
     955                                                        {
    956956                                                                isMaybeFacet=TRUE;
    957                                                                 break;//for
     957                                                                break;for
    958958                                                        }
    959959                                                }
     
    961961                                                if(isMaybeFacet==TRUE)
    962962                                                {
    963                                                         break;//while(p!=NULL)
     963                                                        break;while(p!=NULL)
    964964                                                }
    965965                                                p=pNext(p);
    966                                         }//while
    967 //                                      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!
    968968                                        if(q!=NULL) pDelete(&q);
    969969                                        pDelete(&pDel);
     
    971971                                        if(isMaybeFacet==FALSE)
    972972                                        {
    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;
    978978                                                if(num_alloc==num_elts) num_alloc==0 ? num_alloc=1 : num_alloc*=2;
    979                                                
     979
    980980                                                void *tmp = realloc(redRowsArray,(num_alloc*sizeof(int)));
    981981                                                if(!tmp)
     
    987987                                                redRowsArray[num_elts]=ii;
    988988                                                num_elts++;
    989                                                 //break;//for(int kk, since we have found one that is not in L 
    990                                                 goto _start;    //mea culpa, mea culpa, mea maxima culpa
     989                                                break;//for(int kk, since we have found one that is not in L
     990                                                goto _start;    mea culpa, mea culpa, mea maxima culpa
    991991                                        }
    992                                 }//if(P->p!=NULL)
     992                                }if(P->p!=NULL)
    993993                                pDelete(&(P->p));
    994                         }//for k
    995                 }//for jj
     994                        }for k
     995                }for jj
    996996                _start:;
    997997                idDelete(&L);
    998998                delete P;
    999999                idDelete(&initialForm);
    1000         }//for(ii<ddineq-rowsize
    1001 //      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]
    10031003#ifdef gfan_DEBUG
    10041004        printf("Removed %i of %i in preprocessing step\n",num_elts,ddineq->rowsize);
     
    10061006        for( int ii=0;ii<num_elts;ii++ )
    10071007        {
    1008                 dd_MatrixRowRemove(&ddineq,redRowsArray[ii]+1-offset);//cddlib sucks at enumeration
     1008                dd_MatrixRowRemove(&ddineq,redRowsArray[ii]+1-offset);cddlib sucks at enumeration
    10091009                offset++;
    1010         }       
    1011         free(redRowsArray);//NOTE May crash on some machines.
     1010        }
     1011        free(redRowsArray);NOTE May crash on some machines.
    10121012        /*And now for the strictly positive rows
    10131013        * Doesn't gain significant speedup
     
    10221022                        (*ivPos)[jj]=(int)mpq_get_d(ddineq->matrix[ii][jj+1]);
    10231023                bool isStrictlyPos=FALSE;
    1024                 int posCtr=0;           
     1024                int posCtr=0;
    10251025                for(int jj=0;jj<this->numVars;jj++)
    10261026                {
     
    10301030                        {
    10311031                                if ((*ivPos)[jj]>=0)
    1032                                 {                               
    1033                                         posCtr++;                               
     1032                                {
     1033                                        posCtr++;
    10341034                                }
    1035                         }                       
     1035                        }
    10361036                        delete ivCanonical;
    10371037                }
     
    10521052                        posRowsArray = (int*)tmp;
    10531053                        posRowsArray[num_elts]=ii;
    1054                         num_elts++;     
     1054                        num_elts++;
    10551055                }
    10561056                delete ivPos;
     
    10651065#endif
    10661066
    1067         dd_MatrixCanonicalize(&ddineq, &ddlinset, &ddredrows, &ddnewpos, &dderr);       
    1068         ddrows = ddineq->rowsize;       //Size of the matrix with redundancies removed
     1067        dd_MatrixCanonicalize(&ddineq, &ddlinset, &ddredrows, &ddnewpos, &dderr);
     1068        ddrows = ddineq->rowsize;       Size of the matrix with redundancies removed
    10691069        ddcols = ddineq->colsize;
    1070        
     1070
    10711071        this->ddFacets = dd_CopyMatrix(ddineq);
    1072                        
    1073         /*Write the normals into class facet*/ 
    1074         facet *fAct;    //pointer to active facet       
     1072
     1073        /*Write the normals into class facet*/
     1074        facet *fAct;    pointer to active facet
    10751075        int numNonFlip=0;
    10761076        for (int kk = 0; kk<ddrows; kk++)
    10771077        {
    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 setFacetNormal
     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 setFacetNormal
    10801080                for (int jj = 1; jj <ddcols; jj++)
    10811081                {
    10821082                        int64 val;
    10831083                        val = (int64)mpq_get_d(ddineq->matrix[kk][jj]);
    1084                         (*load)[jj-1] = val;    //store typecasted entry at pos jj-1 of load
     1084                        (*load)[jj-1] = val;    store typecasted entry at pos jj-1 of load
    10851085                        ggT = int64gcd(ggT,/*(int64&)foo*/val);
    1086                 }//for (int jj = 1; jj <ddcols; jj++)
     1086                }for (int jj = 1; jj <ddcols; jj++)
    10871087                if(ggT>1)
    10881088                {
    10891089                        for(int ll=0;ll<this->numVars;ll++)
    1090                                 (*load)[ll] /= ggT;//make primitive vector
     1090                                (*load)[ll] /= ggT;make primitive vector
    10911091                }
    10921092                /*Quick'n'dirty hack for flippability. Executed only if gcone::hasHomInput==FALSE
    10931093                * Otherwise every facet intersects the positive orthant
    1094                 */     
     1094                */
    10951095                if(gcone::hasHomInput==FALSE)
    10961096                {
    1097                         //TODO: No dP needed
     1097                        TODO: No dP needed
    10981098                        bool isFlip=FALSE;
    10991099                        for(int jj = 0; jj<load->length(); jj++)
    11001100                        {
    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;
     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;
    11091109                                if((*load)[jj]<0)
    11101110                                {
    11111111                                        isFlip=TRUE;
    11121112                                        break;
    1113                                 }                               
     1113                                }
    11141114                        }/*End of check for flippability*/
    1115 //                      if(iv64isStrictlyPositive(load))
    1116 //                              isFlip=TRUE;
     1115                        if(iv64isStrictlyPositive(load))
     1116                                isFlip=TRUE;
    11171117                        if(isFlip==FALSE)
    11181118                        {
     
    11231123                                        facet *fRoot = new facet();
    11241124                                        this->facetPtr = fRoot;
    1125                                         fAct = fRoot;                                                   
     1125                                        fAct = fRoot;
    11261126                                }
    11271127                                else
     
    11341134                                fAct->setUCN(this->getUCN());
    11351135#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");
    11371137#endif
    11381138                        }
     
    11531153                                fAct->isFlippable=TRUE;
    11541154                                fAct->setFacetNormal(load);
    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*/                                     
     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*/
    11601160                        this->numFacets++;
    11611161                        if(this->numFacets==1)
     
    11721172                        fAct->isFlippable=TRUE;
    11731173                        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...
    11801180        if(numNonFlip==this->numFacets)
    1181         {                                       
     1181        {
    11821182                WerrorS ("Only non-flippable facets. Terminating...\n");
    1183 //              exit(-1);//Bit harsh maybe...
    1184         }
    1185                        
     1183                exit(-1);//Bit harsh maybe...
     1184        }
     1185
    11861186        /*
    11871187        Now we should have a linked list containing the facet normals of those facets that are
     
    11891189        -flipable
    11901190        Adressing is done via *facetPtr
    1191         */                     
     1191        */
    11921192        if (compIntPoint==TRUE)
    11931193        {
     
    11981198                {
    11991199                        dd_set_si(posRestr->matrix[ii][jj],1);
    1200                         jj++;                                                   
     1200                        jj++;
    12011201                }
    12021202                dd_MatrixAppendTo(&ddineq,posRestr);
    1203                 interiorPoint(ddineq, *iv);     //NOTE ddineq contains non-flippable facets
    1204                 this->setIntPoint(iv);  //stores the interior point in gcone::ivIntPt
     1203                interiorPoint(ddineq, *iv);     NOTE ddineq contains non-flippable facets
     1204                this->setIntPoint(iv);  stores the interior point in gcone::ivIntPt
    12051205                delete iv;
    12061206                dd_FreeMatrix(posRestr);
    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?
     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?
    12131213#ifdef gfanp
    12141214        gettimeofday(&end, 0);
     
    12161216#endif
    12171217
    1218 }//gcone::getConeNormals(ideal I)
    1219                
     1218}gcone::getConeNormals(ideal I)
     1219
    12201220/** \brief Compute the (codim-2)-facets of a given cone
    12211221 * This method is used during noRevS
     
    12291229        gettimeofday(&start, 0);
    12301230#endif
    1231         //this->facetPtr->codim2Ptr = new facet(2);     //instantiate a (codim-2)-facet
     1231        this->facetPtr->codim2Ptr = new facet(2);       //instantiate a (codim-2)-facet
    12321232        facet *fAct;
    1233         fAct = this->facetPtr;         
     1233        fAct = this->facetPtr;
    12341234        facet *codim2Act;
    1235         //codim2Act = this->facetPtr->codim2Ptr;
    1236         dd_MatrixPtr ddineq;//,P,ddakt;
     1235        codim2Act = this->facetPtr->codim2Ptr;
     1236        dd_MatrixPtr ddineq;,P,ddakt;
    12371237        dd_ErrorType err;
    1238         //ddineq = facets2Matrix(gc);   //get a matrix representation of the cone
     1238        ddineq = facets2Matrix(gc);     //get a matrix representation of the cone
    12391239        ddineq = dd_CopyMatrix(gc.ddFacets);
    12401240        /*Now set appropriate linearity*/
    1241         for (int ii=0; ii<this->numFacets; ii++)                       
    1242         {       
     1241        for (int ii=0; ii<this->numFacets; ii++)
     1242        {
    12431243                dd_rowset impl_linset, redset;
    12441244                dd_rowindex newpos;
    12451245                dd_MatrixPtr ddakt;
    12461246                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;
    12491249                set_addelem(ddakt->linset,ii+1);/*Now set appropriate linearity*/
    12501250#ifdef gfanp
    12511251                timeval t_ddMC_start, t_ddMC_end;
    12521252                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);
    12551255                dd_PolyhedraPtr ddpolyh;
    12561256                ddpolyh=dd_DDMatrix2Poly(ddakt, &err);
    1257 //              ddpolyh=dd_DDMatrix2Poly2(ddakt, dd_MaxCutoff, &err);
     1257                ddpolyh=dd_DDMatrix2Poly2(ddakt, dd_MaxCutoff, &err);
    12581258                dd_MatrixPtr P;
    1259                 P=dd_CopyGenerators(ddpolyh);           
     1259                P=dd_CopyGenerators(ddpolyh);
    12601260                dd_FreePolyhedra(ddpolyh);
    1261                 //TODO Call for one cone , normalize - check equalities - plus lineality -done
     1261                TODO Call for one cone , normalize - check equalities - plus lineality -done
    12621262#ifdef gfanp
    12631263                gettimeofday(&t_ddMC_end,0);
    12641264                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
    12661266                /* We loop through each row of P normalize it by making all
    12671267                * entries integer ones and add the resulting vector to the
    12681268                * int matrix facet::codim2Facets */
    12691269                for (int jj=1;jj<=/*ddakt*/P->rowsize;jj++)
    1270                 {                                       
     1270                {
    12711271                        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);
    12751275                                codim2Act = fAct->codim2Ptr;
    12761276                        }
     
    12971297#endif
    12981298                        codim2Act->setFacetNormal(n);
    1299                         delete n;                                       
    1300                 }               
     1299                        delete n;
     1300                }
    13011301                /*We check whether the facet spanned by the codim-2 facets
    13021302                * 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
    13041304                * linearity for ddakt above.
    13051305                */
    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 //              }
     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                }
    13381338                /*End of check*/
    13391339                /*This test should be way less time consuming*/
     
    13581358                }
    13591359                if(containsStrictlyPosRay==FALSE)
    1360                 //TODO Not sufficient. Intersect with pos orthant for pos int
     1360                TODO Not sufficient. Intersect with pos orthant for pos int
    13611361                        fAct->isFlippable=FALSE;
    13621362#ifdef gfanp
     
    13651365#endif
    13661366                /**/
    1367                 fAct = fAct->next;     
     1367                fAct = fAct->next;
    13681368                dd_FreeMatrix(ddakt);
    13691369                dd_FreeMatrix(P);
    1370         }//for 
     1370        }for
    13711371        dd_FreeMatrix(ddineq);
    13721372#ifdef gfanp
     
    13751375#endif
    13761376}
    1377                
     1377
    13781378/** Really extremal rays this time ;)
    13791379* Extremal rays are unique modulo the homogeneity space.
     
    13831383* checking whether the inner product of the ray with the normal is zero.
    13841384* 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
    13861386* 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
    13881388* memleak
    13891389* TODO normalization
     
    13971397        gettimeofday(&poly_start,0);
    13981398#endif
    1399         //Add lineality space - dd_LinealitySpace
     1399        Add lineality space - dd_LinealitySpace
    14001400        dd_MatrixPtr ddineq;
    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);
     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);
    14061406        ddineq = (dd_LinealitySpace->rowsize>0) ? dd_AppendMatrix(gc.ddFacets,gcone::dd_LinealitySpace) : dd_CopyMatrix(gc.ddFacets);
    14071407        /* 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
    14091409        * restricted fan. This way we can be sure to find strictly positive interior points.
    14101410        * This in turn makes life easy when checking for flippability!
     
    14211421                assert(ddineq);
    14221422                dd_FreeMatrix(ddPosRestr);
    1423         }       
     1423        }
    14241424        dd_PolyhedraPtr ddPolyh;
    14251425        ddPolyh = dd_DDMatrix2Poly(ddineq, &err);
     
    14341434        /* Compute interior point on the fly*/
    14351435        int64vec *ivIntPointOfCone = new int64vec(this->numVars);
    1436 //      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
     1436        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
    14391439        /*for(int jj=0;jj<this->numVars;jj++)
    14401440        {
    1441                 mpq_init(colSum[jj]);           
     1441                mpq_init(colSum[jj]);
    14421442                for(int ii=0;ii<P->rowsize;ii++)
    14431443                {
     
    14551455                mpz_clear(den);
    14561456        }
    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?
    14591459        mpz_t kgV; mpz_init(kgV);
    14601460        mpz_set_str(kgV,"1",10);
     
    14771477        for(int ii=0;ii<P->rowsize;ii++)
    14781478        {
    1479 //              int64vec *foo = new int64vec(this->numVars);
     1479                int64vec *foo = new int64vec(this->numVars);
    14801480                int64vec *tmp = ivIntPointOfCone;
    14811481                makeInt(P,ii+1,*foo);
    14821482                ivIntPointOfCone = iv64Add(ivIntPointOfCone,foo);
    14831483                delete tmp;
    1484 //              delete foo;
     1484                delete foo;
    14851485        }
    14861486        delete foo;
     
    14881488        for (int ii=0;ii<(this->numVars);ii++)
    14891489        {
    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 )
    14951495                        WarnS("Interior point exceeds INT_MAX!\n");
    1496 //              mpq_clear(product);
    1497                 //Compute intgcd
     1496                mpq_clear(product);
     1497                Compute intgcd
    14981498                ggT=int64gcd(ggT,(*ivIntPointOfCone)[ii]);
    14991499        }
    1500        
    1501         //Divide out a common gcd > 1
     1500
     1501        Divide out a common gcd > 1
    15021502        if(ggT>1)
    15031503        {
     
    15081508                }
    15091509        }
    1510 //      mpq_clear(qkgV);
    1511 //      delete [] colSum;
     1510        mpq_clear(qkgV);
     1511        delete [] colSum;
    15121512        /*For homogeneous input (like Det3,3,5) the int points may be negative. So add a suitable multiple of (1,_,1)*/
    15131513        if(hasHomInput==TRUE && iv64isStrictlyPositive(ivIntPointOfCone)==FALSE)
     
    15171517                for(int ii=0;ii<this->numVars;ii++)
    15181518                {
    1519 //                      (*ivOne)[ii]=1;
     1519                        (*ivOne)[ii]=1;
    15201520                        if ((*ivIntPointOfCone)[ii]<maxNegEntry) maxNegEntry=(*ivIntPointOfCone)[ii];
    15211521                }
    15221522                maxNegEntry *= -1;
    1523                 maxNegEntry++;//To be on the safe side
     1523                maxNegEntry++;To be on the safe side
    15241524                for(int ii=0;ii<this->numVars;ii++)
    15251525                        (*ivOne)[ii]=maxNegEntry;
     
    15271527                ivIntPointOfCone=iv64Add(ivIntPointOfCone,ivOne);
    15281528                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 2
    1534 //                      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                }
    15371537                delete ivOne;
    15381538                int64 ggT=(*ivIntPointOfCone)[0];
     
    15451545                }
    15461546        }
    1547 //      assert(iv64isStrictlyPositive(ivIntPointOfCone));
    1548        
     1547        assert(iv64isStrictlyPositive(ivIntPointOfCone));
     1548
    15491549        this->setIntPoint(ivIntPointOfCone);
    15501550        delete(ivIntPointOfCone);
    15511551        /* end of interior point computation*/
    1552        
    1553         //Loop through the rows of P and check whether fNormal*row[i]=0 => row[i] belongs to fNormal
     1552
     1553        Loop through the rows of P and check whether fNormal*row[i]=0 => row[i] belongs to fNormal
    15541554        int rows=P->rowsize;
    15551555        facet *fAct=gc.facetPtr;
    1556         //Construct an array to hold the extremal rays of the cone
    1557         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);
    15581558        for(int ii=0;ii<P->rowsize;ii++)
    15591559        {
    15601560                int64vec *rowvec = new int64vec(this->numVars);
    1561                 makeInt(P,ii+1,*rowvec);//get an integer entry instead of rational, rowvec is primitve
     1561                makeInt(P,ii+1,*rowvec);get an integer entry instead of rational, rowvec is primitve
    15621562                this->gcRays[ii] = iv64Copy(rowvec);
    15631563                delete rowvec;
    1564         }       
     1564        }
    15651565        this->numRays=P->rowsize;
    1566         //Check which rays belong to which facet
     1566        Check which rays belong to which facet
    15671567        while(fAct!=NULL)
    15681568        {
    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();
    15711571                int64vec *ivIntPointOfFacet = new int64vec(this->numVars);
    15721572                for(int ii=0;ii<rows;ii++)
    1573                 {                       
     1573                {
    15741574                        if(dotProduct(*fNormal,this->gcRays[ii])==0)
    15751575                        {
    1576                                 int64vec *tmp = ivIntPointOfFacet;//Prevent memleak
     1576                                int64vec *tmp = ivIntPointOfFacet;Prevent memleak
    15771577                                fAct->numCodim2Facets++;
    15781578                                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);
    15821582                                        codim2Act = fAct->codim2Ptr;
    15831583                                }
     
    15871587                                        codim2Act = codim2Act->next;
    15881588                                }
    1589                                 //codim2Act->setFacetNormal(rowvec);
    1590                                 //Rather just let codim2Act point to the corresponding int64vec of gcRays
     1589                                codim2Act->setFacetNormal(rowvec);
     1590                                Rather just let codim2Act point to the corresponding int64vec of gcRays
    15911591                                codim2Act->fNormal=this->gcRays[ii];
    1592                                 fAct->numRays++;                                 
    1593                                 //Memleak avoided via tmp
     1592                                fAct->numRays++;
     1593                                Memleak avoided via tmp
    15941594                                ivIntPointOfFacet=iv64Add(ivIntPointOfFacet,this->gcRays[ii]);
    1595                                 //Now tmp still points to the OLD address of ivIntPointOfFacet
     1595                                Now tmp still points to the OLD address of ivIntPointOfFacet
    15961596                                delete(tmp);
    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)
     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)
    16031603                if( !iv64isStrictlyPositive(ivIntPointOfFacet) && hasHomInput==TRUE)
    16041604                {
     
    16111611                                for(int jj=0;jj<this->numVars;jj++)
    16121612                                {
    1613                                         (*ivOne)[jj] = (*ivOne)[jj] << 1; //times 2
     1613                                        (*ivOne)[jj] = (*ivOne)[jj] << 1; times 2
    16141614                                }
    16151615                                ivIntPointOfFacet = iv64Add(ivIntPointOfFacet/*diff*/,ivOne);
    1616                                 delete tmp;                             
     1616                                delete tmp;
    16171617                        }
    16181618                        delete ivOne;
     
    16251625                        for(int ii=0;ii<this->numVars;ii++)
    16261626                                (*ivIntPointOfFacet)[ii] /= ggT;
    1627                 }                       
     1627                }
    16281628                fAct->setInteriorPoint(ivIntPointOfFacet);
    1629                
     1629
    16301630                delete(ivIntPointOfFacet);
    1631                 //Now (if we have at least 3 variables) do a bubblesort on the rays
     1631                Now (if we have at least 3 variables) do a bubblesort on the rays
    16321632                /*if(this->numVars>2)
    16331633                {
     
    16431643                        do
    16441644                        {
    1645                                 exchanged=FALSE;//n=fAct->numRays-1;                           
     1645                                exchanged=FALSE;n=fAct->numRays-1;
    16461646                                for(unsigned ii=0;ii<=n-1;ii++)
    1647                                 {                                       
     1647                                {
    16481648                                        if((A[ii]->fNormal)->compare((A[ii+1]->fNormal))==1)
    16491649                                        {
    1650                                                 //Swap rays
     1650                                                Swap rays
    16511651                                                cout << "Swapping ";
    16521652                                                A[ii]->fNormal->show(1,0); cout << " with "; A[ii+1]->fNormal->show(1,0); cout << endl;
     
    16571657                                                if(ii==0)
    16581658                                                        fAct->codim2Ptr=A[ii+1];
    1659                                                 //end swap
    1660                                                 facet *tmp=A[ii];//swap in list
     1659                                                end swap
     1660                                                facet *tmp=A[ii];swap in list
    16611661                                                A[ii+1]=A[ii];
    16621662                                                A[ii]=tmp;
    1663 //                                              tmp=NULL;                       
    1664                                         }                                       
     1663                                                tmp=NULL;
     1664                                        }
    16651665                                }
    1666                                 n--;                   
     1666                                n--;
    16671667                        }while(exchanged==TRUE && n>=0);
    1668                 }*///if pVariables>2
    1669 //              delete fNormal;         
     1668                }*/if pVariables>2
     1669                delete fNormal;
    16701670                fAct = fAct->next;
    1671         }//end of facet checking
     1671        }end of facet checking
    16721672        dd_FreeMatrix(P);
    1673         //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
     1673        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
    16771677        if(gcone::hasHomInput==FALSE)
    16781678        {
     
    16801680                while(fAct!=NULL)
    16811681                {
    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;
    17011701                        if(!iv64isStrictlyPositive(fAct->interiorPoint))
    17021702                                fAct->isFlippable=FALSE;
    17031703                        fAct = fAct->next;
    17041704                }
    1705         }//hasHomInput?
     1705        }hasHomInput?
    17061706#ifdef gfanp
    17071707        gettimeofday(&end, 0);
    17081708        t_getExtremalRays += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec));
    1709 #endif 
     1709#endif
    17101710}
    17111711
     
    17131713void gcone::orderRays()
    17141714{
    1715 //   qsort(gcRays,sizeof(int64vec),int64vec::compare);
    1716 }
    1717        
     1715   qsort(gcRays,sizeof(int64vec),int64vec::compare);
     1716}
     1717
    17181718inline bool gcone::iv64isStrictlyPositive(const int64vec * iv64)
    17191719{
     
    17251725                        res=FALSE;
    17261726                        break;
    1727                 }               
     1727                }
    17281728        }
    17291729        return res;
    17301730}
    17311731
    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
    17331733 *
    17341734 * Implements algorithm 4.3.2 from Anders' thesis.
     
    17381738 * Parallelity is checked using basic linear algebra. See gcone::isParallel.
    17391739 * 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
    17411741 * to this interior point.
    17421742 *\param ideal, facet
    17431743 * Input: a marked,reduced Groebner basis and a facet
    17441744 */
    1745 inline void gcone::flip(ideal gb, facet *f)             //Compute "the other side"
    1746 {       
     1745inline void gcone::flip(ideal gb, facet *f)             Compute "the other side"
     1746{
    17471747#ifdef gfanp
    17481748        timeval start, end;
    17491749        gettimeofday(&start, 0);
    1750 #endif         
    1751         int64vec *fNormal;// = new int64vec(this->numVars);     //facet normal, check for parallelity                   
    1752         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;
    17531753#ifdef gfan_DEBUG
    1754 //      std::cout << "running gcone::flip" << std::endl;
     1754        std::cout << "running gcone::flip" << std::endl;
    17551755        printf("flipping UCN %i over facet",this->getUCN());
    17561756        fNormal->show(1,0);
    1757         printf(") with UCN %i\n",f->getUCN() ); 
     1757        printf(") with UCN %i\n",f->getUCN() );
    17581758#endif
    17591759        if(this->getUCN() != f->getUCN())
     
    17631763        }
    17641764        /*1st step: Compute the initial ideal*/
    1765         /*poly initialFormElement[IDELEMS(gb)];*/       //array of #polys in GB to store initial form
     1765        /*poly initialFormElement[IDELEMS(gb)];*/       array of #polys in GB to store initial form
    17661766        ideal initialForm=idInit(IDELEMS(gb),this->gcBasis->rank);
    1767        
     1767
    17681768        computeInv(gb,initialForm,*fNormal);
    17691769
     
    17711771/*      cout << "Initial ideal is: " << endl;
    17721772        idShow(initialForm);
    1773         //f->printFlipGB();*/
    1774 //      cout << "===" << endl;
    1775 #endif                 
     1773        f->printFlipGB();*/
     1774        cout << "===" << endl;
     1775#endif
    17761776        /*2nd step: lift initial ideal to a GB of the neighbouring cone using minus alpha as weight*/
    17771777        /*Substep 2.1
    1778         compute $G_{-\alpha}(in_v(I)) 
     1778        compute $G_{-\alpha}(in_v(I))
    17791779        see journal p. 66
    17801780        NOTE Check for different rings. Prolly it will not always be necessary to add a weight, if the
     
    17831783        ring srcRing=currRing;
    17841784        ring tmpRing;
    1785                        
     1785
    17861786        if( (srcRing->order[0]!=ringorder_a))
    17871787        {
    1788                 int64vec *iv;// = new int64vec(this->numVars);
    1789                 iv = ivNeg(fNormal);//ivNeg uses iv64Copy -> new
    1790 //              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));
    17911791                tmpRing=rCopyAndAddWeight(srcRing,iv);
    17921792                delete iv;
     
    18051805                tmpRing->block1[0]=length;
    18061806                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;
    18131813        ina=idrCopyR(initialForm,srcRing);
    18141814        idDelete(&initialForm);
    18151815        ideal H;
    1816 //      H=kStd(ina,NULL,isHomog,NULL);  //we know it is homogeneous
     1816        H=kStd(ina,NULL,isHomog,NULL);  //we know it is homogeneous
    18171817#ifdef gfanp
    18181818        timeval t_kStd_start, t_kStd_end;
     
    18221822                H=kStd(ina,NULL,isHomog,NULL/*,gcone::hilbertFunction*/);
    18231823        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))
    18251825#ifdef gfanp
    18261826        gettimeofday(&t_kStd_end, 0);
     
    18351835        rChangeCurrRing(srcRing);
    18361836        ideal srcRing_H;
    1837         ideal srcRing_HH;                       
     1837        ideal srcRing_HH;
    18381838        srcRing_H=idrCopyR(H,tmpRing);
    1839         //H is needed further below, so don't idDelete here
     1839        H is needed further below, so don't idDelete here
    18401840        srcRing_HH=ffG(srcRing_H,this->gcBasis);
    18411841        idDelete(&srcRing_H);
    1842                
     1842
    18431843        /*Substep 2.2.1
    18441844         * Mark according to G_-\alpha
     
    18461846         * we have to compute an interior point of C(srcRing_HH). For this we need to know the cone
    18471847         * 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
    18491849         * compute the difference accordingly
    18501850        */
     
    18521852        timeval t_markings_start, t_markings_end;
    18531853        gettimeofday(&t_markings_start, 0);
    1854 #endif         
     1854#endif
    18551855        bool markingsAreCorrect=FALSE;
    18561856        dd_MatrixPtr intPointMatrix;
    18571857        int iPMatrixRows=0;
    1858         dd_rowrange aktrow=0;                   
     1858        dd_rowrange aktrow=0;
    18591859        for (int ii=0;ii<IDELEMS(srcRing_HH);ii++)
    18601860        {
    1861                 poly aktpoly=(poly)srcRing_HH->m[ii];//This is a pointer, so don't pDelete
    1862                 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);
    18631863        }
    18641864        /* additionally one row for the standard-simplex and another for a row that becomes 0 during
    18651865         * construction of the differences
    18661866         */
    1867         intPointMatrix = dd_CreateMatrix(iPMatrixRows+2,this->numVars+1); 
    1868         intPointMatrix->numbtype=dd_Integer;    //NOTE: DO NOT REMOVE OR CHANGE TO dd_Rational
    1869        
     1867        intPointMatrix = dd_CreateMatrix(iPMatrixRows+2,this->numVars+1);
     1868        intPointMatrix->numbtype=dd_Integer;    NOTE: DO NOT REMOVE OR CHANGE TO dd_Rational
     1869
    18701870        for (int ii=0;ii<IDELEMS(srcRing_HH);ii++)
    18711871        {
    1872                 markingsAreCorrect=FALSE;       //crucial to initialise here
    1873                 poly aktpoly=srcRing_HH->m[ii]; //Only a pointer, so don't pDelete
     1872                markingsAreCorrect=FALSE;       crucial to initialise here
     1873                poly aktpoly=srcRing_HH->m[ii]; Only a pointer, so don't pDelete
    18741874                /*Comparison of leading monomials is done via exponent vectors*/
    18751875                for (int jj=0;jj<IDELEMS(H);jj++)
     
    18781878                        int *dst_ExpV = (int *)omAlloc((this->numVars+1)*sizeof(int));
    18791879                        pGetExpV(aktpoly,src_ExpV);
    1880                         rChangeCurrRing(tmpRing);       //this ring change is crucial!
     1880                        rChangeCurrRing(tmpRing);       this ring change is crucial!
    18811881                        poly p=pCopy(H->m[ii]);
    18821882                        pGetExpV(p/*pCopy(H->m[ii])*/,dst_ExpV);
     
    18871887                        {
    18881888#ifdef gfan_DEBUG
    1889 //                              cout << src_ExpV[kk] << "," << dst_ExpV[kk] << endl;
     1889                                cout << src_ExpV[kk] << "," << dst_ExpV[kk] << endl;
    18901890#endif
    18911891                                if (src_ExpV[kk]!=dst_ExpV[kk])
     
    18931893                                        expVAreEqual=FALSE;
    18941894                                }
    1895                         }                                                               
     1895                        }
    18961896                        if (expVAreEqual==TRUE)
    18971897                        {
    1898                                 markingsAreCorrect=TRUE; //everything is fine
     1898                                markingsAreCorrect=TRUE; everything is fine
    18991899#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])
    19031903                        omFree(src_ExpV);
    19041904                        omFree(dst_ExpV);
    1905                 }//for (int jj=0;jj<IDELEMS(H);jj++)
    1906                
     1905                }for (int jj=0;jj<IDELEMS(H);jj++)
     1906
    19071907                int *leadExpV=(int *)omAlloc((this->numVars+1)*sizeof(int));
    19081908                if (markingsAreCorrect==TRUE)
     
    19131913                {
    19141914                        rChangeCurrRing(tmpRing);
    1915                         pGetExpV(pHead(H->m[ii]),leadExpV); //We use H->m[ii] as leading monomial
     1915                        pGetExpV(pHead(H->m[ii]),leadExpV); We use H->m[ii] as leading monomial
    19161916                        rChangeCurrRing(srcRing);
    19171917                }
    1918                 /*compute differences of the expvects*/                         
     1918                /*compute differences of the expvects*/
    19191919                while (pNext(aktpoly)!=NULL)
    19201920                {
    19211921                        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)
    19231923                        is not omitted when computing the differences*/
    19241924                        if(markingsAreCorrect==TRUE)
     
    19341934                        int ctr=0;
    19351935                        for (int jj=0;jj<this->numVars;jj++)
    1936                         {                               
    1937                                 /*Store into ddMatrix*/                         
     1936                        {
     1937                                /*Store into ddMatrix*/
    19381938                                if(leadExpV[jj+1]-v[jj+1])
    19391939                                        ctr++;
     
    19411941                        }
    19421942                        /*It ought to be more sensible to avoid 0-rows in the first place*/
    1943 //                      if(ctr==this->numVars)//We have a 0-row
    1944 //                              dd_MatrixRowRemove(&intPointMatrix,aktrow);
    1945 //                      else
     1943                        if(ctr==this->numVars)//We have a 0-row
     1944                                dd_MatrixRowRemove(&intPointMatrix,aktrow);
     1945                        else
    19461946                                aktrow +=1;
    19471947                        omFree(v);
    19481948                }
    19491949                omFree(leadExpV);
    1950         }//for (int ii=0;ii<IDELEMS(srcRing_HH);ii++)
     1950        }for (int ii=0;ii<IDELEMS(srcRing_HH);ii++)
    19511951#ifdef gfanp
    19521952        gettimeofday(&t_markings_end, 0);
     
    19601960        preprocessInequalities(intPointMatrix);
    19611961        /*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 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 //      }
     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        }
    19761976        /*We create a matrix containing the standard simplex
    19771977        * and constraints to assure a strictly positive point
     
    19831983                {
    19841984                        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);
    19871987                }
    19881988                else
     
    20052005        dd_rowindex newpos;
    20062006
    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();
     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();
    20132013        dd_FreeMatrix(intPointMatrix);
    20142014        /*Crude attempt for interior point */
     
    20342034        gettimeofday(&t_dd_end, 0);
    20352035        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
    20382038        /*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 a
    2041         // 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);
    20432043        ring dstRing=rCopy0(tmpRing);
    20442044        int length=iv_weight->length();
     
    20542054        delete iv_weight;
    20552055
    2056         ideal dstRing_I;                       
     2056        ideal dstRing_I;
    20572057        dstRing_I=idrCopyR(srcRing_HH,srcRing);
    2058         idDelete(&srcRing_HH); //Hmm.... causes trouble - no more
    2059         //dstRing_I=idrCopyR(inputIdeal,srcRing);
     2058        idDelete(&srcRing_HH); Hmm.... causes trouble - no more
     2059        dstRing_I=idrCopyR(inputIdeal,srcRing);
    20602060        BITSET save=test;
    20612061        test|=Sy_bit(OPT_REDSB);
    20622062        test|=Sy_bit(OPT_REDTAIL);
    20632063#ifdef gfan_DEBUG
    2064 //      test|=Sy_bit(6);        //OPT_DEBUG
     2064        test|=Sy_bit(6);        //OPT_DEBUG
    20652065#endif
    20662066        ideal tmpI;
    2067         //NOTE Any of the two variants of tmpI={idrCopy(),dstRing_I} does the trick
    2068         //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);
    20692069        tmpI = dstRing_I;
    20702070#ifdef gfanp
     
    20802080#endif
    20812081        idDelete(&tmpI);
    2082         idNorm(dstRing_I);                     
    2083 //      kInterRed(dstRing_I);
     2082        idNorm(dstRing_I);
     2083        kInterRed(dstRing_I);
    20842084        idSkipZeroes(dstRing_I);
    20852085        test=save;
    20862086        /*End of step 3 - reduction*/
    2087                        
    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
     2087
     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
    20912091#ifdef gfan_DEBUG
    20922092        printf("Flipped GB is UCN %i:\n",counter+1);
    20932093        idDebugPrint(dstRing_I);
    20942094        printf("\n");
    2095 #endif 
    2096         idDelete(&dstRing_I);   
    2097         rChangeCurrRing(srcRing);       //return to the ring we started the computation of flipGB in
     2095#endif
     2096        idDelete(&dstRing_I);
     2097        rChangeCurrRing(srcRing);       return to the ring we started the computation of flipGB in
    20982098        rDelete(dstRing);
    20992099#ifdef gfanp
     
    21012101        time_flip += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec));
    21022102#endif
    2103 }//void flip(ideal gb, facet *f)
     2103}void flip(ideal gb, facet *f)
    21042104
    21052105/** \brief A slightly different approach to flipping
     
    21112111* will be from a ring with (a(),dp,C) and our resulting cone from (a(),a(),dp,C). Hence a way
    21122112* 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).
    21162116* Con: It's incredibly ugly
    21172117* Pro: No messing around with readConeFromFile()
     
    21252125#endif
    21262126        const int64vec *fNormal;
    2127         fNormal = f->getRef2FacetNormal();/*->getFacetNormal();*/       //read this->fNormal;
     2127        fNormal = f->getRef2FacetNormal();/*->getFacetNormal();*/       read this->fNormal;
    21282128#ifdef gfan_DEBUG
    21292129        printf("flipping UCN %i over facet(",this->getUCN());
    21302130        fNormal->show(1,0);
    2131         printf(") with UCN %i\n",f->getUCN()); 
     2131        printf(") with UCN %i\n",f->getUCN());
    21322132#endif
    21332133        if(this->getUCN() != f->getUCN())
     
    21372137        }
    21382138        /*1st step: Compute the initial ideal*/
    2139         ideal initialForm=idInit(IDELEMS(gb),this->gcBasis->rank);     
     2139        ideal initialForm=idInit(IDELEMS(gb),this->gcBasis->rank);
    21402140        computeInv( gb, initialForm, *fNormal );
    21412141        ring srcRing=currRing;
    21422142        ring tmpRing;
    2143        
     2143
    21442144        const int64vec *intPointOfFacet;
    21452145        intPointOfFacet=f->getInteriorPoint();
    2146         //Now we need two blocks of ringorder_a!
    2147         //May assume the same situation as in flip() here                       
     2146        Now we need two blocks of ringorder_a!
     2147        May assume the same situation as in flip() here
    21482148        if( (srcRing->order[0]!=ringorder_a/*64*/) && (srcRing->order[1]!=ringorder_a/*64*/) )
    21492149        {
    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));         
     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));
    21532153                tmpRing=rCopyAndAddWeight2(srcRing,ivw/*intPointOfFacet*/,iv);
    21542154                delete iv;delete ivw;
    2155 //              delete iv_foo;
    2156         }
    2157         else 
     2155                delete iv_foo;
     2156        }
     2157        else
    21582158        {
    21592159                int64vec *iv=new int64vec(this->numVars);
     
    21682168                {
    21692169                        A1[jj] = -(*fNormal)[jj];
    2170                         A2[jj] = 1;//-(*fNormal)[jj];//NOTE Do we need this here? This is only the facet ideal
     2170                        A2[jj] = 1;-(*fNormal)[jj];//NOTE Do we need this here? This is only the facet ideal
    21712171                }
    21722172                omFree(tmpRing->wvhdl[0]);
    21732173                if(tmpRing->wvhdl[1]!=NULL)
    21742174                        omFree(tmpRing->wvhdl[1]);
    2175                 tmpRing->wvhdl[0]=(int*)A1;             
     2175                tmpRing->wvhdl[0]=(int*)A1;
    21762176                tmpRing->block1[0]=length;
    2177                 tmpRing->wvhdl[1]=(int*)A2;             
     2177                tmpRing->wvhdl[1]=(int*)A2;
    21782178                tmpRing->block1[1]=length;
    21792179                rComplete(tmpRing);*/
    21802180        }
    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;
    21852185        ina=idrCopyR(initialForm,srcRing);
    21862186        idDelete(&initialForm);
     
    21932193        test|=Sy_bit(OPT_REDSB);
    21942194        test|=Sy_bit(OPT_REDTAIL);
    2195 //      if(gcone::hasHomInput==TRUE)
     2195        if(gcone::hasHomInput==TRUE)
    21962196                H=kStd(ina,NULL,testHomog/*isHomog*/,NULL/*,gcone::hilbertFunction*/);
    2197 //      else
    2198 //              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))
    21992199        test=save;
    22002200#ifdef gfanp
     
    22042204        idSkipZeroes(H);
    22052205        idDelete(&ina);
    2206        
     2206
    22072207        rChangeCurrRing(srcRing);
    22082208        ideal srcRing_H;
    2209         ideal srcRing_HH;                       
     2209        ideal srcRing_HH;
    22102210        srcRing_H=idrCopyR(H,tmpRing);
    2211         //H is needed further below, so don't idDelete here
     2211        H is needed further below, so don't idDelete here
    22122212        srcRing_HH=ffG(srcRing_H,this->gcBasis);
    22132213        idDelete(&srcRing_H);
    2214         //Now BBA(srcRing_HH) with (a(),a(),dp)
     2214        Now BBA(srcRing_HH) with (a(),a(),dp)
    22152215        /* Evil modification of currRing */
    22162216        ring dstRing=rCopy0(tmpRing);
     
    22222222        {
    22232223                A1[jj] = (*intPointOfFacet)[jj];
    2224                 A2[jj] = -(*ivw)[jj];//TODO Or minus (*ivw)[ii] ??? NOTE minus
     2224                A2[jj] = -(*ivw)[jj];TODO Or minus (*ivw)[ii] ??? NOTE minus
    22252225        }
    22262226        omFree(dstRing->wvhdl[0]);
    22272227        if(dstRing->wvhdl[1]!=NULL)
    22282228                omFree(dstRing->wvhdl[1]);
    2229         dstRing->wvhdl[0]=(int*)A1;             
     2229        dstRing->wvhdl[0]=(int*)A1;
    22302230        dstRing->block1[0]=length;
    2231         dstRing->wvhdl[1]=(int*)A2;             
     2231        dstRing->wvhdl[1]=(int*)A2;
    22322232        dstRing->block1[1]=length;
    22332233        rComplete(dstRing);
    22342234        rChangeCurrRing(dstRing);
    2235         ideal dstRing_I;                       
     2235        ideal dstRing_I;
    22362236        dstRing_I=idrCopyR(srcRing_HH,srcRing);
    2237         idDelete(&srcRing_HH); //Hmm.... causes trouble - no more       
     2237        idDelete(&srcRing_HH); Hmm.... causes trouble - no more
    22382238        save=test;
    22392239        test|=Sy_bit(OPT_REDSB);
     
    22422242        tmpI = dstRing_I;
    22432243#ifdef gfanp
    2244 //      timeval t_kStd_start, t_kStd_end;
     2244        timeval t_kStd_start, t_kStd_end;
    22452245        gettimeofday(&t_kStd_start,0);
    22462246#endif
    2247 //      if(gcone::hasHomInput==TRUE)
    2248 //              dstRing_I=kStd(tmpI,NULL,isHomog,NULL/*,gcone::hilbertFunction*/);
    2249 //      else
     2247        if(gcone::hasHomInput==TRUE)
     2248                dstRing_I=kStd(tmpI,NULL,isHomog,NULL/*,gcone::hilbertFunction*/);
     2249        else
    22502250                dstRing_I=kStd(tmpI,NULL,testHomog,NULL);
    22512251#ifdef gfanp
     
    22542254#endif
    22552255        idDelete(&tmpI);
    2256         idNorm(dstRing_I);                     
     2256        idNorm(dstRing_I);
    22572257        idSkipZeroes(dstRing_I);
    22582258        test=save;
    22592259        /*End of step 3 - reduction*/
    2260        
     2260
    22612261        f->setFlipGB(dstRing_I);
    22622262        f->flipRing=rCopy(dstRing);
    22632263        rDelete(tmpRing);
    22642264        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 list
    2267         //of cones in noRevS
     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 list
     2267        of cones in noRevS
    22682268        rChangeCurrRing(srcRing);
    22692269#ifdef gfanp
     
    22712271        time_flip2 += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec));
    22722272#endif
    2273 }//flip2
     2273}flip2
    22742274
    22752275/** \brief Compute initial ideal
     
    22872287        {
    22882288                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)
    22902290                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)
    22922292                initialFormElement=pHead(aktpoly);
    2293 //              int *v=(int *)omAlloc((this->numVars+1)*sizeof(int));
     2293                int *v=(int *)omAlloc((this->numVars+1)*sizeof(int));
    22942294                while(pNext(aktpoly)!=NULL)     /*loop trough terms and check for parallelity*/
    22952295                {
    22962296                        int64vec *check = new int64vec(this->numVars);
    2297                         aktpoly=pNext(aktpoly); //next term
     2297                        aktpoly=pNext(aktpoly); next term
    22982298                        int *v=(int *)omAlloc((this->numVars+1)*sizeof(int));
    2299                         pGetExpV(aktpoly,v);           
     2299                        pGetExpV(aktpoly,v);
    23002300                        /* Convert (int)v into (int64vec)check */
    2301 //                      bool notPar=FALSE;
     2301                        bool notPar=FALSE;
    23022302                        for (int jj=0;jj<this->numVars;jj++)
    23032303                        {
    23042304                                (*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                                }
    23122312                        }
    23132313                        omFree(v);
    2314                         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
     2314                        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
    23182318                        }
    23192319                        delete check;
    2320                 }//while
    2321 //              omFree(v);
     2320                }while
     2321                omFree(v);
    23222322#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;
    23262326#endif
    23272327                /*Now initialFormElement must be added to (ideal)initialForm */
     
    23292329                pDelete(&initialFormElement);
    23302330                omFree(leadExpV);
    2331         }//for
     2331        }for
    23322332#ifdef gfanp
    23332333        gettimeofday(&end, 0);
     
    23432343 * compute the factors \f$ a_i \f$
    23442344 */
    2345 //NOTE: Should be replaced by kNF or kNF2
    2346 //NOTE: Done
    2347 //NOTE: removed with r12286
    2348                
     2345NOTE: Should be replaced by kNF or kNF2
     2346NOTE: Done
     2347NOTE: removed with r12286
     2348
    23492349/** \brief Compute \f$ f-f^{\mathcal{G}} \f$
    23502350*/
    2351 //NOTE: use kNF or kNF2 instead of restOfDivision
     2351NOTE: use kNF or kNF2 instead of restOfDivision
    23522352inline ideal gcone::ffG(const ideal &H, const ideal &G)
    23532353{
     
    23562356        for (int ii=0;ii<size;ii++)
    23572357        {
    2358 //              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
     2358                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
    23682368                res->m[ii]=pCopy(temp3);
    2369                 //res->m[ii]=pSub(temp1,temp2); //buggy         
    2370                 //cout << "res->m["<<ii<<"]=";pWrite(res->m[ii]);
    2371 //              pDelete(&temp1);//TRY
    2372 //              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);
    23732373                pDelete(&temp3);
    23742374        }
    23752375        return res;
    23762376}
    2377        
     2377
    23782378/** \brief Preprocessing of inequlities
    23792379* Do some preprocessing on the matrix of inequalities
     
    23882388        int num_elts=0;
    23892389        int offset=0;*/
    2390         //Remove zeroes (and strictly pos rows?)
     2390        Remove zeroes (and strictly pos rows?)
    23912391        for(int ii=0;ii<ddineq->rowsize;ii++)
    23922392        {
    23932393                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)
    23952395                int posCtr=0;
    23962396                for(int jj=0;jj<this->numVars;jj++)
    23972397                {
    23982398                        (*iv)[jj]=(int)mpq_get_d(ddineq->matrix[ii][jj+1]);
    2399                         if((*iv)[jj]>0)//check for strictly pos rows
     2399                        if((*iv)[jj]>0)check for strictly pos rows
    24002400                                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) )
    24052405                {
    24062406                        dd_MatrixRowRemove(&ddineq,ii+1);
    2407                         ii--;//Yes. This is on purpose
     2407                        ii--;Yes. This is on purpose
    24082408                }
    24092409                delete iv;
    24102410                delete ivNull;
    24112411        }
    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        
     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
    24582458/** \brief Compute a Groebner Basis
    24592459 *
     
    24622462 *\return void
    24632463 */
    2464 inline void gcone::getGB(const ideal &inputIdeal)               
     2464inline void gcone::getGB(const ideal &inputIdeal)
    24652465{
    24662466        BITSET save=test;
     
    24712471        idNorm(gb);
    24722472        idSkipZeroes(gb);
    2473         this->gcBasis=gb;       //write the GB into gcBasis
     2473        this->gcBasis=gb;       write the GB into gcBasis
    24742474        test=save;
    2475 }//void getGB
    2476                
     2475}void getGB
     2476
    24772477/** \brief Compute the negative of a given int64vec
    2478         */             
     2478        */
    24792479static int64vec* ivNeg(/*const*/int64vec *iv)
    2480 {       //Hm, switching to int64vec const int64vec does no longer work
    2481         int64vec *res;// = new int64vec(iv->length());
     2480{       Hm, switching to int64vec const int64vec does no longer work
     2481        int64vec *res; = new int64vec(iv->length());
    24822482        res=iv64Copy(iv);
    2483         *res *= (int)-1;                                               
     2483        *res *= (int)-1;
    24842484        return res;
    24852485}
     
    24892489*
    24902490*/
    2491 static int dotProduct(const int64vec &iva, const int64vec &ivb)                         
    2492 {                       
    2493         int res=0;     
     2491static int dotProduct(const int64vec &iva, const int64vec &ivb)
     2492{
     2493        int res=0;
    24942494        for (int i=0;i<pVariables;i++)
    24952495        {
    2496 // #ifndef NDEBUG
    2497 //      (const_cast<int64vec*>(&iva))->show(1,0); (const_cast<int64vec*>(&ivb))->show(1,0);
    2498 // #endif
     2496 #ifndef NDEBUG
     2497        (const_cast<int64vec*>(&iva))->show(1,0); (const_cast<int64vec*>(&ivb))->show(1,0);
     2498 #endif
    24992499                res = res+(iva[i]*ivb[i]);
    25002500        }
     
    25062506 */
    25072507static bool isParallel(const int64vec &a,const int64vec &b)
    2508 {       
    2509 /*#ifdef gfanp 
     2508{
     2509/*#ifdef gfanp
    25102510        timeval start, end;
    25112511        gettimeofday(&start, 0);
    2512 #endif*/               
     2512#endif*/
    25132513        bool res;
    25142514        int lhs=dotProduct(a,b)*dotProduct(a,b);
    25152515        int rhs=dotProduct(a,a)*dotProduct(b,b);
    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;
     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;
    25212521        return res = (lhs==rhs)?TRUE:FALSE;
    2522 }//bool isParallel
     2522}bool isParallel
    25232523
    25242524/** \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.
    25262526 * Any rational point is automatically converted into an integer.
    25272527 */
    2528 void gcone::interiorPoint( dd_MatrixPtr &M, int64vec &iv) //no const &M here since we want to remove redundant rows
     2528void gcone::interiorPoint( dd_MatrixPtr &M, int64vec &iv) no const &M here since we want to remove redundant rows
    25292529{
    25302530        dd_LPPtr lp,lpInt;
     
    25322532        dd_LPSolverType solver=dd_DualSimplex;
    25332533        dd_LPSolutionPtr lpSol=NULL;
    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                                                                        
     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
    25422542        /*NOTE: Leave the following line commented out!
    25432543        * Otherwise it will slow down computations a great deal
    25442544        * */
    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;}
    25472547        dd_MatrixPtr posRestr=dd_CreateMatrix(this->numVars,this->numVars+1);
    25482548        int jj=1;
     
    25502550        {
    25512551                dd_set_si(posRestr->matrix[ii][jj],1);
    2552                 jj++;                                                   
     2552                jj++;
    25532553        }
    25542554        dd_MatrixAppendTo(&M,posRestr);
     
    25582558        if (lp==NULL){WerrorS("LP is NULL");}
    25592559#ifdef gfan_DEBUG
    2560 //                      dd_WriteLP(stdout,lp);
    2561 #endif 
    2562                                        
     2560                        dd_WriteLP(stdout,lp);
     2561#endif
     2562
    25632563        lpInt=dd_MakeLPforInteriorFinding(lp);
    25642564        if (err!=dd_NoError){WerrorS("Error during dd_MakeLPForInteriorFinding in gcone::interiorPoint");}
    25652565#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);
    25692569        if (err!=dd_NoError)
    25702570        {
    25712571                WerrorS("Error during dd_FindRelativeInterior in gcone::interiorPoint");
    25722572                dd_WriteErrorMessages(stdout, err);
    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");}                                                                       
     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");}
    25762576        lpSol=dd_CopyLPSolution(lpInt);
    2577 //      if (err!=dd_NoError){WerrorS("Error during dd_CopyLPSolution");}
     2577        if (err!=dd_NoError){WerrorS("Error during dd_CopyLPSolution");}
    25782578#ifdef gfan_DEBUG
    25792579        printf("Interior point: ");
     
    25832583        }
    25842584        printf("\n");
    2585 #endif                 
    2586         //NOTE The following strongly resembles parts of makeInt.
    2587         //Maybe merge sometimes
     2585#endif
     2586        NOTE The following strongly resembles parts of makeInt.
     2587        Maybe merge sometimes
    25882588        mpz_t kgV; mpz_init(kgV);
    25892589        mpz_set_str(kgV,"1",10);
     
    26092609        }
    26102610#ifdef gfan_DEBUG
    2611 //                      iv.show();
    2612 //                      cout << endl;
     2611                        iv.show();
     2612                        cout << endl;
    26132613#endif
    26142614        mpq_clear(qkgV);
    26152615        mpz_clear(tmp);
    26162616        mpz_clear(den);
    2617         mpz_clear(kgV);                 
    2618                        
     2617        mpz_clear(kgV);
     2618
    26192619        dd_FreeLPSolution(lpSol);
    26202620        dd_FreeLPData(lpInt);
    26212621        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)
    26262626
    26272627/** Computes an interior point of a cone by taking two interior points a,b from two different facets
    26282628* 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:
    26312631* 1st: There are only two facets who share the only strictly positive ray
    26322632* 2nd: There are at least two facets which have a distinct positive ray
     
    26372637* positive => these lie in a plane and thus their sum is not from relative interior.
    26382638* So let's just sum up all rays, find one strictly positive and shift the point along that ray
    2639 * 
     2639*
    26402640* Used by noRevS
    26412641*NOTE no longer used nor maintained. MM Mar 9, 2010
    26422642*/
    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        
     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
    27942794/** \brief Copy a ring and add a weighted ordering in first place
    2795  * 
     2795 *
    27962796 */
    2797 ring gcone::rCopyAndAddWeight(const ring &r, int64vec *ivw)                             
     2797ring gcone::rCopyAndAddWeight(const ring &r, int64vec *ivw)
    27982798{
    27992799        ring res=rCopy0(r);
    28002800        int jj;
    2801                        
     2801
    28022802        omFree(res->order);
    28032803        res->order =(int *)omAlloc0(4*sizeof(int/*64*/));
     
    28082808        omfree(res->wvhdl);
    28092809        res->wvhdl =(int **)omAlloc0(4*sizeof(int/*64*/**));
    2810                        
     2810
    28112811        res->order[0]=ringorder_a/*64*/;
    28122812        res->block0[0]=1;
    28132813        res->block1[0]=res->N;
    2814         res->order[1]=ringorder_dp;     //basically useless, since that should never be used                   
     2814        res->order[1]=ringorder_dp;     basically useless, since that should never be used
    28152815        res->block0[1]=1;
    28162816        res->block1[1]=res->N;
     
    28202820        int/*64*/ *A=(int/*64*/ *)omAlloc0(length*sizeof(int/*64*/));
    28212821        for (jj=0;jj<length;jj++)
    2822         {                               
     2822        {
    28232823                A[jj]=(*ivw)[jj];
    28242824                if((*ivw)[jj]>=INT_MAX) WarnS("A[jj] exceeds INT_MAX in gcone::rCopyAndAddWeight!\n");
    2825         }                       
     2825        }
    28262826        res->wvhdl[0]=(int *)A;
    28272827        res->block1[0]=length;
    2828                        
     2828
    28292829        rComplete(res);
    28302830        return res;
    2831 }//rCopyAndAdd
    2832                
    2833 ring gcone::rCopyAndAddWeight2(const ring &r,const int64vec *ivw, const int64vec *fNormal)                             
     2831}rCopyAndAdd
     2832
     2833ring gcone::rCopyAndAddWeight2(const ring &r,const int64vec *ivw, const int64vec *fNormal)
    28342834{
    28352835        ring res=rCopy0(r);
    2836                        
     2836
    28372837        omFree(res->order);
    28382838        res->order =(int *)omAlloc0(5*sizeof(int/*64*/));
     
    28432843        omfree(res->wvhdl);
    28442844        res->wvhdl =(int **)omAlloc0(5*sizeof(int/*64*/**));
    2845                        
     2845
    28462846        res->order[0]=ringorder_a/*64*/;
    28472847        res->block0[0]=1;
     
    28502850        res->block0[1]=1;
    28512851        res->block1[1]=res->N;
    2852        
     2852
    28532853        res->order[2]=ringorder_dp;
    28542854        res->block0[2]=1;
    28552855        res->block1[2]=res->N;
    2856        
     2856
    28572857        res->order[3]=ringorder_C;
    28582858
     
    28612861        int/*64*/ *A2=(int/*64*/ *)omAlloc0(length*sizeof(int/*64*/));
    28622862        for (int jj=0;jj<length;jj++)
    2863         {                               
     2863        {
    28642864                A1[jj]=(*ivw)[jj];
    28652865                A2[jj]=-(*fNormal)[jj];
    28662866                if((*ivw)[jj]>=INT_MAX || (*fNormal)[jj]>=INT_MAX) WarnS("A[jj] exceeds INT_MAX in gcone::rCopyAndAddWeight2!\n");
    2867         }                       
     2867        }
    28682868        res->wvhdl[0]=(int *)A1;
    28692869        res->block1[0]=length;
     
    28732873        return res;
    28742874}
    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                
     2875
     2876NOTE 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
    28862886/** \brief Checks whether a given facet is a search facet
    28872887 * Determines whether a given facet of a cone is the search facet of a neighbouring cone
     
    28902890 * that is first crossed during the generic walk.
    28912891 * 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.
    28932893*/
    2894 //removed with r12286
    2895                
     2894removed with r12286
     2895
    28962896/** \brief Check for equality of two intvecs
    28972897 */
     
    29092909        return res;
    29102910}
    2911                
     2911
    29122912/** \brief The reverse search algorithm
    29132913 */
    2914 //removed with r12286
     2914removed with r12286
    29152915/** \brief Compute the lineality/homogeneity space
    29162916* It is the kernel of the inequality matrix Ax=0
     
    29212921        dd_MatrixPtr res;
    29222922        dd_MatrixPtr ddineq;
    2923         ddineq=dd_CopyMatrix(this->ddFacets);   
    2924         //Add a row of 0s in 0th place
     2923        ddineq=dd_CopyMatrix(this->ddFacets);
     2924        Add a row of 0s in 0th place
    29252925        dd_MatrixPtr ddAppendRowOfZeroes=dd_CreateMatrix(1,this->numVars+1);
    29262926        dd_MatrixPtr ddFoo=dd_AppendMatrix(ddAppendRowOfZeroes,ddineq);
     
    29292929        ddineq=dd_CopyMatrix(ddFoo);
    29302930        dd_FreeMatrix(ddFoo);
    2931         //Cohen starts here
    2932         int dimKer=0;//Cohen calls this r
    2933         int m=ddineq->rowsize;//Rows
    2934         int n=ddineq->colsize;//Cols
     2931        Cohen starts here
     2932        int dimKer=0;Cohen calls this r
     2933        int m=ddineq->rowsize;Rows
     2934        int n=ddineq->colsize;Cols
    29352935        int c[m+1];
    29362936        int d[n+1];
     
    29382938                c[ii]=0;
    29392939        for(int ii=0;ii<n;ii++)
    2940                 d[ii]=0;       
    2941        
     2940                d[ii]=0;
     2941
    29422942        for(int k=1;k<n;k++)
    29432943        {
    2944                 //Let's find a j s.t. m[j][k]!=0 && c[j]=0             
    2945                 int condCtr=0;//Check each row for zeroness
     2944                Let's find a j s.t. m[j][k]!=0 && c[j]=0
     2945                int condCtr=0;Check each row for zeroness
    29462946                for(int j=1;j<m;j++)
    29472947                {
     
    29552955                                mpq_set(ratd,quot);
    29562956                                mpq_canonicalize(ratd);
    2957                
     2957
    29582958                                mpq_set_str(ddineq->matrix[j][k],"-1",10);
    29592959                                for(int ss=k+1;ss<n;ss++)
    29602960                                {
    29612961                                        mpq_t prod; mpq_init(prod);
    2962                                         mpq_mul(prod, ratd, ddineq->matrix[j][ss]);                             
     2962                                        mpq_mul(prod, ratd, ddineq->matrix[j][ss]);
    29632963                                        mpq_set(ddineq->matrix[j][ss],prod);
    29642964                                        mpq_canonicalize(ddineq->matrix[j][ss]);
    29652965                                        mpq_clear(prod);
    2966                                 }               
     2966                                }
    29672967                                for(int ii=1;ii<m;ii++)
    29682968                                {
     
    29702970                                        {
    29712971                                                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);
    29732973                                                for(int ss=k+1;ss<n;ss++)
    29742974                                                {
     
    29842984                                        }
    29852985                                }
    2986                                 c[j]=k;         
     2986                                c[j]=k;
    29872987                                d[k]=j;
    2988                                 mpq_clear(quot); mpq_clear(ratd); mpq_clear(one);       
     2988                                mpq_clear(quot); mpq_clear(ratd); mpq_clear(one);
    29892989                        }
    29902990                        else
    29912991                                condCtr++;
    2992                 }                       
    2993                 if(condCtr==m-1)        //Why -1 ???
     2992                }
     2993                if(condCtr==m-1)        Why -1 ???
    29942994                {
    29952995                        dimKer++;
    29962996                        d[k]=0;
    2997 //                      break;//goto _4;
    2998                 }//else{
     2997                        break;//goto _4;
     2998                }else{
    29992999                /*Eliminate*/
    3000         }//for(k
    3001         /*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);
    30033003        res = dd_CreateMatrix(dimKer,this->numVars+1);
    30043004        int row=-1;
     
    30123012                                if(d[ii]>0)
    30133013                                        mpq_set(res->matrix[row][ii],ddineq->matrix[d[ii]][kk]);
    3014                                 else if(ii==kk)                         
     3014                                else if(ii==kk)
    30153015                                        mpq_set_str(res->matrix[row][ii],"1",10);
    30163016                                mpq_canonicalize(res->matrix[row][ii]);
     
    30203020        dd_FreeMatrix(ddineq);
    30213021        return(res);
    3022         //Better safe than sorry:
    3023         //NOTE dd_LinealitySpace contains RATIONAL ENTRIES
    3024         //Therefore if you need integer ones: CALL gcone::makeInt(...) method
    3025 }       
     3022        Better safe than sorry:
     3023        NOTE dd_LinealitySpace contains RATIONAL ENTRIES
     3024        Therefore if you need integer ones: CALL gcone::makeInt(...) method
     3025}
    30263026
    30273027
     
    30343034 */
    30353035void gcone::noRevS(gcone &gcRoot, bool usingIntPoint)
    3036 {       
    3037         facet *SearchListRoot = new facet(); //The list containing ALL facets we come across
     3036{
     3037        facet *SearchListRoot = new facet(); The list containing ALL facets we come across
    30383038        facet *SearchListAct;
    30393039        SearchListAct = NULL;
    3040         //SearchListAct = SearchListRoot;                       
     3040        SearchListAct = SearchListRoot;
    30413041        gcone *gcAct;
    30423042        gcAct = &gcRoot;
    3043         gcone *gcPtr;   //Pointer to end of linked list of cones
     3043        gcone *gcPtr;   Pointer to end of linked list of cones
    30443044        gcPtr = &gcRoot;
    3045         gcone *gcNext;  //Pointer to next cone to be visited
     3045        gcone *gcNext;  Pointer to next cone to be visited
    30463046        gcNext = &gcRoot;
    30473047        gcone *gcHead;
    3048         gcHead = &gcRoot;                       
     3048        gcHead = &gcRoot;
    30493049        facet *fAct;
    3050         fAct = gcAct->facetPtr;                         
     3050        fAct = gcAct->facetPtr;
    30513051        ring rAct;
    30523052        rAct = currRing;
    3053         int UCNcounter=gcAct->getUCN(); 
     3053        int UCNcounter=gcAct->getUCN();
    30543054#ifdef gfan_DEBUG
    30553055        printf("NoRevs\n");
    30563056        printf("Facets are:\n");
    30573057        gcAct->showFacets();
    3058 #endif                 
     3058#endif
    30593059        /*Compute lineality space here
    30603060        * Afterwards static dd_MatrixPtr gcone::dd_LinealitySpace is set*/
    30613061        if(dd_LinealitySpace==NULL)
    30623062                dd_LinealitySpace = gcAct->computeLinealitySpace();
    3063         /*End of lineality space computation*/         
    3064         //gcAct->getCodim2Normals(*gcAct);
     3063        /*End of lineality space computation*/
     3064        gcAct->getCodim2Normals(*gcAct);
    30653065        if(fAct->codim2Ptr==NULL)
    3066                 gcAct->getExtremalRays(*gcAct);         
     3066                gcAct->getExtremalRays(*gcAct);
    30673067        /* Make a copy of the facet list of first cone
    30683068           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;
    30713071        facet *sl2Root;
    3072         facet *sl2Act;*/                       
     3072        facet *sl2Act;*/
    30733073        for(int ii=0;ii<this->numFacets;ii++)
    30743074        {
    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.
    30763076                if(fAct->isFlippable==TRUE)
    30773077                {
    30783078                        /*Using shallow copy here*/
    30793079#ifdef SHALLOW
    3080                         if( ii==0 || (ii>0 && SearchListAct==NULL) ) //1st facet may be non-flippable
     3080                        if( ii==0 || (ii>0 && SearchListAct==NULL) ) 1st facet may be non-flippable
    30813081                        {
    30823082                                if(SearchListRoot!=NULL) delete(SearchListRoot);
    30833083                                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!
    30853085                        }
    30863086                        else
    3087                         {                       
     3087                        {
    30883088                                SearchListAct->next = fAct->shallowCopy(*fAct);
    3089                                 SearchListAct = SearchListAct->next;                                           
     3089                                SearchListAct = SearchListAct->next;
    30903090                        }
    30913091                        fAct=fAct->next;
     
    30943094                        int64vec *fNormal;
    30953095                        fNormal = fAct->getFacetNormal();
    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!
     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!
    30993099                        }
    31003100                        else
    3101                         {                       
     3101                        {
    31023102                                SearchListAct->next = new facet();
    3103                                 SearchListAct = SearchListAct->next;                                           
     3103                                SearchListAct = SearchListAct->next;
    31043104                        }
    31053105                        SearchListAct->setFacetNormal(fNormal);
     
    31073107                        SearchListAct->numCodim2Facets=fAct->numCodim2Facets;
    31083108                        SearchListAct->isFlippable=TRUE;
    3109                         //Copy int point as well
     3109                        Copy int point as well
    31103110                        int64vec *ivIntPt;
    31113111                        ivIntPt = fAct->getInteriorPoint();
    31123112                        SearchListAct->setInteriorPoint(ivIntPt);
    31133113                        delete(ivIntPt);
    3114                         //Copy codim2-facets
     3114                        Copy codim2-facets
    31153115                        facet *codim2Act;
    3116                         codim2Act = NULL;                       
     3116                        codim2Act = NULL;
    31173117                        facet *sl2Root;
    3118                         facet *sl2Act;                 
     3118                        facet *sl2Act;
    31193119                        codim2Act=fAct->codim2Ptr;
    31203120                        SearchListAct->codim2Ptr = new facet(2);
    31213121                        sl2Root = SearchListAct->codim2Ptr;
    3122                         sl2Act = sl2Root;                       
     3122                        sl2Act = sl2Root;
    31233123                        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++)
    31253125                        {
    31263126                                int64vec *f2Normal;
    31273127                                f2Normal = codim2Act->getFacetNormal();
    31283128                                if(jj==0)
    3129                                 {                                               
     3129                                {
    31303130                                        sl2Act = sl2Root;
    31313131                                        sl2Act->setFacetNormal(f2Normal);
     
    31373137                                        sl2Act->setFacetNormal(f2Normal);
    31383138                                }
    3139                                 delete f2Normal;                               
     3139                                delete f2Normal;
    31403140                                codim2Act = codim2Act->next;
    31413141                        }
     
    31433143                        delete fNormal;
    31443144#endif
    3145                 }//if(fAct->isFlippable==TRUE)                 
     3145                }if(fAct->isFlippable==TRUE)
    31463146                else {fAct = fAct->next;}
    3147         }//End of copying facets into SLA
    3148        
    3149         SearchListAct = SearchListRoot; //Set to beginning of list
     3147        }End of copying facets into SLA
     3148
     3149        SearchListAct = SearchListRoot; Set to beginning of list
    31503150        /*Make SearchList doubly linked*/
    31513151#ifndef NDEBUG
     
    31643164                if(SearchListAct->next!=NULL){
    31653165#endif
    3166                         SearchListAct->next->prev = SearchListAct;                                     
     3166                        SearchListAct->next->prev = SearchListAct;
    31673167                }
    31683168                SearchListAct = SearchListAct->next;
    31693169        }
    3170         SearchListAct = SearchListRoot; //Set to beginning of List
    3171        
    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);
    31743174        /*End of initialisation*/
    3175        
     3175
    31763176        fAct = SearchListAct;
    31773177        /*2nd step
    31783178          Choose a facet from SearchList, flip it and forget the previous cone
    31793179          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;
    31843184                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 that                   
     3185                while( (fAct->getUCN() == fAct->next->getUCN()) )
     3186                {       Since SLA should only contain flippables there should be no need to check for that
    31873187                        gcAct->flip2(gcAct->gcBasis,fAct);
    3188                         //NOTE rCopy needed?
     3188                        NOTE rCopy needed?
    31893189                        ring rTmp=rCopy(fAct->flipRing);
    31903190                        rComplete(rTmp);
    31913191                        rChangeCurrRing(rTmp);
    3192                         gcone *gcTmp = new gcone::gcone(*gcAct,*fAct);//copy constructor!
     3192                        gcone *gcTmp = new gcone::gcone(*gcAct,*fAct);copy constructor!
    31933193                        /* Now gcTmp->gcBasis and gcTmp->baseRing are set from fAct->flipGB and fAct->flipRing.
    31943194                         * Since we come at most once across a given facet from gcAct->facetPtr we can delete them.
     
    32003200                        */
    32013201                        idDelete((ideal *)&fAct->flipGB);
    3202                         rDelete(fAct->flipRing);                       
     3202                        rDelete(fAct->flipRing);
    32033203                        gcTmp->getConeNormals(gcTmp->gcBasis/*, FALSE*/);
    3204 //                      gcTmp->getCodim2Normals(*gcTmp);
     3204                        gcTmp->getCodim2Normals(*gcTmp);
    32053205                        gcTmp->getExtremalRays(*gcTmp);
    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();
     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();
    32123212                        gcTmp->replaceDouble_ringorder_a_ByASingleOne();
    3213                         //gcTmp->ddFacets should not be needed anymore, so
     3213                        gcTmp->ddFacets should not be needed anymore, so
    32143214                        dd_FreeMatrix(gcTmp->ddFacets);
    32153215#ifdef gfan_DEBUG
    3216 //                      gcTmp->showFacets(1);
     3216                        gcTmp->showFacets(1);
    32173217#endif
    32183218                        /*add facets to SLA here*/
     
    32283228  #endif
    32293229                        SearchListRoot=tmp;
    3230                         //SearchListRoot=gcTmp->enqueue2/*NewFacets*/(SearchListRoot);
    3231 #else 
     3230                        SearchListRoot=gcTmp->enqueue2/*NewFacets*/(SearchListRoot);
     3231#else
    32323232                        SearchListRoot=gcTmp->enqueueNewFacets(SearchListRoot);
    3233 #endif //ifdef SHALLOW
    3234 //                      gcTmp->writeConeToFile(*gcTmp);
     3233#endif ifdef SHALLOW
     3234                        gcTmp->writeConeToFile(*gcTmp);
    32353235                        if(gfanHeuristic==1)
    32363236                        {
    32373237                                gcTmp->writeConeToFile(*gcTmp);
    3238                                 idDelete((ideal*)&gcTmp->gcBasis);//Whonder why?
     3238                                idDelete((ideal*)&gcTmp->gcBasis);Whonder why?
    32393239                                rDelete(gcTmp->baseRing);
    3240                         }                       
     3240                        }
    32413241#ifdef gfan_DEBUG
    32423242                        if(SearchListRoot!=NULL)
    32433243                                showSLA(*SearchListRoot);
    3244 #endif                 
     3244#endif
    32453245                        rChangeCurrRing(gcAct->baseRing);
    32463246                        rDelete(rTmp);
    3247                         //doubly linked for easier removal
     3247                        doubly linked for easier removal
    32483248                        gcTmp->prev = gcPtr;
    32493249                        gcPtr->next=gcTmp;
    32503250                        gcPtr=gcPtr->next;
    3251                         //Cleverly disguised exit condition follows
     3251                        Cleverly disguised exit condition follows
    32523252                        if(fAct->getUCN() == fAct->next->getUCN())
    32533253                        {
    32543254                                printf("Switching UCN from %i to %i\n",fAct->getUCN(),fAct->next->getUCN());
    3255                                 fAct=fAct->next;                               
     3255                                fAct=fAct->next;
    32563256                        }
    32573257                        else
    32583258                        {
    3259                                 //rDelete(gcAct->baseRing);
    3260 //                              printf("break\n");
     3259                                rDelete(gcAct->baseRing);
     3260                                printf("break\n");
    32613261                                break;
    32623262                        }
    3263 //                      fAct=fAct->next;
    3264                 }//while( ( (fAct->next!=NULL) && (fAct->getUCN()==fAct->next->getUCN() ) ) );         
    3265                 //Search for cone with smallest UCN
     3263                        fAct=fAct->next;
     3264                }while( ( (fAct->next!=NULL) && (fAct->getUCN()==fAct->next->getUCN() ) ) );
     3265                Search for cone with smallest UCN
    32663266#ifndef NDEBUG
    3267   #if SIZEOF_LONG==8    //64 bit
     3267  #if SIZEOF_LONG==8    64 bit
    32683268                while(gcNext!=(gcone * const)0xfbfbfbfbfbfbfbfb && SearchListRoot!=NULL)
    32693269  #elif SIZEOF_LONG == 4
     
    32723272#endif
    32733273#ifdef NDEBUG
    3274                 while(gcNext!=NULL && SearchListRoot!=NULL)     
    3275 #endif
    3276                 {                       
     3274                while(gcNext!=NULL && SearchListRoot!=NULL)
     3275#endif
     3276                {
    32773277                        if( gcNext->getUCN() == SearchListRoot->getUCN() )
    32783278                        {
     
    32803280                                {
    32813281                                        gcAct = gcNext;
    3282                                         //Seems better to not to use rCopy here
    3283 //                                      rAct=rCopy(gcAct->baseRing);
     3282                                        Seems better to not to use rCopy here
     3283                                        rAct=rCopy(gcAct->baseRing);
    32843284                                        rAct=gcAct->baseRing;
    32853285                                        rComplete(rAct);
    3286                                         rChangeCurrRing(rAct);                                         
     3286                                        rChangeCurrRing(rAct);
    32873287                                        break;
    32883288                                }
     
    32903290                                {
    32913291                                        gcone *gcDel;
    3292                                         gcDel = gcAct;                                 
     3292                                        gcDel = gcAct;
    32933293                                        gcAct = gcNext;
    3294                                         //Read st00f from file &
    3295                                         //implant the GB into gcAct
     3294                                        Read st00f from file &
     3295                                        implant the GB into gcAct
    32963296                                        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
    33023302                                        assure that gcAct->gcBasis belongs to the right ring*/
    33033303                                        rAct=gcAct->baseRing;
     
    33053305                                        rChangeCurrRing(rAct);
    33063306                                        break;
    3307                                 }                               
     3307                                }
    33083308                        }
    33093309                        else if(gcNext->getUCN() < SearchListRoot->getUCN() )
    33103310                        {
    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?
    33133313                        }
    33143314                        /*else
     
    33203320                                        if(gcDel->getUCN()!=1)
    33213321                                                rDelete(gcDel->baseRing);
    3322                                 }                                       
    3323                         }*/                     
     3322                                }
     3323                        }*/
    33243324                        gcNext = gcNext->next;
    33253325                }
    33263326                UCNcounter++;
    3327                 SearchListAct = SearchListRoot;         
     3327                SearchListAct = SearchListRoot;
    33283328        }
    33293329        printf("\nFound %i cones - terminating\n", counter);
    3330 }//void noRevS(gcone &gc)       
    3331                
    3332                
     3330}void noRevS(gcone &gc)
     3331
     3332
    33333333/** \brief Make a set of rational vectors into integers
    33343334 *
     
    33393339 */
    33403340void gcone::makeInt(const dd_MatrixPtr &M, const int line, int64vec &n)
    3341 {                       
     3341{
    33423342        mpz_t *denom = new mpz_t[this->numVars];
    33433343        for(int ii=0;ii<this->numVars;ii++)
     
    33453345                mpz_init_set_str(denom[ii],"0",10);
    33463346        }
    3347                
     3347
    33483348        mpz_t kgV,tmp;
    33493349        mpz_init(kgV);
    33503350        mpz_init(tmp);
    3351                        
     3351
    33523352        for (int ii=0;ii<(M->colsize)-1;ii++)
    33533353        {
     
    33563356                mpq_get_den(z,M->matrix[line-1][ii+1]);
    33573357                mpz_set( denom[ii], z);
    3358                 mpz_clear(z);                           
    3359         }
    3360                                                
     3358                mpz_clear(z);
     3359        }
     3360
    33613361        /*Compute lcm of the denominators*/
    33623362        mpz_set(tmp,denom[0]);
     
    33643364        {
    33653365                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);
    33693369        /*Multiply the nominators by kgV*/
    33703370        mpq_t qkgV,res;
     
    33723372        mpq_set_str(qkgV,"1",10);
    33733373        mpq_canonicalize(qkgV);
    3374                        
     3374
    33753375        mpq_init(res);
    33763376        mpq_set_str(res,"1",10);
    33773377        mpq_canonicalize(res);
    3378                        
     3378
    33793379        mpq_set_num(qkgV,kgV);
    3380                        
    3381 //      mpq_canonicalize(qkgV);
    3382 //      int ggT=1;
     3380
     3381        mpq_canonicalize(qkgV);
     3382        int ggT=1;
    33833383        for (int ii=0;ii<(M->colsize)-1;ii++)
    33843384        {
    33853385                mpq_mul(res,qkgV,M->matrix[line-1][ii+1]);
    33863386                n[ii]=(int64)mpz_get_d(mpq_numref(res));
    3387 //              ggT=int64gcd(ggT,n[ii]);
     3387                ggT=int64gcd(ggT,n[ii]);
    33883388        }
    33893389        int64 ggT=n[0];
    33903390        for(int ii=0;ii<this->numVars;ii++)
    3391                 ggT=int64gcd(ggT,n[ii]);       
    3392         //Normalisation
     3391                ggT=int64gcd(ggT,n[ii]);
     3392        Normalisation
    33933393        if(ggT>1)
    33943394        {
     
    33983398        delete [] denom;
    33993399        mpz_clear(kgV);
    3400         mpq_clear(qkgV); mpq_clear(res);                       
    3401                        
     3400        mpq_clear(qkgV); mpq_clear(res);
     3401
    34023402}
    34033403/**
    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
    34053405 * divide it out. Thus we get a normalized representation of each
    34063406 * (codim-2)-facet normal, i.e. a primitive vector
    34073407 * Actually we now also normalize the facet normals.
    34083408 */
    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 
     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
    34643464 * The searchlist (SLA for short) is implemented as a FIFO
    34653465 * Checks are done as follows:
    34663466 * 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
    34683468 *      facet from SLA and do not add fAct.
    34693469 * It may very well happen, that SLA=\f$ \emptyset \f$ but we do not have checked all fActs yet. In this case we
     
    34803480        facet *slHead;
    34813481        slHead = f;
    3482         facet *slAct;   //called with f=SearchListRoot
     3482        facet *slAct;   called with f=SearchListRoot
    34833483        slAct = f;
    3484         facet *slEnd;   //Pointer to end of SLA
     3484        facet *slEnd;   Pointer to end of SLA
    34853485        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
    34873487        facet *fAct;
    34883488        fAct = this->facetPtr;
     
    34943494        volatile facet *deleteMarker;
    34953495        deleteMarker = NULL;
    3496                        
     3496
    34973497        /** \brief  Flag to mark a facet that might be added
    34983498         * The following case may occur:
     
    35003500         * This does however not mean that there does not exist a facet behind the current slAct that is actually equal
    35013501         * 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.
    35033503         * If slAct->next==NULL AND maybe==TRUE we know, that fAct must be added
    35043504         */
    35053505
    3506         /**A facet was removed, lengthOfSearchlist-- thus we must not rely on 
     3506        /**A facet was removed, lengthOfSearchlist-- thus we must not rely on
    35073507         * if(notParallelCtr==lengthOfSearchList) but rather
    35083508         * if( (notParallelCtr==lengthOfSearchList && removalOccured==FALSE)
     
    35133513                slEnd=slEnd->next;
    35143514        }
    3515         /*1st step: compare facetNormals*/                     
     3515        /*1st step: compare facetNormals*/
    35163516        while(fAct!=NULL)
    3517         {                                               
     3517        {
    35183518                if(fAct->isFlippable==TRUE)
    35193519                {
    35203520                        int64vec *fNormal=NULL;
    3521                         fNormal=fAct->getFacetNormal();                 
     3521                        fNormal=fAct->getFacetNormal();
    35223522                        slAct = slHead;
    3523                         /*If slAct==NULL and fAct!=NULL 
     3523                        /*If slAct==NULL and fAct!=NULL
    35243524                        we just copy all remaining facets into SLA*/
    35253525                        if(slAct==NULL)
     
    35293529                                while(fCopy!=NULL)
    35303530                                {
    3531                                         if(fCopy->isFlippable==TRUE)//We must assure fCopy is also flippable
     3531                                        if(fCopy->isFlippable==TRUE)We must assure fCopy is also flippable
    35323532                                        {
    35333533                                                if(slAct==NULL)
    35343534                                                {
    3535                                                         slAct = new facet(*fCopy/*,TRUE*/);//copy constructor
    3536                                                         slHead = slAct;                                                         
     3535                                                        slAct = new facet(*fCopy/*,TRUE*/);copy constructor
     3536                                                        slHead = slAct;
    35373537                                                }
    35383538                                                else
     
    35443544                                        fCopy = fCopy->next;
    35453545                                }
    3546                                 break;//Where does this lead to?
     3546                                break;Where does this lead to?
    35473547                        }
    35483548                        /*End of dumping into SLA*/
     
    35543554#ifdef gfan_DEBUG
    35553555                                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);
    35593559                                if(areEqual2(fAct,slAct))
    3560                                 {                                       
     3560                                {
    35613561                                        deleteMarker = slAct;
    35623562                                        if(slAct==slHead)
    3563                                         {                                               
    3564                                                 slHead = slAct->next;                                           
     3563                                        {
     3564                                                slHead = slAct->next;
    35653565                                                if(slHead!=NULL)
    35663566                                                        slHead->prev = NULL;
     
    35703570                                                slEnd=slEnd->prev;
    35713571                                                slEnd->next = NULL;
    3572                                         }                                                               
     3572                                        }
    35733573                                        else
    35743574                                        {
     
    35803580                                        if(deleteMarker!=NULL)
    35813581                                        {
    3582 //                                              delete deleteMarker;
    3583 //                                              deleteMarker=NULL;
     3582                                                delete deleteMarker;
     3583                                                deleteMarker=NULL;
    35843584                                        }
    35853585#ifdef gfan_DEBUG
     
    35873587#endif
    35883588                                        delete slNormal;
    3589                                         break;//leave the while loop, since we found fAct=slAct thus delete slAct and do not add fAct
     3589                                        break;leave the while loop, since we found fAct=slAct thus delete slAct and do not add fAct
    35903590                                }
    35913591                                slAct = slAct->next;
     
    35963596                                slAct = slAct->next;*/
    35973597                                if(deleteMarker!=NULL)
    3598                                 {                                               
    3599 //                                      delete deleteMarker;
    3600 //                                      deleteMarker=NULL;
     3598                                {
     3599                                        delete deleteMarker;
     3600                                        deleteMarker=NULL;
    36013601                                }
    36023602                                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)
    36053605                        if(removalOccured==FALSE)
    36063606                        {
    36073607#ifdef gfan_DEBUG
    3608 //                              cout << "Adding facet (";fNormal->show(1,0);cout << ") to SLA " << endl;
    3609 #endif
    3610                                 //Add fAct to SLA
     3608                                cout << "Adding facet (";fNormal->show(1,0);cout << ") to SLA " << endl;
     3609#endif
     3610                                Add fAct to SLA
    36113611                                facet *marker;
    36123612                                marker = slEnd;
     
    36153615
    36163616                                slEnd->next = new facet();
    3617                                 slEnd = slEnd->next;//Update slEnd
     3617                                slEnd = slEnd->next;Update slEnd
    36183618                                facet *slEndCodim2Root;
    36193619                                facet *slEndCodim2Act;
    36203620                                slEndCodim2Root = slEnd->codim2Ptr;
    36213621                                slEndCodim2Act = slEndCodim2Root;
    3622                                                                
     3622
    36233623                                slEnd->setUCN(this->getUCN());
    36243624                                slEnd->isFlippable = TRUE;
    36253625                                slEnd->setFacetNormal(fNormal);
    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());
     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());
    36313631                                slEnd->interiorPoint = fAct->interiorPoint;
    36323632                                slEnd->prev = marker;
    3633                                 //Copy codim2-facets
    3634                                 //int64vec *f2Normal=new int64vec(this->numVars);
     3633                                Copy codim2-facets
     3634                                int64vec *f2Normal=new int64vec(this->numVars);
    36353635                                while(f2Act!=NULL)
    36363636                                {
     
    36403640                                        {
    36413641                                                slEndCodim2Root = new facet(2);
    3642                                                 slEnd->codim2Ptr = slEndCodim2Root;                     
     3642                                                slEnd->codim2Ptr = slEndCodim2Root;
    36433643                                                slEndCodim2Root->setFacetNormal(f2Normal);
    36443644                                                slEndCodim2Act = slEndCodim2Root;
    36453645                                        }
    3646                                         else                                   
     3646                                        else
    36473647                                        {
    36483648                                                slEndCodim2Act->next = new facet(2);
     
    36533653                                        delete f2Normal;
    36543654                                }
    3655                                 gcone::lengthOfSearchList++;                                                   
    3656                         }//if( (notParallelCtr==lengthOfSearchList && removalOccured==FALSE) ||
     3655                                gcone::lengthOfSearchList++;
     3656                        }if( (notParallelCtr==lengthOfSearchList && removalOccured==FALSE) ||
    36573657                        fAct = fAct->next;
    36583658                        delete fNormal;
    3659 //                      delete slNormal;
    3660                 }//if(fAct->isFlippable==TRUE)
     3659                        delete slNormal;
     3660                }if(fAct->isFlippable==TRUE)
    36613661                else
    36623662                {
     
    36653665                if(gcone::maxSize<gcone::lengthOfSearchList)
    36663666                        gcone::maxSize= gcone::lengthOfSearchList;
    3667         }//while(fAct!=NULL)
     3667        }while(fAct!=NULL)
    36683668#ifdef gfanp
    36693669        gettimeofday(&end, 0);
    36703670        time_enqueue += (end.tv_sec - start.tv_sec + 1e-6*(end.tv_usec - start.tv_usec));
    3671 #endif                                         
     3671#endif
    36723672        return slHead;
    3673 }//addC2N
     3673}addC2N
    36743674
    36753675/** Enqueuing using shallow copies*/
     
    36833683        facet *slHead;
    36843684        slHead = f;
    3685         facet *slAct;   //called with f=SearchListRoot
     3685        facet *slAct;   called with f=SearchListRoot
    36863686        slAct = f;
    3687         static facet *slEnd;    //Pointer to end of SLA
     3687        static facet *slEnd;    Pointer to end of SLA
    36883688        if(slEnd==NULL)
    36893689                slEnd = f;
    3690        
     3690
    36913691        facet *fAct;
    3692         fAct = this->facetPtr;//New facets to compare
     3692        fAct = this->facetPtr;New facets to compare
    36933693        facet *codim2Act;
    36943694        codim2Act = this->facetPtr->codim2Ptr;
     
    36973697        {
    36983698                slEnd=slEnd->next;
    3699         }       
     3699        }
    37003700        while(fAct!=NULL)
    37013701        {
     
    37083708                                printf("Zero length SLA\n");
    37093709                                facet *fCopy;
    3710                                 fCopy = fAct;                           
     3710                                fCopy = fAct;
    37113711                                while(fCopy!=NULL)
    37123712                                {
    3713                                         if(fCopy->isFlippable==TRUE)//We must assure fCopy is also flippable
     3713                                        if(fCopy->isFlippable==TRUE)We must assure fCopy is also flippable
    37143714                                        {
    37153715                                                if(slAct==NULL)
    37163716                                                {
    3717                                                         slAct = slAct->shallowCopy(*fCopy);//shallow copy constructor
    3718                                                         slHead = slAct;                                                         
     3717                                                        slAct = slAct->shallowCopy(*fCopy);shallow copy constructor
     3718                                                        slHead = slAct;
    37193719                                                }
    37203720                                                else
     
    37263726                                        fCopy = fCopy->next;
    37273727                                }
    3728                                 break;  //WTF?
     3728                                break;  WTF?
    37293729                        }
    37303730                        /*Comparison starts here*/
     
    37343734#ifdef gfan_DEBUG
    37353735        printf("Checking facet (");fAct->fNormal->show(1,1);printf(") against (");slAct->fNormal->show(1,1);printf(")\n");
    3736 #endif 
     3736#endif
    37373737                                if(areEqual2(fAct,slAct))
    37383738                                {
     
    37403740                                        if(slAct==slHead)
    37413741                                        {
    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());
    37463746                                                if(slHead!=NULL)
    37473747                                                {
     
    37493749                                                }
    37503750                                                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());
    37533753                                        }
    37543754                                        else if (slAct==slEnd)
     
    37583758                                                fDeleteMarker->shallowDelete();
    37593759                                                delete(fDeleteMarker);
    3760                                         }                                                               
     3760                                        }
    37613761                                        else
    37623762                                        {
     
    37713771printf("Removing (");fAct->fNormal->show(1,1);printf(") from list\n");
    37723772#endif
    3773                                         break;//leave the while loop, since we found fAct=slAct thus delete slAct and do not add fAct
     3773                                        break;leave the while loop, since we found fAct=slAct thus delete slAct and do not add fAct
    37743774                                }
    3775                                 slAct = slAct->next;                           
    3776                         }//while(slAct!=NULL)
     3775                                slAct = slAct->next;
     3776                        }while(slAct!=NULL)
    37773777                        if(removalOccured==FALSE)
    37783778                        {
     
    37843784                        }
    37853785                        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                        }
    37923792                }
    37933793                else
    37943794                        fAct = fAct->next;
    3795         }//while(fAct!=NULL)
    3796        
     3795        }while(fAct!=NULL)
     3796
    37973797#ifdef gfanp
    37983798        gettimeofday(&end, 0);
    37993799        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());
    38023802        return slHead;
    38033803}
    38043804
    3805 /** 
     3805/**
    38063806* During flip2 every gc->baseRing gets two ringorder_a
    38073807* To avoid having an awful lot of those in the end we endow
     
    38243824        omfree(replacementRing->wvhdl);
    38253825        replacementRing->wvhdl =(int **)omAlloc0(4*sizeof(int/*64*/**));
    3826                        
     3826
    38273827        replacementRing->order[0]=ringorder_a/*64*/;
    38283828        replacementRing->block0[0]=1;
    38293829        replacementRing->block1[0]=replacementRing->N;
    3830                
     3830
    38313831        replacementRing->order[1]=ringorder_dp;
    38323832        replacementRing->block0[1]=1;
    38333833        replacementRing->block1[1]=replacementRing->N;
    3834        
     3834
    38353835        replacementRing->order[2]=ringorder_C;
    38363836
    3837         int64vec *ivw = this->getIntPoint(TRUE);//returns a reference
    3838 //      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();
    38403840        int/*64*/ *A=(int/*64*/ *)omAlloc0(length*sizeof(int/*64*/));
    38413841        for (int jj=0;jj<length;jj++)
     
    38433843                A[jj]=(*ivw)[jj];
    38443844                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)
    38473847        replacementRing->wvhdl[0]=(int *)A;
    38483848        replacementRing->block1[0]=length;
     
    38533853        rDelete(this->baseRing);
    38543854        this->baseRing=rCopy(replacementRing);
    3855         this->gcBasis=idCopy(temporaryGroebnerBasis);   
     3855        this->gcBasis=idCopy(temporaryGroebnerBasis);
    38563856        /*And back to where we came from*/
    38573857        rChangeCurrRing(srcRing);
    38583858        idDelete( (ideal*)&temporaryGroebnerBasis );
    3859         rDelete(replacementRing);       
     3859        rDelete(replacementRing);
    38603860}
    38613861
     
    38773877        return p;
    38783878}
    3879        
     3879
    38803880/** \brief Construct a dd_MatrixPtr from a cone's list of facets
    38813881 * NO LONGER USED
    38823882 */
    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
    39133913/** \brief Write information about a cone into a file on disk
    39143914 *
     
    39263926        stringstream ss;
    39273927        ss << UCN;
    3928         string UCNstr = ss.str();               
    3929                        
     3928        string UCNstr = ss.str();
     3929
    39303930        string prefix="/tmp/Singular/cone";
    3931 //      string prefix="./";     //crude hack -> run tests in separate directories
     3931        string prefix="./";     //crude hack -> run tests in separate directories
    39323932        string suffix=".sg";
    39333933        string filename;
     
    39353935        filename.append(UCNstr);
    39363936        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
    39433943        ofstream gcOutputFile(filename.c_str());
    39443944        assert(gcOutputFile);
    39453945        facet *fAct;
    3946         fAct = gc.facetPtr;                     
     3946        fAct = gc.facetPtr;
    39473947        facet *f2Act;
    39483948        f2Act=fAct->codim2Ptr;
    3949        
     3949
    39503950        char *ringString = rString(gc.baseRing);
    3951                        
     3951
    39523952        if (!gcOutputFile)
    39533953        {
     
    39553955        }
    39563956        else
    3957         {       
     3957        {
    39583958                gcOutputFile << "UCN" << endl;
    39593959                gcOutputFile << this->UCN << endl;
    3960                 gcOutputFile << "RING" << endl; 
     3960                gcOutputFile << "RING" << endl;
    39613961                gcOutputFile << ringString << endl;
    39623962                gcOutputFile << "GCBASISLENGTH" << endl;
    3963                 gcOutputFile << IDELEMS(gc.gcBasis) << endl;                   
    3964                 //Write this->gcBasis into file
    3965                 gcOutputFile << "GCBASIS" << endl;                             
     3963                gcOutputFile << IDELEMS(gc.gcBasis) << endl;
     3964                Write this->gcBasis into file
     3965                gcOutputFile << "GCBASIS" << endl;
    39663966                for (int ii=0;ii<IDELEMS(gc.gcBasis);ii++)
    3967                 {                                       
     3967                {
    39683968                        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
    39733973                while(fAct!=NULL)
    3974                 {       
     3974                {
    39753975                        const int64vec *iv=fAct->getRef2FacetNormal();
    3976 //                      iv=fAct->getRef2FacetNormal();//->getFacetNormal();
     3976                        iv=fAct->getRef2FacetNormal();//->getFacetNormal();
    39773977                        f2Act=fAct->codim2Ptr;
    39783978                        for (int ii=0;ii<iv->length();ii++)
    39793979                        {
    3980 //                              if (ii<iv->length()-1)
    3981 //                                      gcOutputFile << (*iv)[ii] << ",";
    3982 //                              else
    3983 //                                      gcOutputFile << (*iv)[ii] << " ";
     3980                                if (ii<iv->length()-1)
     3981                                        gcOutputFile << (*iv)[ii] << ",";
     3982                                else
     3983                                        gcOutputFile << (*iv)[ii] << " ";
    39843984                                gcOutputFile << (*iv)[ii];
    39853985                                (ii<iv->length()-1) ? gcOutputFile << "," : gcOutputFile << " ";
    39863986                        }
    3987                         //delete iv;
     3987                        delete iv;
    39883988                        while(f2Act!=NULL)
    39893989                        {
     
    39923992                                for(int jj=0;jj<iv2->length();jj++)
    39933993                                {