~ubuntu-branches/ubuntu/saucy/gfan/saucy-proposed

« back to all changes in this revision

Viewing changes to app_groupfacetbinomials.cpp

  • Committer: Package Import Robot
  • Author(s): Cédric Boutillier
  • Date: 2013-07-09 10:44:01 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130709104401-5q66ozz5j5af0dak
Tags: 0.5+dfsg-3
* Upload to unstable.
* modify remove_failing_tests_on_32bits.patch to replace command of
  0009RenderStairCase test with an empty one instead of deleting it.
* remove lintian override about spelling error

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "parser.h"
2
 
#include "printer.h"
3
 
#include "polynomial.h"
4
 
#include "division.h"
5
 
#include "buchberger.h"
6
 
#include "wallideal.h"
7
 
#include "lp.h"
8
 
#include "reversesearch.h"
9
 
#include "termorder.h"
10
 
#include "ep_standard.h"
11
 
#include "ep_xfig.h"
12
 
#include "gfanapplication.h"
13
 
 
14
 
class GroupFacetBinomialsApplication : public GFanApplication
15
 
{
16
 
  SimpleOption optionLexicographic;
17
 
  SimpleOption optionReadTwoSets;
18
 
  SimpleOption optionNotOnlyFacets;
19
 
  FieldOption theFieldOption;
20
 
public:
21
 
  bool includeInDefaultInstallation()
22
 
  {
23
 
    return false;
24
 
  }
25
 
  const char *helpText()
26
 
  {
27
 
    return "This program takes a list of reduced Groebner bases for a binomial ideal and outputs the facet binomials grouped by hyperplane\n";
28
 
  }
29
 
  GroupFacetBinomialsApplication():
30
 
    optionNotOnlyFacets("-a","group all binomials - not only facets\n"),
31
 
    optionLexicographic("-l","order output polynomials with respect to lexicographic order\n"),
32
 
    optionReadTwoSets("-2","read two polynomial lists instead of one\n")
33
 
  {
34
 
    registerOptions();
35
 
  }
36
 
 
37
 
  char *name()
38
 
  {
39
 
    return "_groupfacetbinomials";
40
 
  }
41
 
 
42
 
  IntegerVector getVector(const Polynomial &p)
43
 
  {
44
 
    IntegerVector markedExponent=p.getMarked().m.exponent;
45
 
    
46
 
    for(TermMap::const_iterator i=p.terms.begin();i!=p.terms.end();i++)
47
 
      {
48
 
        IntegerVector dif=markedExponent-i->first.exponent;
49
 
        if(!dif.isZero())return dif;
50
 
      }
51
 
    assert(0);
52
 
    return markedExponent;
53
 
  }
54
 
 
55
 
  bool dependencyCheck(const Polynomial &p, const Polynomial &q)
56
 
  {
57
 
    return dependent(getVector(p),getVector(q));
58
 
  }
59
 
 
60
 
  IntegerVectorList extremeRays(IntegerVectorList const &normals)
61
 
  {
62
 
    IntegerVectorList extreme;
63
 
    for(IntegerVectorList::const_iterator i=normals.begin();i!=normals.end();i++)
64
 
      {
65
 
        if(isFacet(normals,i))extreme.push_back(*i);
66
 
      }
67
 
    return extreme;
68
 
  }
69
 
  void process(FileParser &P, PolynomialSetList &s)
70
 
  {
71
 
    PolynomialSetList l=P.parsePolynomialSetListWithRing();
72
 
    for(PolynomialSetList::const_iterator i=l.begin();i!=l.end();i++)
73
 
      {
74
 
        IntegerVectorList normals=wallInequalities(*i);
75
 
        IntegerVectorList extreme=extremeRays(normals);
76
 
        if(optionNotOnlyFacets.getValue())extreme=normals;
77
 
        for(PolynomialSet::const_iterator j=i->begin();j!=i->end();j++)
78
 
          {
79
 
            IntegerVectorList::const_iterator m;
80
 
            for(m=extreme.begin();m!=extreme.end();m++)
81
 
              if(dependent(getVector(*j),*m))break;
82
 
            Polynomial dummy=*j;
83
 
            if(optionLexicographic.getValue())
84
 
              {
85
 
                dummy.mark(LexicographicTermOrder());
86
 
                dummy.scaleMarkedCoefficientToOne();
87
 
              }
88
 
            if(m!=extreme.end())
89
 
              {
90
 
                PolynomialSetList::iterator k;
91
 
                for(k=s.begin();k!=s.end();k++)
92
 
                  if(dependencyCheck(*(k->begin()),dummy))break;
93
 
                if(k==s.end())
94
 
                  {
95
 
                    PolynomialSet q(j->getRing());
96
 
                    q.unionPolynomial(dummy);
97
 
                    s.push_back(q);
98
 
                  }
99
 
                else
100
 
                  {
101
 
                    k->unionPolynomial(dummy);
102
 
                  }
103
 
              }
104
 
          }
105
 
      }
106
 
  }
107
 
  
108
 
  int main()
109
 
  {
110
 
    FileParser P(Stdin);
111
 
    PolynomialSetList s;
112
 
  
113
 
    process(P,s);
114
 
    if(optionReadTwoSets.getValue())process(P,s);
115
 
 
116
 
    AsciiPrinter(Stdout).printPolynomialSetList(s);
117
 
    
118
 
    return 0;
119
 
  }
120
 
};
121
 
 
122
 
static GroupFacetBinomialsApplication theApplication;