source: git/gfanlib/gfanlib_zfan.cpp @ 92e2cd

spielwiese
Last change on this file since 92e2cd was c4d065, checked in by Frank Seelisch <seelisch@…>, 13 years ago
coding at Goettingen (cones&fans) git-svn-id: file:///usr/local/Singular/svn/trunk@13677 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.4 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        std::cerr<<"D"<<std::endl;
60        complex->buildConeLists(false,false,&cones);
61        std::cerr<<"D"<<std::endl;
62        complex->buildConeLists(true,false,&maximalCones);
63        std::cerr<<"D"<<std::endl;
64        complex->buildConeLists(false,true,&coneOrbits);
65        std::cerr<<"D"<<std::endl;
66        complex->buildConeLists(true,true,&maximalConeOrbits);
67        std::cerr<<"D"<<std::endl;
68      }
69  }
70  ZFan::ZFan(std::istream &f):
71    coneCollection(0),
72    complex(0)
73  {
74//    PolyhedralFan PolyhedralFan::readFan(string const &filename, bool onlyMaximal, IntegerVector *w, set<int> const *coneIndices, SymmetryGroup const *sym, bool readCompressedIfNotSym)
75    PolymakeFile inFile;
76    //assert(0);
77     inFile.open(f);
78
79    int n=inFile.readCardinalProperty("AMBIENT_DIM").toInt();
80    int nRays=inFile.readCardinalProperty("N_RAYS").toInt();
81    ZMatrix rays=inFile.readMatrixProperty("RAYS",nRays,n);
82    int linealityDim=inFile.readCardinalProperty("LINEALITY_DIM").toInt();
83    ZMatrix linealitySpace=inFile.readMatrixProperty("LINEALITY_SPACE",linealityDim,n);
84
85    SymmetryGroup sym(n);
86    bool readingSymmetricComplex=false;
87    if(inFile.hasProperty("SYMMETRY_GENERATORS"))
88      {
89        sym.computeClosure(ZToIntMatrix(inFile.readMatrixProperty("SYMMETRY_GENERATORS",-1,n)));
90        readingSymmetricComplex=true;
91      }
92
93
94    const char *sectionName=0;
95    const char *sectionNameMultiplicities=0;
96    if(readingSymmetricComplex)
97      {
98        if(inFile.hasProperty("MAXIMAL_CONES_ORBITS"))
99          {
100            sectionName="MAXIMAL_CONES_ORBITS";
101            sectionNameMultiplicities="MULTIPLICITIES_ORBITS";
102          }
103        else
104          {
105            sectionName="CONES_ORBITS";
106          }
107      }
108    else
109      {
110        if(inFile.hasProperty("MAXIMAL_CONES"))
111          {
112            sectionName="MAXIMAL_CONES";
113            sectionNameMultiplicities="MULTIPLICITIES";
114          }
115        else
116          {
117            sectionName="CONES";
118          }
119      }
120
121    /*    if(sym || readCompressedIfNotSym)
122      {
123        sectionName=(onlyMaximal)?"MAXIMAL_CONES_ORBITS":"CONES_ORBITS";
124        sectionNameMultiplicities=(onlyMaximal)?"MULTIPLICITIES_ORBITS":"DUMMY123";
125      }
126    else
127*/
128    /*{
129        sectionName="MAXIMAL_CONES";//(onlyMaximal)?"MAXIMAL_CONES":"CONES";
130        sectionNameMultiplicities="MULTIPLICITIES";//(onlyMaximal)?"MULTIPLICITIES":"DUMMY123";
131      }
132*/
133//    ZVector w2(n);
134//    if(w==0)w=&w2;
135
136 //       SymmetryGroup sym2(n);
137 //       if(sym==0)sym=&sym2;
138
139/*  sectionName=0;
140  if(inFile.hasProperty("MAXIMAL_CONES"))
141    sectionName="MAXIMAL_CONES";
142  else
143    {  if(inFile.hasProperty("CONES"))
144      sectionName="CONES";
145    else
146      assert(0);
147    }*/
148
149  vector<list<int> > cones=inFile.readMatrixIncidenceProperty(sectionName);
150//        IntegerVectorList r;
151
152        bool hasMultiplicities=inFile.hasProperty(sectionNameMultiplicities);
153        ZMatrix multiplicities(0,0);
154        if(hasMultiplicities)multiplicities=inFile.readMatrixProperty(sectionNameMultiplicities,cones.size(),1);
155
156        ZFan ret(sym);
157
158//        log2 cerr<< "Number of orbits to expand "<<cones.size()<<endl;
159        for(int i=0;i<cones.size();i++)
160        //  if(coneIndices==0 || coneIndices->count(i))
161            {
162//              log2 cerr<<"Expanding symmetries of cone"<<endl;
163              {
164                ZMatrix coneRays(0,n);
165                for(list<int>::const_iterator j=cones[i].begin();j!=cones[i].end();j++)
166                  coneRays.appendRow((rays[*j]));
167                ZCone C=ZCone::givenByRays(coneRays,linealitySpace);
168                if(hasMultiplicities)C.setMultiplicity(multiplicities[i][0]);
169//                for(SymmetryGroup::ElementContainer::const_iterator perm=sym->elements.begin();perm!=sym->elements.end();perm++)
170                  {
171//                    if(C.contains(perm.applyInverse(*w)))
172//                      {
173 //                       PolyhedralCone C2=C.permuted(*perm);
174//                        C2.canonicalize();
175//                        ret.insert(C2);
176 //                     }
177                    ret.insert(C);
178                  }
179              }
180            }
181//        return ret;
182        *this=ret;
183  }
184
185  ZFan::~ZFan()
186  {
187    if(coneCollection)
188      {
189        delete coneCollection;
190        coneCollection=0;
191      }
192    if(complex)
193      {
194        delete complex;
195        complex=0;
196      }
197  }
198  ZFan::ZFan(ZFan const& f):
199    complex(0),
200    coneCollection(0)
201  {
202    if(f.coneCollection)
203      {
204        coneCollection=new PolyhedralFan(*f.coneCollection);
205      }
206    if(f.complex)
207      {
208        complex=new SymmetricComplex(*f.complex);
209      }
210  }
211  ZFan& ZFan::operator=(ZFan const &f)
212  {
213    if(this!=&f)
214      {
215std::cerr<<"COPYING\n";
216        if(complex)
217          {
218            delete complex;
219            complex=0;
220          }
221        std::cerr<<"1COPYING\n";
222        if(coneCollection)
223          {
224            delete coneCollection;
225            coneCollection=0;
226          }
227        std::cerr<<"2COPYING\n";
228        if(f.coneCollection)
229          {
230            coneCollection=new PolyhedralFan(*f.coneCollection);
231          }
232        std::cerr<<"3COPYING\n";
233        if(f.complex)
234          {
235            complex=new SymmetricComplex(*f.complex);
236          }
237        std::cerr<<"DONE COPYING\n";
238      }
239    return *this;
240  }
241  ZFan::ZFan(int ambientDimension):
242    complex(0)
243  {
244    coneCollection=new PolyhedralFan(ambientDimension);
245  }
246  ZFan::ZFan(SymmetryGroup const &sym_):
247    complex(0)
248  {
249    coneCollection=new PolyhedralFan(sym_);
250  }
251  ZFan ZFan::fullFan(int n)
252  {
253    ZFan ret(n);
254    ret.insert(ZCone(ZMatrix(0,n),ZMatrix(0,n)));
255    return ret;
256  }
257  ZFan ZFan::fullFan(SymmetryGroup const &sym_)
258  {
259    ZFan ret(sym_);
260    ret.insert(ZCone(ZMatrix(0,sym_.sizeOfBaseSet()),ZMatrix(0,sym_.sizeOfBaseSet())));
261    return ret;
262  }
263  int ZFan::getAmbientDimension()const
264  {
265    if(complex)
266      return complex->getAmbientDimension();
267    if(coneCollection)
268      return coneCollection->getAmbientDimension();
269    assert(0);
270    return 0;
271  }
272  void ZFan::insert(ZCone const &c)
273  {
274    ensureConeCollection();
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  return complex->toString(flags);//complex->getMinDim(),complex->getMaxDim(),0,0);
294//  return "NEEDTOFIXTHIS";
295
296  //return theFan.toString();
297}
298
299/*int ZFan::getAmbientDimension()const
300{
301  return theFan.getAmbientDimension();
302}
303
304
305void ZFan::insert(ZCone const &c)
306{
307  theFan.insert(c);
308}
309*/
310/*
311void ZFan::remove(ZCone const &c)
312{
313  theFan.remove(c);
314}
315*/
316/*
317ZFan::coneIterator ZFan::conesBegin()const
318{
319  return theFan.conesBegin();
320}
321
322ZFan::coneIterator ZFan::conesEnd()const
323{
324  return theFan.conesEnd();
325}
326*/
327  //  static PolyhedralFan readFan(string const &filename, bool onlyMaximal=true, IntegerVector *w=0, set<int> const *conesIndice=0, SymmetryGroup const *sym=0, bool readCompressedIfNotSym=false);
328
329}
Note: See TracBrowser for help on using the repository browser.