File: app_minkowski.cpp

package info (click to toggle)
gfan 0.5%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,348 kB
  • ctags: 5,683
  • sloc: cpp: 39,675; makefile: 454; sh: 1
file content (188 lines) | stat: -rw-r--r-- 5,525 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <iostream>
#include "parser.h"
#include "printer.h"
#include "polynomial.h"
#include "division.h"
#include "buchberger.h"
#include "wallideal.h"
#include "lp.h"
#include "reversesearch.h"
#include "breadthfirstsearch.h"
#include "termorder.h"
#include "ep_standard.h"
#include "ep_xfig.h"
#include "gfanapplication.h"
#include "polyhedralfan.h"
#include "minkowskidual.h"
#include "log.h"

class MinkowskiEnumerationTarget:public EnumerationTarget
{
  SymmetryGroup const &s;
 public:
  IntegerVectorList weightVectors;
  MinkowskiEnumerationTarget(SymmetryGroup const &s_):
    s(s_)
  {
  }
  virtual void beginEnumeration(const PolynomialSet &groebnerBasis)
  {
  }
  virtual void endEnumeration()
  {
  }
  virtual bool basis(const PolynomialSet &groebnerBasis)
  {
    //    log0 cerr<<"ETST"<<endl;
    PolyhedralCone c=coneFromMarkedBasis(groebnerBasis);
    weightVectors.push_back(PolyhedralFan::stableRay(c,&s));
    return true;
  } /* return false to break enumaration */
};


class MinkowskiApplication : public GFanApplication
{
  SimpleOption optionSymmetry;
  SimpleOption optionDisableSymmetryTest;
  SimpleOption optionIgnoreCones;
  SimpleOption optionPartOne;
  SimpleOption optionPartTwo;
public:
  const char *helpText()
  {
    return "This is a program for computing the normal fan of the Minkowski sum of the Newton polytopes of a list of polynomials.\n";
  }
  MinkowskiApplication():
    optionSymmetry("--symmetry",
		   "Tells the program to read in generators for a group of symmetries (subgroup of $S_n$) after having read in the ideal. The program checks that the ideal stays fixed when permuting the variables with respect to elements in the group. The program uses breadth first search to compute the set of reduced Groebner bases up to symmetry with respect to the specified subgroup.\n"),
    optionDisableSymmetryTest("--disableSymmetryTest","When using --symmetry this option will disable the check that the group read off from the input actually is a symmetry group with respect to the input ideal.\n"),
    optionIgnoreCones("--nocones","Tell the program to not list cones in the output."),
    optionPartOne("--partOne","Do only the fist part of the computation i.e. compute a weight vector for each vertex.\n"),
    optionPartTwo("--partTwo","Do only the second part of the computation .\n")
  {
    registerOptions();
    optionPartOne.hide();
    optionPartTwo.hide();
  }

  const char *name()
  {
    return "_minkowskisum";
  }

  int main()
  {
    LexicographicTermOrder myOrder;

    PolynomialSet g=FileParser(Stdin).parsePolynomialSetWithRing();
    g.sort_();
    g.markAndScale(myOrder);


    SymmetryGroup s(g.numberOfVariablesInRing());

    IntegerVectorList generators;
    if(optionSymmetry.getValue())
      {
	generators=FileParser(Stdin).parseIntegerVectorList();
	if(!optionDisableSymmetryTest.getValue())
	  {
	    /*	    for(IntegerVectorList::iterator i=generators.begin();i!=generators.end();i++)
	      {
		PolynomialSet G=SymmetryGroup::permutePolynomialSet(g,*i);
		G.sort_();
		assert(g==G);
	      }
	    */
	    assertSymmetriesMatch(generators, g,0,true);//eldMatrix const *torusActions);
	  }
	s.computeClosure(generators);

	s.createByteTable();
      }
    //    EnumerationTargetCollector ep;

    IntegerVectorList weightVectors;
    if(optionPartTwo.getValue())
      {
	weightVectors=FileParser(Stdin).parseIntegerVectorList();
      }
    else
      {
	MinkowskiEnumerationTarget ep(s);
	log1 fprintf(Stderr,"Traversing normal fan.\n");
	BreadthFirstSearch rs(s,true);
	rs.setEnumerationTarget(&ep);
	rs.enumerate(g);
	weightVectors=ep.weightVectors;
      }
    if(optionPartOne.getValue())
      {
	AsciiPrinter P(Stdout);
	P.printPolynomialSet(g);
	if(optionSymmetry.getValue())
	  P.printVectorList(generators);
	P.printVectorList(weightVectors);
      }
    else
      {
	log1 fprintf(Stderr,"Computing polyhedral cones.\n");
	int n=g.getRing().getNumberOfVariables();
	PolyhedralFan f(n);
	int counter=0;
	for(IntegerVectorList::const_iterator i=weightVectors.begin();i!=weightVectors.end();i++)
	  {
      {
	static int t;
	if(!((t++)%10))log1 fprintf(Stderr,"%i\n",t);
      }

      //            if(counter++==35)break;
	    //log0 fprintf(Stderr,"Weight vektor:\n");
	    //log0 AsciiPrinter(Stderr).printVector(*i);
	    // log0 fprintf(Stderr,"1");
	    WeightTermOrder T(*i);
	    g.markAndScale(T);
	    // log0 fprintf(Stderr,"2");
	    PolyhedralCone c=coneFromMarkedBasis(g);
	    // log0 fprintf(Stderr,"3");
	    //inequalities=
	      /*wallInequalities(g);
	    fprintf(stderr,"%i ",inequalities.size());
	    inequalities=normalizedWithSumsAndDuplicatesRemoved(inequalities);
	    fprintf(stderr,"%i\n",inequalities.size());
	    IntegerVectorList empty;
	    PolyhedralCone c(inequalities,empty,n);
	      */

	    c.canonicalize();
	    //log0 fprintf(Stderr,"4");
	    f.insert(c);
	    //log0 fprintf(Stderr,"5\n");
	    //static int i;
	    //log0 fprintf(Stderr,"inserted:%i\n",++i);
	  }
	log1 fprintf(Stderr,"Resolving symmetries.\n");

	/*	{
	  SymmetricComplex c=dualMinkowskiMixed(g,s,f);
	  return 0;
	  }*/


	AsciiPrinter P(Stdout);
	f.printWithIndices(&P,
			   FPF_conesExpanded|
			   (optionIgnoreCones.getValue()?0:FPF_cones|FPF_maximalCones)|
			   (optionSymmetry.getValue()?FPF_group|FPF_conesCompressed:0),
			   &s);
	//	f.printWithIndices(&P,false, &s,optionSymmetry.getValue(),optionIgnoreCones.getValue());
      }

    return 0;
  }
};

static MinkowskiApplication theApplication;