Changeset 1fcefd in git


Ignore:
Timestamp:
May 11, 2009, 4:27:44 PM (15 years ago)
Author:
Martin Monerjan
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
5435c37074ca280bb7d26c85ede7b6f237e78cb3
Parents:
0b1568ce1cbf77cc61022a7be99c105dc5e27cc6
Message:
Started work on new way to compute the fan
Wrote method to write cone out to file


git-svn-id: file:///usr/local/Singular/svn/trunk@11791 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/gfan.cc

    r0b1568 r1fcefd  
    22Compute the Groebner fan of an ideal
    33$Author: monerjan $
    4 $Date: 2009-05-08 12:58:01 $
    5 $Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.48 2009-05-08 12:58:01 monerjan Exp $
    6 $Id: gfan.cc,v 1.48 2009-05-08 12:58:01 monerjan Exp $
     4$Date: 2009-05-11 14:27:44 $
     5$Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.49 2009-05-11 14:27:44 monerjan Exp $
     6$Id: gfan.cc,v 1.49 2009-05-11 14:27:44 monerjan Exp $
    77*/
    88
     
    2121#include "ring.h"
    2222#include "prCopy.h"
    23 #include <iostream.h>   //deprecated
     23#include <iostream>     //deprecated
    2424#include <bitset>
    25 
    26 /*remove the following at your own risk*/
     25#include <fstream>      //read-write cones to files
     26
     27/*DO NOT REMOVE THIS*/
    2728#ifndef GMPRATIONAL
    2829#define GMPRATIONAL
     
    5354
    5455//#include gcone.h
     56using namespace std;
    5557
    5658/**
     
    190192                intvec *ivIntPt;        //an interior point of the cone
    191193               
    192         public:
     194        public:
     195                /** Pointer to the first facet */
     196                facet *facetPtr;        //Will hold the adress of the first facet; set by gcone::getConeNormals
     197               
     198                /** # of variables in the ring */
     199                int numVars;            //#of variables in the ring
     200               
     201                /** Contains the Groebner basis of the cone. Is set by gcone::getGB(ideal I)*/
     202                ideal gcBasis;          //GB of the cone, set by gcone::getGB();
     203                gcone *next;            //Pointer to *previous* cone in search tree     
     204               
    193205                /** \brief Default constructor.
    194206                *
     
    206218                * This constructor takes the root ring and the root ideal as parameters and stores
    207219                * them in the private members gcone::rootRing and gcone::inputIdeal
     220                * Since knowledge of the root ring is only needed when using reverse search,
     221                * this constructor is not needed when using the "second" method
    208222                */
    209223                gcone(ring r, ideal I)
     
    235249                        gb=gc.facetPtr->getFlipGB();                   
    236250                        this->gcBasis=gb;//gc.facetPtr->getFlipGB();    //this cone's GB is the flipped GB
    237                         idShow(this->gcBasis);
     251                        //idShow(this->gcBasis);
    238252                       
    239253                        /*Reverse direction of the facet normal to make it an inner normal*/                   
     
    243257                        }
    244258                       
    245                         fAct->setFacetNormal(ivtmp);                   
     259                        fAct->setFacetNormal(ivtmp);
     260                        delete ivtmp;                                           
    246261                }
    247262               
    248263                /** \brief Default destructor */
    249264                ~gcone(){;}             //destructor
    250                
    251                 /** Pointer to the first facet */
    252                 facet *facetPtr;        //Will hold the adress of the first facet; set by gcone::getConeNormals
    253                
    254                 /** # of variables in the ring */
    255                 int numVars;            //#of variables in the ring
    256                
    257                 /** Contains the Groebner basis of the cone. Is set by gcone::getGB(ideal I)*/
    258                 ideal gcBasis;          //GB of the cone, set by gcone::getGB();
    259                 gcone *next;            //Pointer to *previous* cone in search tree
     265                       
    260266               
    261267                /** \brief Set the interior point of a cone */
     
    408414                        facet *fAct;                    //instantiate pointer to active facet
    409415                        fAct = fRoot;                   //Seems to do the trick. fRoot and fAct have to point to the same adress!
    410                         std::cout << "fRoot = " << fRoot << ", fAct = " << fAct << endl;
     416                        //std::cout << "fRoot = " << fRoot << ", fAct = " << fAct << endl;
    411417                        for (int kk = 0; kk<ddrows; kk++)
    412418                        {
    413                                 intvec *load = new intvec(numvar);      //intvec to store a single facet normal that will then be stored via setFacetNormal
     419                                intvec *load = new intvec(this->numVars);       //intvec to store a single facet normal that will then be stored via setFacetNormal
    414420                                for (int jj = 1; jj <ddcols; jj++)
    415421                                {
     
    417423                                        double foo;
    418424                                        foo = mpq_get_d(ddineq->matrix[kk][jj]);
    419 /*#ifdef gfan_DEBUG
     425#ifdef gfan_DEBUG
    420426                                        std::cout << "fAct is " << foo << " at " << fAct << std::endl;
    421 #endif*/
     427#endif
    422428                                        (*load)[jj-1] = (int)foo;               //store typecasted entry at pos jj-1 of load
    423 #endif
    424 #ifndef GMPRATIONAL
    425                                         double *foo;
    426                                         foo = (double*)ddineq->matrix[kk][jj];  //get entry from actual position#endif
    427 /*#ifdef gfan_DEBUG
    428                                         std::cout << "fAct is " << *foo << " at " << fAct << std::endl;
    429 #endif*/
    430                                         (*load)[jj-1] = (int)*foo;              //store typecasted entry at pos jj-1 of load
    431 #endif //GMPRATIONAL                                   
    432                        
     429#endif                 
    433430
    434431                                        //(*load)[jj-1] = (int)foo;             //store typecasted entry at pos jj-1 of load
     
    444441                                {
    445442                                        intvec *ivCanonical = new intvec(load->length());
    446                                         (*ivCanonical)[jj]=1;                           
    447                                         if (dotProduct(load,ivCanonical)<0)
     443                                        (*ivCanonical)[jj]=1;
     444                                        cout << "dotProd=" << dotProduct(*load,*ivCanonical) << endl;
     445                                        if (dotProduct(*load,*ivCanonical)<0)                                   
    448446                                        {
    449447                                                isFlippable=TRUE;
     
    480478                        }
    481479                       
    482                         //Clean up but don't delete the return value! (Whatever it will turn out to be)
    483                        
     480                        //Clean up but don't delete the return value! (Whatever it will turn out to be)                 
    484481                        dd_FreeMatrix(ddineq);
    485482                        set_free(ddredrows);
     
    899896                }//GGW
    900897               
     898                /** \brief Compute the negative of a given intvec
     899                */             
    901900                intvec *ivNeg(intvec const &iv)
    902901                {
     
    12081207                }//bool isSearchFacet
    12091208               
     1209                /** \brief Check for equality of two intvecs
     1210                */
    12101211                bool areEqual(intvec const &a, intvec const &b)
    12111212                {
     
    12221223                }
    12231224               
     1225                /** \brief The reverse search algorithm
     1226                */
    12241227                void reverseSearch(gcone *gcAct) //no const possible here since we call gcAct->flip
    12251228                {
     
    12601263                        }//while(fAct->next!=NULL)
    12611264                }//reverseSearch
    1262                 friend class facet;
     1265               
     1266                /** \brief Write information about a cone into a file on disk
     1267                *
     1268                * This methods writes the information needed for the "second" method into a file.
     1269                * The file's is divided in sections containing information on
     1270                * 1) the ring
     1271                * 2) the cone's Groebner Basis
     1272                * 3) the cone's facets
     1273                * Each line contains exactly one date
     1274                * Each section starts with its name in CAPITALS
     1275                */
     1276                void writeConeToFile(gcone const &gc)
     1277                {
     1278                        ofstream gcOutputFile("/tmp/cone1.gc");
     1279                        if (!gcOutputFile)
     1280                        {
     1281                                cout << "Error opening file for writing in writeConeToFile" << endl;
     1282                        }
     1283                        else
     1284                        {                       
     1285                                gcOutputFile << "RING" << endl;                         
     1286                                //Write this->gcBasis into file
     1287                                gcOutputFile << "GCBASIS" << endl;                             
     1288                                for (int ii=0;ii<IDELEMS(gc.gcBasis);ii++)
     1289                                {                                       
     1290                                        gcOutputFile << p_String((poly)gc.gcBasis->m[ii],gc.baseRing) << endl;
     1291                                }                       
     1292                               
     1293                                facet *fAct = new facet();
     1294                                fAct = gc.facetPtr;
     1295                                gcOutputFile << "FACETS" << endl;                                                               
     1296                                while(fAct!=NULL)
     1297                                {       
     1298                                        intvec *iv = new intvec(gc.numVars);
     1299                                        iv=fAct->getFacetNormal();
     1300                                        for (int ii=0;ii<iv->length();ii++)
     1301                                        {
     1302                                                if (ii<iv->length()-1)
     1303                                                {
     1304                                                        gcOutputFile << (*iv)[ii] << ",";
     1305                                                }
     1306                                                else
     1307                                                {
     1308                                                        gcOutputFile << (*iv)[ii] << endl;
     1309                                                }
     1310                                        }
     1311                                        fAct=fAct->next;
     1312                                }                               
     1313                               
     1314                                gcOutputFile.close();
     1315                        }
     1316                }//writeConeToFile(gcone const &gc)
     1317               
     1318                /** \brief Reads a cone from a file identified by its number
     1319                */
     1320                void readConeFromFile(int gcNum)
     1321                {
     1322                }
     1323               
     1324        friend class facet;
    12631325};//class gcone
    12641326
     
    12661328{
    12671329        int numvar = pVariables;
     1330       
     1331        enum searchMethod {
     1332                reverseSearch,
     1333                noRevS
     1334        };
     1335       
     1336        searchMethod method;
     1337        method = noRevS;
     1338        //method = reverseSearch;
    12681339       
    12691340#ifdef gfan_DEBUG
     
    12751346        facet *fRoot;
    12761347       
    1277         /*
    1278         1. Select target order, say dp.
    1279         2. Compute GB of inputIdeal wrt target order -> newRing, setCurrRing etc...
    1280         3. getConeNormals
    1281         */
     1348        if (method==reverseSearch)
     1349        {
    12821350       
    12831351        /* Construct a new ring which will serve as our root*/
     
    13131381        But since we are in the root all facets should be search facets. IS THIS TRUE?
    13141382        NOTE: Check for flippability is not very sophisticated
    1315         */
    1316         /*facet *fAct=new facet();
    1317         fAct=gcAct->facetPtr;
    1318         while(fAct->next!=NULL)
     1383        */     
     1384        //gcAct->reverseSearch(gcAct); 
     1385        rChangeCurrRing(rootRing);
     1386        res=gcRoot->gcBasis;   
     1387        }//if method==reverSearch
     1388       
     1389        if(method==noRevS)
    13191390        {
    1320                 gcAct->flip(gcAct->gcBasis,gcAct->facetPtr);
    1321                 gcone *gcTmp = new gcone(*gcAct);
    1322                 idShow(gcTmp->gcBasis);
    1323                 gcTmp->getConeNormals(gcTmp->gcBasis, TRUE);
    1324                 gcTmp->getIntPoint();
    1325                 fAct = fAct->next;             
    1326         }*/
    1327         gcAct->reverseSearch(gcAct);
     1391                gcone *gcRoot = new gcone(currRing,inputIdeal);
     1392                gcone *gcAct;
     1393                gcAct = gcRoot;
     1394                gcAct->numVars=pVariables;
     1395                gcAct->getGB(inputIdeal);
     1396                gcAct->getConeNormals(gcAct->gcBasis);         
     1397                gcAct->writeConeToFile(*gcAct);
     1398                res=gcAct->gcBasis;     
     1399        }
    13281400       
    13291401        /*As of now extra.cc expects gfan to return type ideal. Probably this will change in near future.
     
    13341406        => Count the cones!
    13351407        */
    1336         rChangeCurrRing(rootRing);
     1408        //rChangeCurrRing(rootRing);
    13371409        //res=gcAct->gcBasis;
    1338         res=gcRoot->gcBasis;   
     1410        //res=gcRoot->gcBasis; 
    13391411        return res;
    13401412        //return GBlist;
Note: See TracChangeset for help on using the changeset viewer.