source: git/gfanlib/gfanlib_zfan.cpp @ 5a6083

spielwiese
Last change on this file since 5a6083 was 19addd1, checked in by Yue Ren <ren@…>, 10 years ago
fix: warnings
  • Property mode set to 100644
File size: 9.9 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>=(int)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    this->ensureComplex();
34    return numberOf(table(orbit,maximal),d);
35  }
36  ZCone ZFan::getCone(int dimension, int index, bool orbit, bool maximal)const
37  {
38    IntVector indices=getConeIndices(dimension,index,orbit,maximal);
39    return this->complex->makeZCone(indices);
40  }
41  IntVector ZFan::getConeIndices(int dimension, int index, bool orbit, bool maximal)const
42  {
43    assert(index>=0);
44    assert(index<numberOfConesOfDimension(dimension,orbit,maximal));
45    return table(orbit,maximal)[dimension][index];
46  }
47  void ZFan::ensureConeCollection()const
48  {
49    if(!coneCollection)
50      {
51        assert(0);
52      }
53  }
54  void ZFan::ensureComplex()const
55  {
56    if(!complex)
57      {
58        assert(coneCollection);
59        complex = new SymmetricComplex(coneCollection->toSymmetricComplex());
60        complex->buildConeLists(false,false,&cones);
61        complex->buildConeLists(true,false,&maximalCones);
62        complex->buildConeLists(false,true,&coneOrbits);
63        complex->buildConeLists(true,true,&maximalConeOrbits);
64      }
65  }
66  void ZFan::killComplex()const
67  {
68    if(complex)
69      {
70        delete complex;
71        complex=0;
72      }
73  }
74
75  ZFan::ZFan(std::istream &f):
76    coneCollection(0),
77    complex(0)
78  {
79//    PolyhedralFan PolyhedralFan::readFan(string const &filename, bool onlyMaximal, IntegerVector *w, set<int> const *coneIndices, SymmetryGroup const *sym, bool readCompressedIfNotSym)
80    PolymakeFile inFile;
81    //assert(0);
82     inFile.open(f);
83
84    int n=inFile.readCardinalProperty("AMBIENT_DIM").toInt();
85    int nRays=inFile.readCardinalProperty("N_RAYS").toInt();
86    ZMatrix rays=inFile.readMatrixProperty("RAYS",nRays,n);
87    int linealityDim=inFile.readCardinalProperty("LINEALITY_DIM").toInt();
88    ZMatrix linealitySpace=inFile.readMatrixProperty("LINEALITY_SPACE",linealityDim,n);
89
90    SymmetryGroup sym(n);
91    bool readingSymmetricComplex=false;
92    if(inFile.hasProperty("SYMMETRY_GENERATORS"))
93      {
94        sym.computeClosure(ZToIntMatrix(inFile.readMatrixProperty("SYMMETRY_GENERATORS",-1,n)));
95        readingSymmetricComplex=true;
96      }
97
98
99    const char *sectionName=0;
100    const char *sectionNameMultiplicities=0;
101    if(readingSymmetricComplex)
102      {
103        if(inFile.hasProperty("MAXIMAL_CONES_ORBITS"))
104          {
105            sectionName="MAXIMAL_CONES_ORBITS";
106            sectionNameMultiplicities="MULTIPLICITIES_ORBITS";
107          }
108        else
109          {
110            sectionName="CONES_ORBITS";
111          }
112      }
113    else
114      {
115        if(inFile.hasProperty("MAXIMAL_CONES"))
116          {
117            sectionName="MAXIMAL_CONES";
118            sectionNameMultiplicities="MULTIPLICITIES";
119          }
120        else
121          {
122            sectionName="CONES";
123          }
124      }
125
126    /*    if(sym || readCompressedIfNotSym)
127      {
128        sectionName=(onlyMaximal)?"MAXIMAL_CONES_ORBITS":"CONES_ORBITS";
129        sectionNameMultiplicities=(onlyMaximal)?"MULTIPLICITIES_ORBITS":"DUMMY123";
130      }
131    else
132*/
133    /*{
134        sectionName="MAXIMAL_CONES";//(onlyMaximal)?"MAXIMAL_CONES":"CONES";
135        sectionNameMultiplicities="MULTIPLICITIES";//(onlyMaximal)?"MULTIPLICITIES":"DUMMY123";
136      }
137*/
138//    ZVector w2(n);
139//    if(w==0)w=&w2;
140
141 //       SymmetryGroup sym2(n);
142 //       if(sym==0)sym=&sym2;
143
144/*  sectionName=0;
145  if(inFile.hasProperty("MAXIMAL_CONES"))
146    sectionName="MAXIMAL_CONES";
147  else
148    {  if(inFile.hasProperty("CONES"))
149      sectionName="CONES";
150    else
151      assert(0);
152    }*/
153
154  vector<list<int> > cones=inFile.readMatrixIncidenceProperty(sectionName);
155//        IntegerVectorList r;
156
157        bool hasMultiplicities=inFile.hasProperty(sectionNameMultiplicities);
158        ZMatrix multiplicities(0,0);
159        if(hasMultiplicities)multiplicities=inFile.readMatrixProperty(sectionNameMultiplicities,cones.size(),1);
160
161        ZFan ret(sym);
162
163//        log2 cerr<< "Number of orbits to expand "<<cones.size()<<endl;
164        for(unsigned i=0;i<cones.size();i++)
165        //  if(coneIndices==0 || coneIndices->count(i))
166            {
167//              log2 cerr<<"Expanding symmetries of cone"<<endl;
168              {
169                ZMatrix coneRays(0,n);
170                for(list<int>::const_iterator j=cones[i].begin();j!=cones[i].end();j++)
171                  coneRays.appendRow((rays[*j]));
172                ZCone C=ZCone::givenByRays(coneRays,linealitySpace);
173                if(hasMultiplicities)C.setMultiplicity(multiplicities[i][0]);
174//                for(SymmetryGroup::ElementContainer::const_iterator perm=sym->elements.begin();perm!=sym->elements.end();perm++)
175                  {
176//                    if(C.contains(perm.applyInverse(*w)))
177//                      {
178 //                       PolyhedralCone C2=C.permuted(*perm);
179//                        C2.canonicalize();
180//                        ret.insert(C2);
181 //                     }
182                    ret.insert(C);
183                  }
184              }
185            }
186//        return ret;
187        *this=ret;
188  }
189
190  ZFan::~ZFan()
191  {
192    if(coneCollection)
193      {
194        delete coneCollection;
195        coneCollection=0;
196      }
197    if(complex)
198      {
199        delete complex;
200        complex=0;
201      }
202  }
203  ZFan::ZFan(ZFan const& f):
204    coneCollection(0),
205    complex(0),
206    cones(f.table(0,0)),
207    maximalCones(f.table(0,1)),
208    coneOrbits(f.table(1,0)),
209    maximalConeOrbits(f.table(1,1))
210  {
211    if(f.coneCollection)
212      {
213        coneCollection=new PolyhedralFan(*f.coneCollection);
214      }
215    if(f.complex)
216      {
217        complex=new SymmetricComplex(*f.complex);
218      }
219  }
220  ZFan& ZFan::operator=(ZFan const &f)
221  {
222    if(this!=&f)
223      {
224        if(complex)
225          {
226            delete complex;
227            complex=0;
228          }
229        if(coneCollection)
230          {
231            delete coneCollection;
232            coneCollection=0;
233          }
234        if(f.coneCollection)
235          {
236            coneCollection=new PolyhedralFan(*f.coneCollection);
237          }
238        if(f.complex)
239          {
240            complex=new SymmetricComplex(*f.complex);
241          }
242      }
243    return *this;
244  }
245  ZFan::ZFan(int ambientDimension):
246    complex(0)
247  {
248    coneCollection=new PolyhedralFan(ambientDimension);
249  }
250  ZFan::ZFan(SymmetryGroup const &sym_):
251    complex(0)
252  {
253    coneCollection=new PolyhedralFan(sym_);
254  }
255  ZFan ZFan::fullFan(int n)
256  {
257    ZFan ret(n);
258    ret.insert(ZCone(ZMatrix(0,n),ZMatrix(0,n)));
259    return ret;
260  }
261  ZFan ZFan::fullFan(SymmetryGroup const &sym_)
262  {
263    ZFan ret(sym_);
264    ret.insert(ZCone(ZMatrix(0,sym_.sizeOfBaseSet()),ZMatrix(0,sym_.sizeOfBaseSet())));
265    return ret;
266  }
267  int ZFan::getAmbientDimension()const
268  {
269    if(complex)
270      return complex->getAmbientDimension();
271    if(coneCollection)
272      return coneCollection->getAmbientDimension();
273    assert(0);
274    return 0;
275  }
276  int ZFan::getCodimension()const
277  {
278    if(complex)
279      return complex->getAmbientDimension()-complex->getMaxDim();
280    if(coneCollection)
281      return coneCollection->getAmbientDimension()-coneCollection->getMaxDimension();
282    assert(0);
283    return 0;
284  }
285  int ZFan::getDimension()const
286  {
287    if(complex)
288      return complex->getMaxDim();
289    if(coneCollection)
290      return coneCollection->getMaxDimension();
291    assert(0);
292    return 0;
293  }
294  int ZFan::getLinealityDimension()const
295  {
296    if(complex)
297      return complex->getLinDim();
298    if(coneCollection)
299      return coneCollection->dimensionOfLinealitySpace();
300    assert(0);
301    return 0;
302  }
303  ZVector ZFan::getFVector()const
304  {
305    ensureComplex();
306    return complex->fvector();
307  }
308  bool ZFan::isSimplicial()const
309  {
310    ensureComplex();
311    return complex->isSimplicial();
312  }
313  bool ZFan::isPure()const
314  {
315    ensureComplex();
316    return complex->isPure();
317  }
318  bool ZFan::isComplete()const
319  {
320    ensureConeCollection();
321    if(coneCollection->isEmpty())
322      return 0;
323    int ambientdim=coneCollection->getAmbientDimension();
324    int linealitydim=coneCollection->dimensionOfLinealitySpace();
325    return (ambientdim==linealitydim);
326  }
327  void ZFan::insert(ZCone const &c)
328  {
329    ensureConeCollection();
330    killComplex();
331    coneCollection->insert(c);
332  }
333  void ZFan::remove(ZCone const &c)
334  {
335    ensureConeCollection();
336    killComplex();
337    coneCollection->remove(c);
338  }
339
340/*  ZFan::ZFan(int ambientDimension):
341    theFan(ambientDimension)
342  {
343
344  }*/
345/*
346ZFan::ZFan(SymmetryGroup const &sym):
347  theFan(sym)
348{
349}
350*/
351
352std::string ZFan::toString(int flags)const
353{
354  ensureComplex();
355
356  //  std::string s=complex->toString(flags);
357//  killComplex();
358//  return s;//complex->getMinDim(),complex->getMaxDim(),0,0);
359  return complex->toString(flags);//complex->getMinDim(),complex->getMaxDim(),0,0);
360//  return "NEEDTOFIXTHIS";
361
362  //return theFan.toString();
363}
364
365std::string ZFan::toStringJustRaysAndMaximalCones(int flags)const
366{
367  ensureComplex();
368  return complex->toStringJustRaysAndMaximalCones(flags);
369}
370
371/*int ZFan::getAmbientDimension()const
372{
373  return theFan.getAmbientDimension();
374}
375
376
377void ZFan::insert(ZCone const &c)
378{
379  theFan.insert(c);
380}
381*/
382/*
383void ZFan::remove(ZCone const &c)
384{
385  theFan.remove(c);
386}
387*/
388/*
389ZFan::coneIterator ZFan::conesBegin()const
390{
391  return theFan.conesBegin();
392}
393
394ZFan::coneIterator ZFan::conesEnd()const
395{
396  return theFan.conesEnd();
397}
398*/
399  //  static PolyhedralFan readFan(string const &filename, bool onlyMaximal=true, IntegerVector *w=0, set<int> const *conesIndice=0, SymmetryGroup const *sym=0, bool readCompressedIfNotSym=false);
400
401}
Note: See TracBrowser for help on using the repository browser.