1 | /* |
---|
2 | * gfanlib_symmetriccomplex.cpp |
---|
3 | * |
---|
4 | * Created on: Nov 16, 2010 |
---|
5 | * Author: anders |
---|
6 | */ |
---|
7 | |
---|
8 | #include "gfanlib_symmetriccomplex.h" |
---|
9 | #include "gfanlib_polymakefile.h" |
---|
10 | |
---|
11 | #include <sstream> |
---|
12 | #include <iostream> |
---|
13 | |
---|
14 | namespace gfan{ |
---|
15 | |
---|
16 | SymmetricComplex::Cone::Cone(std::set<int> const &indices_, int dimension_, Integer multiplicity_, bool sortWithSymmetry, SymmetricComplex const &complex): |
---|
17 | isKnownToBeNonMaximalFlag(false), |
---|
18 | dimension(dimension_), |
---|
19 | multiplicity(multiplicity_), |
---|
20 | sortKeyPermutation(complex.n) |
---|
21 | { |
---|
22 | indices=IntVector(indices_.size()); |
---|
23 | int j=0; |
---|
24 | for(std::set<int>::const_iterator i=indices_.begin();i!=indices_.end();i++,j++) |
---|
25 | indices[j]=*i; |
---|
26 | |
---|
27 | ZMatrix const &vertices=complex.getVertices(); |
---|
28 | ZVector sum(vertices.getWidth()); |
---|
29 | for(unsigned i=0;i<indices.size();i++) |
---|
30 | sum+=vertices[indices[i]]; |
---|
31 | |
---|
32 | if(sortWithSymmetry) |
---|
33 | { |
---|
34 | sortKey=complex.sym.orbitRepresentative(sum,&sortKeyPermutation); |
---|
35 | } |
---|
36 | else |
---|
37 | { |
---|
38 | sortKey=sum; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | int SymmetricComplex::indexOfVertex(ZVector const &v)const |
---|
44 | { |
---|
45 | // std::cerr<<v<<std::endl<<"In"; |
---|
46 | // for(std::map<ZVector,int>::const_iterator i =indexMap.begin();i!=indexMap.end();i++)std::cerr<<i->first; |
---|
47 | |
---|
48 | std::map<ZVector,int>::const_iterator it=indexMap.find(v); |
---|
49 | assert(it!=indexMap.end()); |
---|
50 | return it->second; |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | void SymmetricComplex::Cone::remap(SymmetricComplex &complex) |
---|
55 | { |
---|
56 | ZMatrix const &vertices=complex.getVertices(); |
---|
57 | ZVector sum(vertices.getWidth()); |
---|
58 | for(unsigned i=0;i<indices.size();i++) |
---|
59 | sum+=vertices[indices[i]]; |
---|
60 | |
---|
61 | int n=sum.size(); |
---|
62 | Permutation const &bestPermutation=sortKeyPermutation; |
---|
63 | |
---|
64 | assert((int)bestPermutation.size()==n); |
---|
65 | |
---|
66 | IntVector indicesNew(indices.size()); |
---|
67 | int I=0; |
---|
68 | for(unsigned i=0;i<indices.size();i++,I++) |
---|
69 | { |
---|
70 | ZVector ny=bestPermutation.apply(complex.vertices[indices[i]]); |
---|
71 | std::map<ZVector,int>::const_iterator it=complex.indexMap.find(ny); |
---|
72 | assert(it!=complex.indexMap.end()); |
---|
73 | indicesNew[I]=it->second; |
---|
74 | } |
---|
75 | indices=indicesNew; |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | std::set<int> SymmetricComplex::Cone::indexSet()const |
---|
80 | { |
---|
81 | std::set<int> ret; |
---|
82 | for(unsigned i=0;i<indices.size();i++) |
---|
83 | ret.insert(indices[i]); |
---|
84 | |
---|
85 | return ret; |
---|
86 | } |
---|
87 | |
---|
88 | bool SymmetricComplex::Cone::isSubsetOf(Cone const &c)const |
---|
89 | { |
---|
90 | int next=0; |
---|
91 | for(unsigned i=0;i<indices.size();i++) |
---|
92 | { |
---|
93 | while(1) |
---|
94 | { |
---|
95 | if(next>=(int)c.indices.size())return false; |
---|
96 | if(indices[i]==c.indices[next])break; |
---|
97 | next++; |
---|
98 | } |
---|
99 | } |
---|
100 | return true; |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | SymmetricComplex::Cone SymmetricComplex::Cone::permuted(Permutation const &permutation, SymmetricComplex const &complex, bool withSymmetry)const |
---|
105 | { |
---|
106 | std::set<int> r; |
---|
107 | for(unsigned i=0;i<indices.size();i++) |
---|
108 | { |
---|
109 | ZVector ny=permutation.apply(complex.vertices[indices[i]]); |
---|
110 | std::map<ZVector,int>::const_iterator it=complex.indexMap.find(ny); |
---|
111 | if(it==complex.indexMap.end()) |
---|
112 | { |
---|
113 | // AsciiPrinter(Stderr).printVector(complex.vertices[indices[i]]); |
---|
114 | // AsciiPrinter(Stderr).printVector(ny); |
---|
115 | |
---|
116 | assert(0); |
---|
117 | } |
---|
118 | r.insert(it->second); |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | return Cone(r,dimension,multiplicity,withSymmetry,complex); |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | bool SymmetricComplex::Cone::operator<(Cone const & b)const |
---|
127 | { |
---|
128 | return sortKey<b.sortKey; |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | bool SymmetricComplex::Cone::isSimplicial(int linealityDim)const |
---|
133 | { |
---|
134 | return (indices.size()+linealityDim)==dimension; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | ZMatrix SymmetricComplex::Cone::orthogonalComplement(SymmetricComplex &complex)const |
---|
139 | { |
---|
140 | ZMatrix l; |
---|
141 | for(unsigned i=0;i<indices.size();i++) |
---|
142 | l.appendRow(complex.vertices[indices[i]]); |
---|
143 | |
---|
144 | return l.reduceAndComputeKernel(); |
---|
145 | // FieldMatrix m=integerMatrixToFieldMatrix(rowsToIntegerMatrix(l,complex.n),Q); |
---|
146 | // return fieldMatrixToIntegerMatrixPrimitive(m.reduceAndComputeKernel()).getRows(); |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | SymmetricComplex::SymmetricComplex(ZMatrix const &rays, ZMatrix const &linealitySpace_, SymmetryGroup const &sym_): |
---|
151 | n(rays.getWidth()), |
---|
152 | linealitySpace(canonicalizeSubspace(linealitySpace_)), |
---|
153 | sym(sym_), |
---|
154 | dimension(-1) |
---|
155 | { |
---|
156 | assert(rays.getWidth()==linealitySpace.getWidth()); |
---|
157 | // vertices=rowsToIntegerMatrix(v,n); |
---|
158 | vertices=rays; |
---|
159 | |
---|
160 | for(int i=0;i<vertices.getHeight();i++)indexMap[vertices[i]]=i; |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | bool SymmetricComplex::contains(Cone const &c)const |
---|
165 | { |
---|
166 | Cone temp=c; |
---|
167 | return cones.find(temp)!=cones.end();///////////////////!!!!!!!!!!!!!!!!!!!!!!! |
---|
168 | } |
---|
169 | |
---|
170 | |
---|
171 | void SymmetricComplex::insert(Cone const &c) |
---|
172 | { |
---|
173 | if(c.dimension>dimension)dimension=c.dimension; |
---|
174 | if(!contains(c))//#2 |
---|
175 | { |
---|
176 | cones.insert(c); |
---|
177 | } |
---|
178 | else |
---|
179 | { |
---|
180 | if(c.isKnownToBeNonMaximal()){cones.erase(c);cones.insert(c);}// mark as non-maximal |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | int SymmetricComplex::getMaxDim()const |
---|
186 | { |
---|
187 | return dimension; |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | int SymmetricComplex::getMinDim()const |
---|
192 | { |
---|
193 | int ret=100000; |
---|
194 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
195 | { |
---|
196 | if(i->dimension<ret)ret=i->dimension; |
---|
197 | } |
---|
198 | return ret; |
---|
199 | } |
---|
200 | |
---|
201 | |
---|
202 | int SymmetricComplex::getLinDim()const |
---|
203 | { |
---|
204 | ZMatrix zm=linealitySpace; |
---|
205 | return zm.reduceAndComputeRank(); |
---|
206 | } |
---|
207 | |
---|
208 | bool SymmetricComplex::isMaximal(Cone const &c)const |
---|
209 | { |
---|
210 | if(c.isKnownToBeNonMaximal())return false; |
---|
211 | if(c.dimension==dimension)return true; |
---|
212 | for(SymmetryGroup::ElementContainer::const_iterator k=sym.elements.begin();k!=sym.elements.end();k++) |
---|
213 | { |
---|
214 | Cone c2=c.permuted(*k,*this,false); |
---|
215 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
216 | { |
---|
217 | if(i->dimension>c.dimension) |
---|
218 | if(c2.isSubsetOf(*i) && !i->isSubsetOf(c2))return false; |
---|
219 | } |
---|
220 | } |
---|
221 | return true; |
---|
222 | } |
---|
223 | |
---|
224 | #if 0 |
---|
225 | IntVector SymmetricComplex::dimensionsAtInfinity()const |
---|
226 | { |
---|
227 | /* Using a double description like method this routine computes the |
---|
228 | dimension of the intersection of each cone in the complex with |
---|
229 | the plane x_0=0 */ |
---|
230 | IntVector ret(cones.size()); |
---|
231 | |
---|
232 | int I=0; |
---|
233 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++,I++) |
---|
234 | { |
---|
235 | ZMatrix raysAtInfinity; |
---|
236 | for(int j=0;j<i->indices.size();j++) |
---|
237 | { |
---|
238 | if(vertices[i->indices[j]][0]==0)raysAtInfinity.push_back(vertices[i->indices[j]]); |
---|
239 | for(vector<int>::const_iterator k=j;k!=i->indices.end();k++) |
---|
240 | if(vertices[*j][0]*vertices[*k][0]<0) |
---|
241 | raysAtInfinity.push_back(((vertices[*j][0]>0)?1:-1)*(vertices[*j][0])*vertices[*k]+ |
---|
242 | ((vertices[*k][0]>0)?1:-1)*(vertices[*k][0])*vertices[*j]); |
---|
243 | } |
---|
244 | ret[I]=rankOfMatrix(raysAtInfinity); |
---|
245 | } |
---|
246 | return ret; |
---|
247 | } |
---|
248 | #endif |
---|
249 | |
---|
250 | void SymmetricComplex::buildConeLists(bool onlyMaximal, bool compressed, std::vector<std::vector<IntVector > >*conelist/*, ZMatrix *multiplicities*/)const |
---|
251 | { |
---|
252 | int dimLow=this->linealitySpace.getHeight(); |
---|
253 | int dimHigh=this->getMaxDim(); |
---|
254 | if(dimHigh<dimLow)dimHigh=dimLow-1; |
---|
255 | if(conelist)*conelist=std::vector<std::vector<IntVector> >(dimHigh-dimLow+1); |
---|
256 | for(int d=dimLow;d<=dimHigh;d++) |
---|
257 | { |
---|
258 | int numberOfOrbitsOutput=0; |
---|
259 | int numberOfOrbitsOfThisDimension=0; |
---|
260 | // bool newDimension=true; |
---|
261 | { |
---|
262 | int I=0; |
---|
263 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++,I++) |
---|
264 | if(i->dimension==d) |
---|
265 | { |
---|
266 | numberOfOrbitsOfThisDimension++; |
---|
267 | if(!onlyMaximal || isMaximal(*i)) |
---|
268 | { |
---|
269 | numberOfOrbitsOutput++; |
---|
270 | // bool isMax=isMaximal(*i); |
---|
271 | // bool newOrbit=true; |
---|
272 | std::set<std::set<int> > temp; |
---|
273 | for(SymmetryGroup::ElementContainer::const_iterator k=sym.elements.begin();k!=sym.elements.end();k++) |
---|
274 | { |
---|
275 | Cone temp1=i->permuted(*k,*this,false); |
---|
276 | temp.insert(temp1.indexSet()); |
---|
277 | if(compressed)break; |
---|
278 | } |
---|
279 | for(std::set<std::set<int> >::const_iterator j=temp.begin();j!=temp.end();j++) |
---|
280 | { |
---|
281 | IntVector temp; |
---|
282 | for(std::set<int>::const_iterator k=j->begin();k!=j->end();k++)temp.push_back(*k); |
---|
283 | if(conelist)(*conelist)[d-dimLow].push_back(temp); |
---|
284 | /* if(isMax)if(multiplicities) |
---|
285 | { |
---|
286 | |
---|
287 | *multiplicities << i->multiplicity; |
---|
288 | if(group)if(newOrbit)*multiplicities << "\t# New orbit"; |
---|
289 | if(newDimension)*multiplicities << "\t# Dimension "<<d; |
---|
290 | *multiplicities << std::endl; |
---|
291 | }*/ |
---|
292 | // newOrbit=false; |
---|
293 | // newDimension=false; |
---|
294 | } |
---|
295 | } |
---|
296 | } |
---|
297 | } |
---|
298 | } |
---|
299 | |
---|
300 | } |
---|
301 | |
---|
302 | std::string SymmetricComplex::toStringJustCones(int dimLow, int dimHigh, bool onlyMaximal, bool group, std::ostream *multiplicities, bool compressed, bool /*tPlaneSort*/)const |
---|
303 | { |
---|
304 | std::stringstream ret; |
---|
305 | |
---|
306 | ZVector additionalSortKeys(cones.size()); |
---|
307 | // if(tPlaneSort)additionalSortKeys=dimensionsAtInfinity(); |
---|
308 | // Integer lowKey=additionalSortKeys.min(); |
---|
309 | // Integer highKey=additionalSortKeys.max(); |
---|
310 | |
---|
311 | for(int d=dimLow;d<=dimHigh;d++) |
---|
312 | { |
---|
313 | int numberOfOrbitsOutput=0; |
---|
314 | int numberOfOrbitsOfThisDimension=0; |
---|
315 | bool newDimension=true; |
---|
316 | // for(int key=lowKey;key<=highKey;key++) |
---|
317 | { |
---|
318 | int I=0; |
---|
319 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++,I++) |
---|
320 | // if(additionalSortKeys[I]==key) |
---|
321 | if(i->dimension==d) |
---|
322 | { |
---|
323 | numberOfOrbitsOfThisDimension++; |
---|
324 | if(!onlyMaximal || isMaximal(*i)) |
---|
325 | { |
---|
326 | numberOfOrbitsOutput++; |
---|
327 | bool isMax=isMaximal(*i); |
---|
328 | bool newOrbit=true; |
---|
329 | std::set<std::set<int> > temp; |
---|
330 | for(SymmetryGroup::ElementContainer::const_iterator k=sym.elements.begin();k!=sym.elements.end();k++) |
---|
331 | { |
---|
332 | Cone temp1=i->permuted(*k,*this,false); |
---|
333 | temp.insert(temp1.indexSet()); |
---|
334 | if(compressed)break; |
---|
335 | } |
---|
336 | for(std::set<std::set<int> >::const_iterator j=temp.begin();j!=temp.end();j++) |
---|
337 | { |
---|
338 | ret << "{"; |
---|
339 | for(std::set<int>::const_iterator a=j->begin();a!=j->end();a++) |
---|
340 | { |
---|
341 | if(a!=j->begin())ret<<" "; |
---|
342 | ret << *a; |
---|
343 | } |
---|
344 | ret << "}"; |
---|
345 | if(group)if(newOrbit)ret << "\t# New orbit"; |
---|
346 | if(newDimension)ret << "\t# Dimension "<<d; |
---|
347 | ret <<std::endl; |
---|
348 | if(isMax)if(multiplicities) |
---|
349 | { |
---|
350 | *multiplicities << i->multiplicity; |
---|
351 | if(group)if(newOrbit)*multiplicities << "\t# New orbit"; |
---|
352 | if(newDimension)*multiplicities << "\t# Dimension "<<d; |
---|
353 | *multiplicities << std::endl; |
---|
354 | } |
---|
355 | newOrbit=false; |
---|
356 | newDimension=false; |
---|
357 | } |
---|
358 | } |
---|
359 | } |
---|
360 | } |
---|
361 | } |
---|
362 | |
---|
363 | return ret.str(); |
---|
364 | } |
---|
365 | |
---|
366 | |
---|
367 | std::string SymmetricComplex::toStringJustRaysAndMaximalCones(int flags)const |
---|
368 | { |
---|
369 | PolymakeFile polymakeFile; |
---|
370 | polymakeFile.create("NONAME","PolyhedralFan","PolyhedralFan",flags&FPF_xml); |
---|
371 | polymakeFile.writeMatrixProperty("RAYS",vertices,true); |
---|
372 | polymakeFile.writeStringProperty("MAXIMAL_CONES",toStringJustCones(getMinDim(),getMaxDim(),true,flags&FPF_group, 0,false,flags&FPF_tPlaneSort)); |
---|
373 | |
---|
374 | std::stringstream s; |
---|
375 | polymakeFile.writeStream(s); |
---|
376 | return s.str(); |
---|
377 | } |
---|
378 | |
---|
379 | |
---|
380 | ZVector SymmetricComplex::fvector(bool boundedPart)const |
---|
381 | { |
---|
382 | int min=getMinDim(); |
---|
383 | int dimHigh=getMaxDim(); |
---|
384 | if(dimHigh<min)dimHigh=min-1; |
---|
385 | ZVector ret(dimHigh-min+1); |
---|
386 | |
---|
387 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
388 | { |
---|
389 | bool doAdd=!boundedPart; |
---|
390 | if(boundedPart) |
---|
391 | { |
---|
392 | bool isBounded=true; |
---|
393 | for(unsigned j=0;j<i->indices.size();j++) |
---|
394 | if(vertices[i->indices[j]][0].sign()==0)isBounded=false; |
---|
395 | doAdd=isBounded; |
---|
396 | } |
---|
397 | if(doAdd) |
---|
398 | ret[i->dimension-min]+=Integer(sym.orbitSize(i->sortKey)); |
---|
399 | } |
---|
400 | return ret; |
---|
401 | } |
---|
402 | |
---|
403 | |
---|
404 | bool SymmetricComplex::isPure()const |
---|
405 | { |
---|
406 | int dim=-1; |
---|
407 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
408 | { |
---|
409 | if(isMaximal(*i)) |
---|
410 | { |
---|
411 | int dim2=i->dimension; |
---|
412 | if(dim==-1)dim=dim2; |
---|
413 | if(dim!=dim2)return false; |
---|
414 | } |
---|
415 | } |
---|
416 | return true; |
---|
417 | } |
---|
418 | |
---|
419 | |
---|
420 | bool SymmetricComplex::isSimplicial()const |
---|
421 | { |
---|
422 | int linealityDim=getMinDim(); |
---|
423 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
424 | if(!i->isSimplicial(linealityDim)) |
---|
425 | return false; |
---|
426 | return true; |
---|
427 | } |
---|
428 | |
---|
429 | |
---|
430 | void SymmetricComplex::remap() |
---|
431 | { |
---|
432 | for(ConeContainer::iterator i=cones.begin();i!=cones.end();i++) |
---|
433 | { |
---|
434 | Cone const&j=*i; |
---|
435 | Cone &j2=const_cast<Cone&>(j);//DANGER: cast away const. This does not change the sort key in the container, so should be OK. |
---|
436 | j2.remap(*this); |
---|
437 | } |
---|
438 | } |
---|
439 | |
---|
440 | |
---|
441 | int SymmetricComplex::numberOfConesOfDimension(int d)const |
---|
442 | { |
---|
443 | assert(sym.isTrivial()); |
---|
444 | |
---|
445 | int ret=0; |
---|
446 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
447 | if(d==i->dimension) |
---|
448 | { |
---|
449 | ret++; |
---|
450 | } |
---|
451 | return ret; |
---|
452 | } |
---|
453 | |
---|
454 | |
---|
455 | int SymmetricComplex::dimensionIndex(Cone const &c) |
---|
456 | { |
---|
457 | assert(sym.isTrivial()); |
---|
458 | |
---|
459 | int ret=0; |
---|
460 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
461 | if(c.dimension==i->dimension) |
---|
462 | { |
---|
463 | if(!(c<*i)&&!(*i<c)) |
---|
464 | return ret; |
---|
465 | else |
---|
466 | ret++; |
---|
467 | } |
---|
468 | return ret; |
---|
469 | } |
---|
470 | |
---|
471 | #if 0 |
---|
472 | void SymmetricComplex::boundary(Cone const &c, vector<int> &indices_, vector<int> &signs) |
---|
473 | { |
---|
474 | indices_=vector<int>(); |
---|
475 | signs=vector<int>(); |
---|
476 | int d=c.dimension; |
---|
477 | |
---|
478 | |
---|
479 | IntegerVectorList l; |
---|
480 | for(int i=0;i<c.indices.size();i++) |
---|
481 | l.push_back(vertices[c.indices[i]]); |
---|
482 | IntegerVectorList facetNormals=PolyhedralCone(l,IntegerVectorList(),n).extremeRays(); |
---|
483 | IntegerVectorList complementBasis=c.orthogonalComplement(*this); |
---|
484 | for(IntegerVectorList::const_iterator i=facetNormals.begin();i!=facetNormals.end();i++) |
---|
485 | { |
---|
486 | IntegerVectorList complementBasis1=complementBasis; |
---|
487 | complementBasis1.push_back(*i); |
---|
488 | FieldMatrix m=integerMatrixToFieldMatrix(rowsToIntegerMatrix(complementBasis1,n),Q); |
---|
489 | IntegerVectorList completion=fieldMatrixToIntegerMatrixPrimitive(m.reduceAndComputeKernel()).getRows(); |
---|
490 | for(IntegerVectorList::const_iterator j=completion.begin();j!=completion.end();j++)complementBasis1.push_back(*j); |
---|
491 | int sign=determinantSign(complementBasis1); |
---|
492 | |
---|
493 | set<int> indices; |
---|
494 | for(vector<int>::const_iterator j=c.indices.begin();j!=c.indices.end();j++)if(dotLong(vertices[*j],*i)==0)indices.insert(*j); |
---|
495 | Cone facet(indices,d-1,1,true,*this); |
---|
496 | IntegerVectorList complementBasis2=facet.orthogonalComplement(*this); |
---|
497 | for(IntegerVectorList::const_iterator j=completion.begin();j!=completion.end();j++)complementBasis2.push_back(*j); |
---|
498 | indices_.push_back(dimensionIndex(facet)); |
---|
499 | signs.push_back(sign*determinantSign(complementBasis2)); |
---|
500 | } |
---|
501 | } |
---|
502 | |
---|
503 | |
---|
504 | IntegerMatrix SymmetricComplex::boundaryMap(int d) |
---|
505 | { |
---|
506 | assert(sym.isTrivial()); |
---|
507 | |
---|
508 | IntegerMatrix ret(numberOfConesOfDimension(d-1),numberOfConesOfDimension(d)); |
---|
509 | |
---|
510 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
511 | if(d==i->dimension) |
---|
512 | { |
---|
513 | int I=dimensionIndex(*i); |
---|
514 | vector<int> indices; |
---|
515 | vector<int> signs; |
---|
516 | boundary(*i,indices,signs); |
---|
517 | for(int j=0;j<indices.size();j++) |
---|
518 | { |
---|
519 | ret[indices[j]][I]+=signs[j]; |
---|
520 | } |
---|
521 | } |
---|
522 | return ret; |
---|
523 | } |
---|
524 | #endif |
---|
525 | |
---|
526 | |
---|
527 | std::string SymmetricComplex::toString(int flags)const |
---|
528 | { |
---|
529 | PolymakeFile polymakeFile; |
---|
530 | polymakeFile.create("NONAME","PolyhedralFan","PolyhedralFan",flags&FPF_xml); |
---|
531 | |
---|
532 | |
---|
533 | |
---|
534 | |
---|
535 | |
---|
536 | polymakeFile.writeCardinalProperty("AMBIENT_DIM",n); |
---|
537 | polymakeFile.writeCardinalProperty("DIM",getMaxDim()); |
---|
538 | polymakeFile.writeCardinalProperty("LINEALITY_DIM",linealitySpace.getHeight()); |
---|
539 | // polymakeFile.writeMatrixProperty("RAYS",rays,true,comments); |
---|
540 | polymakeFile.writeMatrixProperty("RAYS",vertices,true); |
---|
541 | polymakeFile.writeCardinalProperty("N_RAYS",vertices.getHeight()); |
---|
542 | |
---|
543 | |
---|
544 | polymakeFile.writeMatrixProperty("LINEALITY_SPACE",linealitySpace,n); |
---|
545 | polymakeFile.writeMatrixProperty("ORTH_LINEALITY_SPACE",kernel(linealitySpace),n); |
---|
546 | |
---|
547 | /* |
---|
548 | if(flags & FPF_primitiveRays) |
---|
549 | { |
---|
550 | ZMatrix primitiveRays; |
---|
551 | for(int i=0;i<rays.getHeight();i++) |
---|
552 | for(PolyhedralConeList::const_iterator j=cones.begin();j!=cones.end();j++) |
---|
553 | if(j->contains(*i)&&(j->dimensionOfLinealitySpace()+1==j->dimension())) |
---|
554 | primitiveRays.push_back(j->semiGroupGeneratorOfRay()); |
---|
555 | |
---|
556 | polymakeFile.writeMatrixProperty("PRIMITIVE_RAYS",rowsToIntegerMatrix(primitiveRays,n)); |
---|
557 | } |
---|
558 | */ |
---|
559 | #if 0 |
---|
560 | ZMatrix generatorsOfLinealitySpace=cones.begin()->generatorsOfLinealitySpace(); |
---|
561 | |
---|
562 | log1 fprintf(Stderr,"Building symmetric complex.\n"); |
---|
563 | for(PolyhedralConeList::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
564 | { |
---|
565 | { |
---|
566 | static int t; |
---|
567 | // log1 fprintf(Stderr,"Adding faces of cone %i\n",t++); |
---|
568 | } |
---|
569 | // log2 fprintf(Stderr,"Dim: %i\n",i->dimension()); |
---|
570 | |
---|
571 | addFacesToSymmetricComplex(symCom,*i,i->getHalfSpaces(),generatorsOfLinealitySpace); |
---|
572 | } |
---|
573 | |
---|
574 | // log1 cerr<<"Remapping"; |
---|
575 | symCom.remap(); |
---|
576 | // log1 cerr<<"Done remapping"; |
---|
577 | |
---|
578 | |
---|
579 | PolyhedralFan f=*this; |
---|
580 | #endif |
---|
581 | |
---|
582 | // log1 fprintf(Stderr,"Computing f-vector.\n"); |
---|
583 | ZVector fvector=this->fvector(); |
---|
584 | polymakeFile.writeCardinalVectorProperty("F_VECTOR",fvector); |
---|
585 | // log1 fprintf(Stderr,"Done computing f-vector.\n"); |
---|
586 | |
---|
587 | if(flags&FPF_boundedInfo) |
---|
588 | { |
---|
589 | // log1 fprintf(Stderr,"Computing bounded f-vector.\n"); |
---|
590 | ZVector fvectorBounded=this->fvector(true); |
---|
591 | polymakeFile.writeCardinalVectorProperty("F_VECTOR_BOUNDED",fvectorBounded); |
---|
592 | // log1 fprintf(Stderr,"Done computing bounded f-vector.\n"); |
---|
593 | } |
---|
594 | #if 0 |
---|
595 | { |
---|
596 | Integer euler; |
---|
597 | int mul=-1; |
---|
598 | for(int i=0;i<fvector.size();i++,mul*=-1)euler+=Integer(mul)*fvector[i]; |
---|
599 | polymakeFile.writeCardinalProperty("MY_EULER",euler); |
---|
600 | } |
---|
601 | #endif |
---|
602 | // log1 fprintf(Stderr,"Checking if complex is simplicial and pure.\n"); |
---|
603 | polymakeFile.writeCardinalProperty("SIMPLICIAL",isSimplicial()); |
---|
604 | polymakeFile.writeCardinalProperty("PURE",isPure()); |
---|
605 | // log1 fprintf(Stderr,"Done checking.\n"); |
---|
606 | |
---|
607 | |
---|
608 | polymakeFile.writeStringProperty("CONES",toStringJustCones(getMinDim(),getMaxDim(),false,flags&FPF_group, 0,false,flags&FPF_tPlaneSort)); |
---|
609 | polymakeFile.writeStringProperty("MAXIMAL_CONES",toStringJustCones(getMinDim(),getMaxDim(),true,flags&FPF_group, 0,false,flags&FPF_tPlaneSort)); |
---|
610 | polymakeFile.writeStringProperty("CONES_ORBITS",toStringJustCones(getMinDim(),getMaxDim(),false,flags&FPF_group, 0,true,flags&FPF_tPlaneSort)); |
---|
611 | polymakeFile.writeStringProperty("MAXIMAL_CONES_ORBITS",toStringJustCones(getMinDim(),getMaxDim(),true,flags&FPF_group, 0,true,flags&FPF_tPlaneSort)); |
---|
612 | |
---|
613 | if(!sym.isTrivial()) |
---|
614 | { |
---|
615 | polymakeFile.writeMatrixProperty("SYMMETRY_GENERATORS",IntToZMatrix(sym.getGenerators())); |
---|
616 | } |
---|
617 | |
---|
618 | std::stringstream s; |
---|
619 | polymakeFile.writeStream(s); |
---|
620 | return s.str(); |
---|
621 | |
---|
622 | #if 0 |
---|
623 | |
---|
624 | if(flags&FPF_conesCompressed) |
---|
625 | { |
---|
626 | // log1 fprintf(Stderr,"Producing list of cones up to symmetry.\n"); |
---|
627 | polymakeFile.writeStringProperty("CONES_ORBITS",symCom.toString(symCom.getMinDim(),symCom.getMaxDim(),false,flags&FPF_group,0,true,flags&FPF_tPlaneSort)); |
---|
628 | // log1 fprintf(Stderr,"Done producing list of cones up to symmetry.\n"); |
---|
629 | // log1 fprintf(Stderr,"Producing list of maximal cones up to symmetry.\n"); |
---|
630 | stringstream multiplicities; |
---|
631 | polymakeFile.writeStringProperty("MAXIMAL_CONES_ORBITS",symCom.toString(symCom.getMinDim(),symCom.getMaxDim(),true,flags&FPF_group, &multiplicities,true,flags&FPF_tPlaneSort)); |
---|
632 | if(flags&FPF_multiplicities)polymakeFile.writeStringProperty("MULTIPLICITIES_ORBITS",multiplicities.str()); |
---|
633 | // log1 fprintf(Stderr,"Done producing list of maximal cones up to symmetry.\n"); |
---|
634 | } |
---|
635 | |
---|
636 | if(flags&FPF_conesExpanded) |
---|
637 | { |
---|
638 | if(flags&FPF_cones) |
---|
639 | { |
---|
640 | // log1 fprintf(Stderr,"Producing list of cones.\n"); |
---|
641 | polymakeFile.writeStringProperty("CONES",symCom.toString(symCom.getMinDim(),symCom.getMaxDim(),false,flags&FPF_group,0,false,flags&FPF_tPlaneSort)); |
---|
642 | // log1 fprintf(Stderr,"Done producing list of cones.\n"); |
---|
643 | } |
---|
644 | if(flags&FPF_maximalCones) |
---|
645 | { |
---|
646 | // log1 fprintf(Stderr,"Producing list of maximal cones.\n"); |
---|
647 | stringstream multiplicities; |
---|
648 | polymakeFile.writeStringProperty("MAXIMAL_CONES",symCom.toString(symCom.getMinDim(),symCom.getMaxDim(),true,flags&FPF_group, &multiplicities,false,flags&FPF_tPlaneSort)); |
---|
649 | if(flags&FPF_multiplicities)polymakeFile.writeStringProperty("MULTIPLICITIES",multiplicities.str()); |
---|
650 | // log1 fprintf(Stderr,"Done producing list of maximal cones.\n"); |
---|
651 | } |
---|
652 | } |
---|
653 | #endif |
---|
654 | #if 0 |
---|
655 | if(flags&FPF_values) |
---|
656 | { |
---|
657 | { |
---|
658 | ZMatrix values; |
---|
659 | for(int i=0;i<linealitySpaceGenerators.getHeight();i++) |
---|
660 | { |
---|
661 | ZVector v(1); |
---|
662 | v[0]=evaluatePiecewiseLinearFunction(linealitySpaceGenerators[i]); |
---|
663 | values.appendRow(v); |
---|
664 | } |
---|
665 | polymakeFile.writeMatrixProperty("LINEALITY_VALUES",rowsToIntegerMatrix(values,1)); |
---|
666 | } |
---|
667 | { |
---|
668 | ZMatrix values; |
---|
669 | for(IntegerVectorList::const_iterator i=rays.begin();i!=rays.end();i++) |
---|
670 | { |
---|
671 | ZVector v(1); |
---|
672 | v[0]=evaluatePiecewiseLinearFunction(*i); |
---|
673 | values.push_back(v); |
---|
674 | } |
---|
675 | polymakeFile.writeMatrixProperty("RAY_VALUES",rowsToIntegerMatrix(values,1)); |
---|
676 | } |
---|
677 | } |
---|
678 | #endif |
---|
679 | |
---|
680 | |
---|
681 | // log1 fprintf(Stderr,"Producing final string for output.\n"); |
---|
682 | /* stringstream s; |
---|
683 | polymakeFile.writeStream(s); |
---|
684 | string S=s.str(); |
---|
685 | // log1 fprintf(Stderr,"Printing string.\n"); |
---|
686 | p->printString(S.c_str()); |
---|
687 | */// log1 fprintf(Stderr,"Done printing string.\n"); |
---|
688 | } |
---|
689 | |
---|
690 | ZCone SymmetricComplex::makeZCone(IntVector const &indices)const |
---|
691 | { |
---|
692 | ZMatrix generators(indices.size(),getAmbientDimension()); |
---|
693 | for(unsigned i=0;i<indices.size();i++) |
---|
694 | generators[i]=vertices[indices[i]]; |
---|
695 | return ZCone::givenByRays(generators,linealitySpace); |
---|
696 | } |
---|
697 | } |
---|