File: app_fancoarsening.cpp

package info (click to toggle)
gfan 0.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,372 kB
  • sloc: cpp: 53,144; makefile: 556
file content (172 lines) | stat: -rw-r--r-- 4,761 bytes parent folder | download | duplicates (4)
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
/*
 * app_fancoarsening.cpp
 *
 *  Created on: Jul 19, 2010
 *      Author: anders
 */

#include "parser.h"
#include "printer.h"
#include "polynomial.h"
#include "division.h"
#include "lp.h"
#include "gfanapplication.h"
#include "polyhedralcone.h"
#include "polyhedralfan.h"
#include "symmetry.h"

#include "polymakefile.h"

#include "traverser_sphere.h"

class FanCoarseningApplication : public GFanApplication
{

  StringOption inputOption;
//  SimpleOption resultantOption;

  multimap<IntegerVector,int> coneIndicesAtRidge;
  vector<PolyhedralCone> F1,F2;
public:
  bool includeInDefaultInstallation()
  {
    return false;
  }

  IntegerVectorList inequalitiesForCone(IntegerVector const &codim1interior, IntegerVector const &newDirection)
  {

    int i=0;

  }

  const char *helpText()
  {
    return "This program reads in a codimension-one fan (with support equal to the codimension-1 skeleton of the normal fan of a polytope) and constructs the normal fan of the polytope.\n";
  }
  FanCoarseningApplication():
    inputOption("-i","Specify the name of the input file.","polymake.out")
 //   resultantOption("--resultant","Take codim 1 skeleton and wipe out bad cones.")
  {
    registerOptions();
  }

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

/*  bool zeroOrTwo(int v)
  {
    return (v==0) || (v==2);
  }*/

  class MyTarget : public SymmetricTarget
  {
    list<IntegerVector> normals;
    bool process(ConeTraverser &traverser)
    {
      SphereTraverser *t=dynamic_cast<SphereTraverser*> (&traverser);
      normals.push_back(t->currentNormal);
      return true;
    }
  public:
    PolyhedralCone toCone()
    {
      PolyhedralCone c(normals,IntegerVectorList(),normals.begin()->size());
      c.canonicalize();
      return c;
    }
  };


  class MyTraverser: public ConeTraverser
  {
    int currentConeIndex;
    vector<PolyhedralCone> const &cones;
    map<IntegerVector,list<int> > adjacency;
    PolyhedralCone theCone;
    //void updatePolyhedralCone();
    void moveToCone(IntegerVector const &v, IntegerVector const &normal)
    {
      SphereTraverser traverser(cones,adjacency,v,normal);

      MyTarget myTarget;
      SymmetryGroup s(normal.size());
      symmetricTraverse(traverser,myTarget);
      theCone=myTarget.toCone();
    }
  public:
//    IntegerVector currentNormal;
          MyTraverser(vector<PolyhedralCone> const &cones_, map<IntegerVector,list<int> > const &adjacency_, IntegerVector const &v, IntegerVector const &normal):
        	  ConeTraverser(normal.size()),
            cones(cones_),
            adjacency(adjacency_)
            {
              moveToCone(v,normal);
          }
          virtual void changeCone(IntegerVector const &ridgeVector, IntegerVector const &rayVector)
          {
            moveToCone(ridgeVector,rayVector);
          }
          virtual IntegerVectorList link(IntegerVector const &ridgeVector)
          {
            IntegerVector v=theCone.link(ridgeVector).getUniquePoint();
            IntegerVectorList ret;
            ret.push_back(v);
            ret.push_back(-v);
            return ret;
          }
          PolyhedralCone & refToPolyhedralCone()
          {
            return theCone;
          }
  };




  int main()
  {
    PolyhedralFan f1=PolyhedralFan::readFan(inputOption.getValue(),true,0,0,0);
    AsciiPrinter P(Stdout);

    for(PolyhedralFan::coneIterator i=f1.conesBegin();i!=f1.conesEnd();i++)F1.push_back(*i);
    map<IntegerVector,list<int> > adjacency;
    for(int i=0;i<F1.size();i++)
      {
        PolyhedralFan temp(F1[i].ambientDimension());
        temp.insert(F1[i]);
        PolyhedralFan facets=temp.facetComplex();
        for(PolyhedralFan::coneIterator j=facets.conesBegin();j!=facets.conesEnd();j++)
          adjacency[j->getUniquePoint()].push_back(i);
      }
//    SphereTraverser(vector<PolyhedralCone> const &cones_, map<IntegerVector,list<int> > const &ajacency_, IntegerVector const &startCone, IntegerVector const &normal);

    SphereTraverser traverser(F1,adjacency,F1[0].getUniquePoint(),*F1[0].getEquations().begin());

    MyTarget myTarget;
    SymmetryGroup s(f1.getAmbientDimension());
//    SymmetricTargetFanBuilder myTarget(f1.getAmbientDimension(),s);
    symmetricTraverse(traverser,myTarget);

//    myTarget.getFanRef().printWithIndices(&pout);
    myTarget.toCone().print(&debug);



    {
      MyTraverser traverser(F1,adjacency,F1[0].getUniquePoint(),*F1[0].getEquations().begin());

      SymmetryGroup s(f1.getAmbientDimension());
      SymmetricTargetFanBuilder myTarget(f1.getAmbientDimension(),s);
      symmetricTraverse(traverser,myTarget);
      myTarget.getFanRef().printWithIndices(&pout);
    }

    return 0;
  }
};

static FanCoarseningApplication theApplication;