source: git/kernel/gfan.cc @ 87beab7

spielwiese
Last change on this file since 87beab7 was c5d8dd, checked in by Martin Monerjan, 15 years ago
Added cddlib made gfan optional via HAVE_GFAN git-svn-id: file:///usr/local/Singular/svn/trunk@11369 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2Compute the Groebner fan of an ideal
3Author: $Author: monerjan $
4Date: $Date: 2009-02-11 14:57:55 $
5Header: $Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.10 2009-02-11 14:57:55 monerjan Exp $
6Id: $Id: gfan.cc,v 1.10 2009-02-11 14:57:55 monerjan Exp $
7*/
8
9#include "mod2.h"
10#include "kstd1.h"
11#include "intvec.h"
12#include "polys.h"
13#include "ideals.h"
14#include "kmatrix.h"
15#include "/users/urmel/alggeom/monerjan/cddlib/include/setoper.h" //Support for cddlib. Dirty hack
16#include "/users/urmel/alggeom/monerjan/cddlib/include/cdd.h"
17
18#ifndef gfan_DEBUG
19#define gfan_DEBUG
20#endif
21
22ideal getGB(ideal inputIdeal)
23{
24        #ifdef gfan_DEBUG
25        printf("Now in getGB\n");
26        #endif
27
28        ideal gb;
29        gb=kStd(inputIdeal,NULL,testHomog,NULL); //Possible to call without testHomog/isHomog?
30        idSkipZeroes(gb); //Get rid of zero entries
31
32        return gb;
33}
34
35/****** getWallIneq computes the inequalities ***/
36/*INPUT_TYPE: ideal                             */
37/*RETURN_TYPE: matrix                           */
38/************************************************/
39void getWallIneq(ideal I)
40{
41        #ifdef gfan_DEBUG
42        printf("*** Computing Inequalities... ***\n");
43        #endif
44
45        //All variables go here - except ineq matrix and *v, see below
46        int lengthGB=IDELEMS(I);        // # of polys in the groebner basis
47        int pCompCount;                 // # of terms in a poly
48        poly aktpoly;
49        int numvar = pVariables;        // # of variables in a polynomial (or ring?)
50        int leadexp[numvar];            // dirty hack of exp.vects
51        int aktexp[numvar];
52        int cols,rows;                  // will contain the dimensions of the ineq matrix - deprecated by
53        dd_rowrange ddrows;
54        dd_colrange ddcols;
55        dd_rowset ddredrows;            // # of redundant rows in ddineq
56        dd_NumberType ddnumb=dd_Real;   //Number type
57        dd_ErrorType dderr=dd_NoError;  //
58        // End of var declaration
59
60        printf("The Groebner basis has %i elements\n",lengthGB);
61        printf("The current ring has %i variables\n",numvar);
62        cols = numvar;
63
64        //Compute the # inequalities i.e. rows of the matrix
65        rows=0; //Initialization
66        for (int ii=0;ii<IDELEMS(I);ii++)
67        {
68                aktpoly=(poly)I->m[ii];
69                rows=rows+pLength(aktpoly)-1;
70        }
71        printf("rows=%i\n",rows);
72        printf("Will create a %i x %i - matrix to store inequalities\n",rows,cols);
73
74        dd_rowrange aktmatrixrow=0;     // needed to store the diffs of the expvects in the rows of ddineq
75        dd_set_global_constants();
76        ddrows=rows;
77        ddcols=cols;
78        dd_MatrixPtr ddineq;            //Matrix to store the inequalities
79        ddineq=dd_CreateMatrix(ddrows,ddcols);
80
81        // We loop through each g\in GB and compute the resulting inequalities
82        for (int i=0; i<IDELEMS(I); i++)
83        {
84                aktpoly=(poly)I->m[i];          //get aktpoly as i-th component of I
85                pCompCount=pLength(aktpoly);    //How many terms does aktpoly consist of?
86                printf("Poly No. %i has %i components\n",i,pCompCount);
87
88                int *v=(int *)omAlloc((numvar+1)*sizeof(int));
89                pGetExpV(aktpoly,v);    //find the exp.vect in v[1],...,v[n], use pNext(p)
90               
91                //Store leadexp for aktpoly
92                for (int kk=0;kk<numvar;kk++)
93                {
94                        leadexp[kk]=v[kk+1];
95                        //printf("Leadexpcomp=%i\n",leadexp[kk]);
96                        //Since we need to know the difference of leadexp with the other expvects we do nothing here
97                        //but compute the diff below
98                }
99
100               
101                while (pNext(aktpoly)!=NULL) //move to next term until NULL
102                {
103                        aktpoly=pNext(aktpoly);
104                        pSetm(aktpoly);         //doesn't seem to help anything
105                        pGetExpV(aktpoly,v);
106                        for (int kk=0;kk<numvar;kk++)
107                        {
108//The ordering somehow gets lost here but this is acceptable, since we are only interested in the inequalities
109                                aktexp[kk]=v[kk+1];
110                                //printf("aktexpcomp=%i\n",aktexp[kk]);
111                                //ineq[aktmatrixrow][kk]=leadexp[kk]-aktexp[kk];        //dito
112                                dd_set_si(ddineq->matrix[(dd_rowrange)aktmatrixrow][kk],leadexp[kk]-aktexp[kk]);
113                        }
114                        aktmatrixrow=aktmatrixrow+1;
115                }//while
116
117        } //for
118
119        // The inequalities are now stored in ddineq
120        // Next we check for superflous rows
121        ddredrows = dd_RedundantRows(ddineq, &dderr);
122        if (dderr!=dd_NoError)                  // did an error occur?
123        {
124                 dd_WriteErrorMessages(stderr,dderr);   //if so tell us
125        } else
126        {
127                printf("Redundant rows: ");
128                set_fwrite(stdout, ddredrows);          //otherwise print the redundant rows
129        }//if dd_Error
130
131        #ifdef gfan_DEBUGs
132        printf("Inequalitiy matrix\n");
133        for (int i=0;i<rows;i++)
134        {
135                for (int j=0;j<cols;j++)
136                {
137                        printf("%i ",ineq[i][j]);
138                }
139                printf("\n");
140        }
141        #endif
142        //res=(ideal)aktpoly;
143        //return res;
144}
145
146ideal gfan(ideal inputIdeal)
147{
148        #ifdef gfan_DEBUG
149        printf("Now in subroutine gfan\n");
150        #endif
151        ideal res;
152        matrix ineq; //Matrix containing the boundary inequalities
153
154        res=getGB(inputIdeal);
155        getWallIneq(res);
156        return res;
157}
Note: See TracBrowser for help on using the repository browser.