source: git/kernel/gfan.cc @ 4b81d75

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