source: git/gfanlib/gfanlib_zfan.cpp @ e543dd

spielwiese
Last change on this file since e543dd was e543dd, checked in by Frank Seelisch <seelisch@…>, 13 years ago
new gfanlib from Anders git-svn-id: file:///usr/local/Singular/svn/trunk@14098 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.3 KB
Line 
1/*
2 * gfanlib_zfan.cpp
3 *
4 *  Created on: Nov 17, 2010
5 *      Author: anders
6 */
7
8#include "gfanlib_zfan.h"
9#include "gfanlib_polymakefile.h"
10
11using namespace std;
12
13namespace gfan
14{
15  static int numberOf(std::vector<std::vector<IntVector> > T, int dimension)
16  {
17    assert(dimension>=0);
18    if(dimension>=T.size())return 0;
19    return T[dimension].size();
20  }
21  std::vector<std::vector<IntVector> > &ZFan::table(bool orbit, bool maximal)const
22  {
23    if(orbit)
24      {
25        if(maximal)return maximalConeOrbits;
26        return coneOrbits;
27      }
28    if(maximal)return maximalCones;
29    return cones;
30  }
31  int ZFan::numberOfConesOfDimension(int d, bool orbit, bool maximal)const
32  {
33    return numberOf(table(orbit,maximal),d);
34  }
35  ZCone ZFan::getCone(int dimension, int index, bool orbit, bool maximal)const
36  {
37    IntVector indices=getConeIndices(dimension,index,orbit,maximal);
38    return this->complex->makeZCone(indices);
39  }
40  IntVector ZFan::getConeIndices(int dimension, int index, bool orbit, bool maximal)const
41  {
42    assert(index>=0);
43    assert(index<numberOfConesOfDimension(dimension,orbit,maximal));
44    return table(orbit,maximal)[dimension][index];
45  }
46  void ZFan::ensureConeCollection()const
47  {
48    if(!coneCollection)
49      {
50        assert(0);
51      }
52  }
53  void ZFan::ensureComplex()const
54  {
55    if(!complex)
56      {
57        assert(coneCollection);
58        complex = new SymmetricComplex(coneCollection->toSymmetricComplex());
59        complex->buildConeLists(false,false,&cones);
60        complex->buildConeLists(true,false,&maximalCones);
61        complex->buildConeLists(false,true,&coneOrbits);
62        complex->buildConeLists(true,true,&maximalConeOrbits);
63      }
64  }
65  void ZFan::killComplex()const
66  {
67    if(complex)
68      {
69        delete complex;
70        complex=0;
71      }
72  }
73
74  ZFan::ZFan(std::istream &f):
75    coneCollection(0),
76    complex(0)
77  {
78//    PolyhedralFan PolyhedralFan::readFan(string const &filename, bool onlyMaximal, IntegerVector *w, set<int> const *coneIndices, SymmetryGroup const *sym, bool readCompressedIfNotSym)
79    PolymakeFile inFile;
80    //assert(0);
81     inFile.open(f);
82
83    int n=inFile.readCardinalProperty("AMBIENT_DIM").toInt();
84    int nRays=inFile.readCardinalProperty("N_RAYS").toInt();
85    ZMatrix rays=inFile.readMatrixProperty("RAYS",nRays,n);
86    int linealityDim=inFile.readCardinalProperty("LINEALITY_DIM").toInt();
87    ZMatrix linealitySpace=inFile.readMatrixProperty("LINEALITY_SPACE",linealityDim,n);
88
89    SymmetryGroup sym(n);
90    bool readingSymmetricComplex=false;
91    if(inFile.hasProperty("SYMMETRY_GENERATORS"))
92      {
93        sym.computeClosure(ZToIntMatrix(inFile.readMatrixProperty("SYMMETRY_GENERATORS",-1,n)));
94        readingSymmetricComplex=true;
95      }
96
97
98    const char *sectionName=0;
99    const char *sectionNameMultiplicities=0;
100    if(readingSymmetricComplex)
101      {
102        if(inFile.hasProperty("MAXIMAL_CONES_ORBITS"))
103          {
104            sectionName="MAXIMAL_CONES_ORBITS";
105            sectionNameMultiplicities="MULTIPLICITIES_ORBITS";
106          }
107        else
108          {
109            sectionName="CONES_ORBITS";
110          }
111      }
112    else
113      {
114        if(inFile.hasProperty("MAXIMAL_CONES"))
115          {
116            sectionName="MAXIMAL_CONES";
117            sectionNameMultiplicities="MULTIPLICITIES";
118          }
119        else
120          {
121            sectionName="CONES";
122          }
123      }
124
125    /*    if(sym || readCompressedIfNotSym)
126      {
127        sectionName=(onlyMaximal)?"MAXIMAL_CONES_ORBITS":"CONES_ORBITS";
128        sectionNameMultiplicities=(onlyMaximal)?"MULTIPLICITIES_ORBITS":"DUMMY123";
129      }
130    else
131*/
132    /*{
133        sectionName="MAXIMAL_CONES";//(onlyMaximal)?"MAXIMAL_CONES":"CONES";
134        sectionNameMultiplicities="MULTIPLICITIES";//(onlyMaximal)?"MULTIPLICITIES":"DUMMY123";
135      }
136*/
137//    ZVector w2(n);
138//    if(w==0)w=&w2;
139
140 //       SymmetryGroup sym2(n);
141 //       if(sym==0)sym=&sym2;
142
143/*  sectionName=0;
144  if(inFile.hasProperty("MAXIMAL_CONES"))
145    sectionName="MAXIMAL_CONES";
146  else
147    {  if(inFile.hasProperty("CONES"))
148      sectionName="CONES";
149    else
150      assert(0);
151    }*/
152
153  vector<list<int> > cones=inFile.readMatrixIncidenceProperty(sectionName);
154//        IntegerVectorList r;
155
156        bool hasMultiplicities=inFile.hasProperty(sectionNameMultiplicities);
157        ZMatrix multiplicities(0,0);
158        if(hasMultiplicities)multiplicities=inFile.readMatrixProperty(sectionNameMultiplicities,cones.size(),1);
159
160        ZFan ret(sym);
161
162//        log2 cerr<< "Number of orbits to expand "<<cones.size()<<endl;
163        for(int i=0;i<cones.size();i++)
164        //  if(coneIndices==0 || coneIndices->count(i))
165            {
166//              log2 cerr<<"Expanding symmetries of cone"<<endl;
167              {
168                ZMatrix coneRays(0,n);
169                for(list<int>::const_iterator j=cones[i].begin();j!=cones[i].end();j++)
170                  coneRays.appendRow((rays[*j]));
171                ZCone C=ZCone::givenByRays(coneRays,linealitySpace);
172                if(hasMultiplicities)C.setMultiplicity(multiplicities[i][0]);
173//                for(SymmetryGroup::ElementContainer::const_iterator perm=sym->elements.begin();perm!=sym->elements.end();perm++)
174                  {
175//                    if(C.contains(perm.applyInverse(*w)))
176//                      {
177 //                       PolyhedralCone C2=C.permuted(*perm);
178//                        C2.canonicalize();
179//                        ret.insert(C2);
180 //                     }
181                    ret.insert(C);
182                  }
183              }
184            }
185//        return ret;
186        *this=ret;
187  }
188
189  ZFan::~ZFan()
190  {
191    if(coneCollection)
192      {
193        delete coneCollection;
194        coneCollection=0;
195      }
196    if(complex)
197      {
198        delete complex;
199        complex=0;
200      }
201  }
202  ZFan::ZFan(ZFan const& f):
203    complex(0),
204    coneCollection(0)
205  {
206    if(f.coneCollection)
207      {
208        coneCollection=new PolyhedralFan(*f.coneCollection);
209      }
210    if(f.complex)
211      {
212        complex=new SymmetricComplex(*f.complex);
213      }
214  }
215  ZFan& ZFan::operator=(ZFan const &f)
216  {
217    if(this!=&f)
218      {
219        if(complex)
220          {
221            delete complex;
222            complex=0;
223          }
224        if(coneCollection)
225          {
226            delete coneCollection;
227            coneCollection=0;
228          }
229        if(f.coneCollection)
230          {
231            coneCollection=new PolyhedralFan(*f.coneCollection);
232          }
233        if(f.complex)
234          {
235            complex=new SymmetricComplex(*f.complex);
236          }
237      }
238    return *this;
239  }
240  ZFan::ZFan(int ambientDimension):
241    complex(0)
242  {
243    coneCollection=new PolyhedralFan(ambientDimension);
244  }
245  ZFan::ZFan(SymmetryGroup const &sym_):
246    complex(0)
247  {
248    coneCollection=new PolyhedralFan(sym_);
249  }
250  ZFan ZFan::fullFan(int n)
251  {
252    ZFan ret(n);
253    ret.insert(ZCone(ZMatrix(0,n),ZMatrix(0,n)));
254    return ret;
255  }
256  ZFan ZFan::fullFan(SymmetryGroup const &sym_)
257  {
258    ZFan ret(sym_);
259    ret.insert(ZCone(ZMatrix(0,sym_.sizeOfBaseSet()),ZMatrix(0,sym_.sizeOfBaseSet())));
260    return ret;
261  }
262  int ZFan::getAmbientDimension()const
263  {
264    if(complex)
265      return complex->getAmbientDimension();
266    if(coneCollection)
267      return coneCollection->getAmbientDimension();
268    assert(0);
269    return 0;
270  }
271  void ZFan::insert(ZCone const &c)
272  {
273    ensureConeCollection();
274    killComplex();
275    coneCollection->insert(c);
276  }
277
278/*  ZFan::ZFan(int ambientDimension):
279    theFan(ambientDimension)
280  {
281
282  }*/
283/*
284ZFan::ZFan(SymmetryGroup const &sym):
285  theFan(sym)
286{
287}
288*/
289
290std::string ZFan::toString(int flags)const
291{
292  ensureComplex();
293
294  //  std::string s=complex->toString(flags);
295//  killComplex();
296//  return s;//complex->getMinDim(),complex->getMaxDim(),0,0);
297  return complex->toString(flags);//complex->getMinDim(),complex->getMaxDim(),0,0);
298//  return "NEEDTOFIXTHIS";
299
300  //return theFan.toString();
301}
302
303/*int ZFan::getAmbientDimension()const
304{
305  return theFan.getAmbientDimension();
306}
307
308
309void ZFan::insert(ZCone const &c)
310{
311  theFan.insert(c);
312}
313*/
314/*
315void ZFan::remove(ZCone const &c)
316{
317  theFan.remove(c);
318}
319*/
320/*
321ZFan::coneIterator ZFan::conesBegin()const
322{
323  return theFan.conesBegin();
324}
325
326ZFan::coneIterator ZFan::conesEnd()const
327{
328  return theFan.conesEnd();
329}
330*/
331  //  static PolyhedralFan readFan(string const &filename, bool onlyMaximal=true, IntegerVector *w=0, set<int> const *conesIndice=0, SymmetryGroup const *sym=0, bool readCompressedIfNotSym=false);
332
333}
Note: See TracBrowser for help on using the repository browser.