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