[74a91c9] | 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 | dimension(dimension_), |
---|
| 18 | multiplicity(multiplicity_), |
---|
| 19 | isKnownToBeNonMaximalFlag(false), |
---|
| 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(int 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(int 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(bestPermutation.size()==n); |
---|
| 65 | |
---|
| 66 | IntVector indicesNew(indices.size()); |
---|
| 67 | int I=0; |
---|
| 68 | for(int 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(int 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(int i=0;i<indices.size();i++) |
---|
| 92 | { |
---|
| 93 | while(1) |
---|
| 94 | { |
---|
| 95 | if(next>=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(int 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(int 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 | sym(sym_), |
---|
| 153 | dimension(-1), |
---|
| 154 | linealitySpace(canonicalizeSubspace(linealitySpace_)) |
---|
| 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 | |
---|
[26b713] | 202 | int SymmetricComplex::getLinDim()const |
---|
| 203 | { |
---|
| 204 | ZMatrix zm=linealitySpace; |
---|
| 205 | return zm.reduceAndComputeRank(); |
---|
| 206 | } |
---|
| 207 | |
---|
[74a91c9] | 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 | /* |
---|
| 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 | /* |
---|
| 231 | IntVector ret(cones.size()); |
---|
| 232 | |
---|
| 233 | int I=0; |
---|
| 234 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++,I++) |
---|
| 235 | { |
---|
| 236 | ZMatrix raysAtInfinity; |
---|
| 237 | for(int j=0;j<i->indices.size();j++) |
---|
| 238 | { |
---|
| 239 | if(vertices[i->indices[j]][0]==0)raysAtInfinity.push_back(vertices[i->indices[j]]); |
---|
| 240 | for(vector<int>::const_iterator k=j;k!=i->indices.end();k++) |
---|
| 241 | if(vertices[*j][0]*vertices[*k][0]<0) |
---|
| 242 | raysAtInfinity.push_back(((vertices[*j][0]>0)?1:-1)*(vertices[*j][0])*vertices[*k]+ |
---|
| 243 | ((vertices[*k][0]>0)?1:-1)*(vertices[*k][0])*vertices[*j]); |
---|
| 244 | } |
---|
| 245 | ret[I]=rankOfMatrix(raysAtInfinity); |
---|
| 246 | } |
---|
| 247 | return ret; |
---|
| 248 | } |
---|
| 249 | */ |
---|
| 250 | |
---|
| 251 | void SymmetricComplex::buildConeLists(bool onlyMaximal, bool compressed, std::vector<std::vector<IntVector > >*conelist/*, ZMatrix *multiplicities*/)const |
---|
| 252 | { |
---|
| 253 | int dimLow=this->linealitySpace.getHeight(); |
---|
| 254 | int dimHigh=this->getMaxDim(); |
---|
[c4d065] | 255 | if(dimHigh<dimLow)dimHigh=dimLow-1; |
---|
[74a91c9] | 256 | if(conelist)*conelist=std::vector<std::vector<IntVector> >(dimHigh-dimLow+1); |
---|
| 257 | for(int d=dimLow;d<=dimHigh;d++) |
---|
| 258 | { |
---|
| 259 | int numberOfOrbitsOutput=0; |
---|
| 260 | int numberOfOrbitsOfThisDimension=0; |
---|
| 261 | bool newDimension=true; |
---|
| 262 | { |
---|
| 263 | int I=0; |
---|
| 264 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++,I++) |
---|
| 265 | if(i->dimension==d) |
---|
| 266 | { |
---|
[26b713] | 267 | numberOfOrbitsOfThisDimension++; |
---|
[74a91c9] | 268 | if(!onlyMaximal || isMaximal(*i)) |
---|
| 269 | { |
---|
| 270 | numberOfOrbitsOutput++; |
---|
| 271 | bool isMax=isMaximal(*i); |
---|
| 272 | bool newOrbit=true; |
---|
| 273 | std::set<std::set<int> > temp; |
---|
| 274 | for(SymmetryGroup::ElementContainer::const_iterator k=sym.elements.begin();k!=sym.elements.end();k++) |
---|
| 275 | { |
---|
| 276 | Cone temp1=i->permuted(*k,*this,false); |
---|
| 277 | temp.insert(temp1.indexSet()); |
---|
| 278 | if(compressed)break; |
---|
| 279 | } |
---|
| 280 | for(std::set<std::set<int> >::const_iterator j=temp.begin();j!=temp.end();j++) |
---|
| 281 | { |
---|
| 282 | IntVector temp; |
---|
| 283 | for(std::set<int>::const_iterator k=j->begin();k!=j->end();k++)temp.push_back(*k); |
---|
| 284 | if(conelist)(*conelist)[d-dimLow].push_back(temp); |
---|
| 285 | /* if(isMax)if(multiplicities) |
---|
| 286 | { |
---|
| 287 | |
---|
| 288 | *multiplicities << i->multiplicity; |
---|
| 289 | if(group)if(newOrbit)*multiplicities << "\t# New orbit"; |
---|
| 290 | if(newDimension)*multiplicities << "\t# Dimension "<<d; |
---|
| 291 | *multiplicities << std::endl; |
---|
| 292 | }*/ |
---|
| 293 | newOrbit=false; |
---|
| 294 | newDimension=false; |
---|
| 295 | } |
---|
| 296 | } |
---|
| 297 | } |
---|
| 298 | } |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | std::string SymmetricComplex::toStringJustCones(int dimLow, int dimHigh, bool onlyMaximal, bool group, std::ostream *multiplicities, bool compressed, bool tPlaneSort)const |
---|
| 304 | { |
---|
| 305 | std::stringstream ret; |
---|
| 306 | |
---|
| 307 | ZVector additionalSortKeys(cones.size()); |
---|
| 308 | // if(tPlaneSort)additionalSortKeys=dimensionsAtInfinity(); |
---|
| 309 | // Integer lowKey=additionalSortKeys.min(); |
---|
| 310 | // Integer highKey=additionalSortKeys.max(); |
---|
| 311 | |
---|
| 312 | for(int d=dimLow;d<=dimHigh;d++) |
---|
| 313 | { |
---|
| 314 | int numberOfOrbitsOutput=0; |
---|
| 315 | int numberOfOrbitsOfThisDimension=0; |
---|
| 316 | bool newDimension=true; |
---|
| 317 | // for(int key=lowKey;key<=highKey;key++) |
---|
| 318 | { |
---|
| 319 | int I=0; |
---|
| 320 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++,I++) |
---|
| 321 | // if(additionalSortKeys[I]==key) |
---|
| 322 | if(i->dimension==d) |
---|
| 323 | { |
---|
| 324 | numberOfOrbitsOfThisDimension++; |
---|
| 325 | if(!onlyMaximal || isMaximal(*i)) |
---|
| 326 | { |
---|
| 327 | numberOfOrbitsOutput++; |
---|
| 328 | bool isMax=isMaximal(*i); |
---|
| 329 | bool newOrbit=true; |
---|
| 330 | std::set<std::set<int> > temp; |
---|
| 331 | for(SymmetryGroup::ElementContainer::const_iterator k=sym.elements.begin();k!=sym.elements.end();k++) |
---|
| 332 | { |
---|
| 333 | Cone temp1=i->permuted(*k,*this,false); |
---|
| 334 | temp.insert(temp1.indexSet()); |
---|
| 335 | if(compressed)break; |
---|
| 336 | } |
---|
| 337 | for(std::set<std::set<int> >::const_iterator j=temp.begin();j!=temp.end();j++) |
---|
| 338 | { |
---|
| 339 | ret << "{"; |
---|
| 340 | for(std::set<int>::const_iterator a=j->begin();a!=j->end();a++) |
---|
| 341 | { |
---|
| 342 | if(a!=j->begin())ret<<" "; |
---|
| 343 | ret << *a; |
---|
| 344 | } |
---|
| 345 | ret << "}"; |
---|
| 346 | if(group)if(newOrbit)ret << "\t# New orbit"; |
---|
| 347 | if(newDimension)ret << "\t# Dimension "<<d; |
---|
| 348 | ret <<std::endl; |
---|
| 349 | if(isMax)if(multiplicities) |
---|
| 350 | { |
---|
| 351 | *multiplicities << i->multiplicity; |
---|
| 352 | if(group)if(newOrbit)*multiplicities << "\t# New orbit"; |
---|
| 353 | if(newDimension)*multiplicities << "\t# Dimension "<<d; |
---|
| 354 | *multiplicities << std::endl; |
---|
| 355 | } |
---|
| 356 | newOrbit=false; |
---|
| 357 | newDimension=false; |
---|
| 358 | } |
---|
| 359 | } |
---|
| 360 | } |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | return ret.str(); |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | |
---|
[f80a530] | 368 | std::string SymmetricComplex::toStringJustRaysAndMaximalCones(int flags)const |
---|
| 369 | { |
---|
| 370 | PolymakeFile polymakeFile; |
---|
| 371 | polymakeFile.create("NONAME","PolyhedralFan","PolyhedralFan",flags&FPF_xml); |
---|
| 372 | polymakeFile.writeMatrixProperty("RAYS",vertices,true); |
---|
| 373 | polymakeFile.writeStringProperty("MAXIMAL_CONES",toStringJustCones(getMinDim(),getMaxDim(),true,flags&FPF_group, 0,false,flags&FPF_tPlaneSort)); |
---|
| 374 | |
---|
| 375 | std::stringstream s; |
---|
| 376 | polymakeFile.writeStream(s); |
---|
| 377 | return s.str(); |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | |
---|
[74a91c9] | 381 | ZVector SymmetricComplex::fvector(bool boundedPart)const |
---|
| 382 | { |
---|
| 383 | int min=getMinDim(); |
---|
[c4d065] | 384 | int dimHigh=getMaxDim(); |
---|
| 385 | if(dimHigh<min)dimHigh=min-1; |
---|
| 386 | ZVector ret(dimHigh-min+1); |
---|
[74a91c9] | 387 | |
---|
| 388 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
| 389 | { |
---|
| 390 | bool doAdd=!boundedPart; |
---|
| 391 | if(boundedPart) |
---|
| 392 | { |
---|
| 393 | bool isBounded=true; |
---|
| 394 | for(int j=0;j<i->indices.size();j++) |
---|
| 395 | if(vertices[i->indices[j]][0].sign()==0)isBounded=false; |
---|
| 396 | doAdd=isBounded; |
---|
| 397 | } |
---|
| 398 | if(doAdd) |
---|
| 399 | ret[i->dimension-min]+=Integer(sym.orbitSize(i->sortKey)); |
---|
| 400 | } |
---|
| 401 | return ret; |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | |
---|
| 405 | bool SymmetricComplex::isPure()const |
---|
| 406 | { |
---|
| 407 | int dim=-1; |
---|
| 408 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
| 409 | { |
---|
| 410 | if(isMaximal(*i)) |
---|
| 411 | { |
---|
| 412 | int dim2=i->dimension; |
---|
| 413 | if(dim==-1)dim=dim2; |
---|
| 414 | if(dim!=dim2)return false; |
---|
| 415 | } |
---|
| 416 | } |
---|
| 417 | return true; |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | |
---|
| 421 | bool SymmetricComplex::isSimplicial()const |
---|
| 422 | { |
---|
| 423 | int linealityDim=getMinDim(); |
---|
| 424 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
| 425 | if(!i->isSimplicial(linealityDim)) |
---|
| 426 | return false; |
---|
| 427 | return true; |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | |
---|
| 431 | void SymmetricComplex::remap() |
---|
| 432 | { |
---|
| 433 | for(ConeContainer::iterator i=cones.begin();i!=cones.end();i++) |
---|
| 434 | { |
---|
| 435 | Cone const&j=*i; |
---|
| 436 | Cone &j2=const_cast<Cone&>(j);//DANGER: cast away const. This does not change the sort key in the container, so should be OK. |
---|
| 437 | j2.remap(*this); |
---|
| 438 | } |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | |
---|
| 442 | int SymmetricComplex::numberOfConesOfDimension(int d)const |
---|
| 443 | { |
---|
| 444 | assert(sym.isTrivial()); |
---|
| 445 | |
---|
| 446 | int ret=0; |
---|
| 447 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
| 448 | if(d==i->dimension) |
---|
| 449 | { |
---|
| 450 | ret++; |
---|
| 451 | } |
---|
| 452 | return ret; |
---|
| 453 | } |
---|
| 454 | |
---|
| 455 | |
---|
| 456 | int SymmetricComplex::dimensionIndex(Cone const &c) |
---|
| 457 | { |
---|
| 458 | assert(sym.isTrivial()); |
---|
| 459 | |
---|
| 460 | int ret=0; |
---|
| 461 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
| 462 | if(c.dimension==i->dimension) |
---|
| 463 | { |
---|
| 464 | if(!(c<*i)&&!(*i<c)) |
---|
| 465 | return ret; |
---|
| 466 | else |
---|
| 467 | ret++; |
---|
| 468 | } |
---|
| 469 | return ret; |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | #if 0 |
---|
| 473 | void SymmetricComplex::boundary(Cone const &c, vector<int> &indices_, vector<int> &signs) |
---|
| 474 | { |
---|
| 475 | indices_=vector<int>(); |
---|
| 476 | signs=vector<int>(); |
---|
| 477 | int d=c.dimension; |
---|
| 478 | |
---|
| 479 | |
---|
| 480 | IntegerVectorList l; |
---|
| 481 | for(int i=0;i<c.indices.size();i++) |
---|
| 482 | l.push_back(vertices[c.indices[i]]); |
---|
| 483 | IntegerVectorList facetNormals=PolyhedralCone(l,IntegerVectorList(),n).extremeRays(); |
---|
| 484 | IntegerVectorList complementBasis=c.orthogonalComplement(*this); |
---|
| 485 | for(IntegerVectorList::const_iterator i=facetNormals.begin();i!=facetNormals.end();i++) |
---|
| 486 | { |
---|
| 487 | IntegerVectorList complementBasis1=complementBasis; |
---|
| 488 | complementBasis1.push_back(*i); |
---|
| 489 | FieldMatrix m=integerMatrixToFieldMatrix(rowsToIntegerMatrix(complementBasis1,n),Q); |
---|
| 490 | IntegerVectorList completion=fieldMatrixToIntegerMatrixPrimitive(m.reduceAndComputeKernel()).getRows(); |
---|
| 491 | for(IntegerVectorList::const_iterator j=completion.begin();j!=completion.end();j++)complementBasis1.push_back(*j); |
---|
| 492 | int sign=determinantSign(complementBasis1); |
---|
| 493 | |
---|
| 494 | set<int> indices; |
---|
| 495 | for(vector<int>::const_iterator j=c.indices.begin();j!=c.indices.end();j++)if(dotLong(vertices[*j],*i)==0)indices.insert(*j); |
---|
| 496 | Cone facet(indices,d-1,1,true,*this); |
---|
| 497 | IntegerVectorList complementBasis2=facet.orthogonalComplement(*this); |
---|
| 498 | for(IntegerVectorList::const_iterator j=completion.begin();j!=completion.end();j++)complementBasis2.push_back(*j); |
---|
| 499 | indices_.push_back(dimensionIndex(facet)); |
---|
| 500 | signs.push_back(sign*determinantSign(complementBasis2)); |
---|
| 501 | } |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | |
---|
| 505 | IntegerMatrix SymmetricComplex::boundaryMap(int d) |
---|
| 506 | { |
---|
| 507 | assert(sym.isTrivial()); |
---|
| 508 | |
---|
| 509 | IntegerMatrix ret(numberOfConesOfDimension(d-1),numberOfConesOfDimension(d)); |
---|
| 510 | |
---|
| 511 | for(ConeContainer::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
| 512 | if(d==i->dimension) |
---|
| 513 | { |
---|
| 514 | int I=dimensionIndex(*i); |
---|
| 515 | vector<int> indices; |
---|
| 516 | vector<int> signs; |
---|
| 517 | boundary(*i,indices,signs); |
---|
| 518 | for(int j=0;j<indices.size();j++) |
---|
| 519 | { |
---|
| 520 | ret[indices[j]][I]+=signs[j]; |
---|
| 521 | } |
---|
| 522 | } |
---|
| 523 | return ret; |
---|
| 524 | } |
---|
| 525 | #endif |
---|
| 526 | |
---|
| 527 | |
---|
| 528 | std::string SymmetricComplex::toString(int flags)const |
---|
| 529 | { |
---|
| 530 | PolymakeFile polymakeFile; |
---|
| 531 | polymakeFile.create("NONAME","PolyhedralFan","PolyhedralFan",flags&FPF_xml); |
---|
| 532 | |
---|
| 533 | |
---|
| 534 | |
---|
| 535 | |
---|
| 536 | |
---|
| 537 | polymakeFile.writeCardinalProperty("AMBIENT_DIM",n); |
---|
| 538 | polymakeFile.writeCardinalProperty("DIM",getMaxDim()); |
---|
| 539 | polymakeFile.writeCardinalProperty("LINEALITY_DIM",linealitySpace.getHeight()); |
---|
| 540 | // polymakeFile.writeMatrixProperty("RAYS",rays,true,comments); |
---|
[f80a530] | 541 | polymakeFile.writeMatrixProperty("RAYS",vertices,true); |
---|
[74a91c9] | 542 | polymakeFile.writeCardinalProperty("N_RAYS",vertices.getHeight()); |
---|
| 543 | |
---|
| 544 | |
---|
[c4d065] | 545 | polymakeFile.writeMatrixProperty("LINEALITY_SPACE",linealitySpace,n); |
---|
| 546 | polymakeFile.writeMatrixProperty("ORTH_LINEALITY_SPACE",kernel(linealitySpace),n); |
---|
[74a91c9] | 547 | |
---|
| 548 | /* |
---|
| 549 | if(flags & FPF_primitiveRays) |
---|
| 550 | { |
---|
| 551 | ZMatrix primitiveRays; |
---|
| 552 | for(int i=0;i<rays.getHeight();i++) |
---|
| 553 | for(PolyhedralConeList::const_iterator j=cones.begin();j!=cones.end();j++) |
---|
| 554 | if(j->contains(*i)&&(j->dimensionOfLinealitySpace()+1==j->dimension())) |
---|
| 555 | primitiveRays.push_back(j->semiGroupGeneratorOfRay()); |
---|
| 556 | |
---|
| 557 | polymakeFile.writeMatrixProperty("PRIMITIVE_RAYS",rowsToIntegerMatrix(primitiveRays,n)); |
---|
| 558 | } |
---|
| 559 | */ |
---|
| 560 | #if 0 |
---|
| 561 | ZMatrix generatorsOfLinealitySpace=cones.begin()->generatorsOfLinealitySpace(); |
---|
| 562 | |
---|
| 563 | log1 fprintf(Stderr,"Building symmetric complex.\n"); |
---|
| 564 | for(PolyhedralConeList::const_iterator i=cones.begin();i!=cones.end();i++) |
---|
| 565 | { |
---|
| 566 | { |
---|
| 567 | static int t; |
---|
| 568 | // log1 fprintf(Stderr,"Adding faces of cone %i\n",t++); |
---|
| 569 | } |
---|
| 570 | // log2 fprintf(Stderr,"Dim: %i\n",i->dimension()); |
---|
| 571 | |
---|
| 572 | addFacesToSymmetricComplex(symCom,*i,i->getHalfSpaces(),generatorsOfLinealitySpace); |
---|
| 573 | } |
---|
| 574 | |
---|
| 575 | // log1 cerr<<"Remapping"; |
---|
| 576 | symCom.remap(); |
---|
| 577 | // log1 cerr<<"Done remapping"; |
---|
| 578 | |
---|
| 579 | |
---|
| 580 | PolyhedralFan f=*this; |
---|
| 581 | #endif |
---|
| 582 | |
---|
| 583 | // log1 fprintf(Stderr,"Computing f-vector.\n"); |
---|
| 584 | ZVector fvector=this->fvector(); |
---|
| 585 | polymakeFile.writeCardinalVectorProperty("F_VECTOR",fvector); |
---|
| 586 | // log1 fprintf(Stderr,"Done computing f-vector.\n"); |
---|
| 587 | |
---|
| 588 | if(flags&FPF_boundedInfo) |
---|
| 589 | { |
---|
| 590 | // log1 fprintf(Stderr,"Computing bounded f-vector.\n"); |
---|
| 591 | ZVector fvectorBounded=this->fvector(true); |
---|
| 592 | polymakeFile.writeCardinalVectorProperty("F_VECTOR_BOUNDED",fvectorBounded); |
---|
| 593 | // log1 fprintf(Stderr,"Done computing bounded f-vector.\n"); |
---|
| 594 | } |
---|
| 595 | #if 0 |
---|
| 596 | { |
---|
| 597 | Integer euler; |
---|
| 598 | int mul=-1; |
---|
| 599 | for(int i=0;i<fvector.size();i++,mul*=-1)euler+=Integer(mul)*fvector[i]; |
---|
| 600 | polymakeFile.writeCardinalProperty("MY_EULER",euler); |
---|
| 601 | } |
---|
| 602 | #endif |
---|
| 603 | // log1 fprintf(Stderr,"Checking if complex is simplicial and pure.\n"); |
---|
| 604 | polymakeFile.writeCardinalProperty("SIMPLICIAL",isSimplicial()); |
---|
| 605 | polymakeFile.writeCardinalProperty("PURE",isPure()); |
---|
| 606 | // log1 fprintf(Stderr,"Done checking.\n"); |
---|
| 607 | |
---|
[c4d065] | 608 | |
---|
| 609 | polymakeFile.writeStringProperty("CONES",toStringJustCones(getMinDim(),getMaxDim(),false,flags&FPF_group, 0,false,flags&FPF_tPlaneSort)); |
---|
| 610 | polymakeFile.writeStringProperty("MAXIMAL_CONES",toStringJustCones(getMinDim(),getMaxDim(),true,flags&FPF_group, 0,false,flags&FPF_tPlaneSort)); |
---|
| 611 | polymakeFile.writeStringProperty("CONES_ORBITS",toStringJustCones(getMinDim(),getMaxDim(),false,flags&FPF_group, 0,true,flags&FPF_tPlaneSort)); |
---|
| 612 | polymakeFile.writeStringProperty("MAXIMAL_CONES_ORBITS",toStringJustCones(getMinDim(),getMaxDim(),true,flags&FPF_group, 0,true,flags&FPF_tPlaneSort)); |
---|
| 613 | |
---|
| 614 | if(!sym.isTrivial()) |
---|
| 615 | { |
---|
| 616 | polymakeFile.writeMatrixProperty("SYMMETRY_GENERATORS",IntToZMatrix(sym.getGenerators())); |
---|
| 617 | } |
---|
| 618 | |
---|
[74a91c9] | 619 | std::stringstream s; |
---|
| 620 | polymakeFile.writeStream(s); |
---|
| 621 | return s.str(); |
---|
| 622 | |
---|
| 623 | #if 0 |
---|
| 624 | |
---|
| 625 | if(flags&FPF_conesCompressed) |
---|
| 626 | { |
---|
| 627 | // log1 fprintf(Stderr,"Producing list of cones up to symmetry.\n"); |
---|
| 628 | polymakeFile.writeStringProperty("CONES_ORBITS",symCom.toString(symCom.getMinDim(),symCom.getMaxDim(),false,flags&FPF_group,0,true,flags&FPF_tPlaneSort)); |
---|
| 629 | // log1 fprintf(Stderr,"Done producing list of cones up to symmetry.\n"); |
---|
| 630 | // log1 fprintf(Stderr,"Producing list of maximal cones up to symmetry.\n"); |
---|
| 631 | stringstream multiplicities; |
---|
| 632 | polymakeFile.writeStringProperty("MAXIMAL_CONES_ORBITS",symCom.toString(symCom.getMinDim(),symCom.getMaxDim(),true,flags&FPF_group, &multiplicities,true,flags&FPF_tPlaneSort)); |
---|
| 633 | if(flags&FPF_multiplicities)polymakeFile.writeStringProperty("MULTIPLICITIES_ORBITS",multiplicities.str()); |
---|
| 634 | // log1 fprintf(Stderr,"Done producing list of maximal cones up to symmetry.\n"); |
---|
| 635 | } |
---|
| 636 | |
---|
| 637 | if(flags&FPF_conesExpanded) |
---|
| 638 | { |
---|
| 639 | if(flags&FPF_cones) |
---|
| 640 | { |
---|
| 641 | // log1 fprintf(Stderr,"Producing list of cones.\n"); |
---|
| 642 | polymakeFile.writeStringProperty("CONES",symCom.toString(symCom.getMinDim(),symCom.getMaxDim(),false,flags&FPF_group,0,false,flags&FPF_tPlaneSort)); |
---|
| 643 | // log1 fprintf(Stderr,"Done producing list of cones.\n"); |
---|
| 644 | } |
---|
| 645 | if(flags&FPF_maximalCones) |
---|
| 646 | { |
---|
| 647 | // log1 fprintf(Stderr,"Producing list of maximal cones.\n"); |
---|
| 648 | stringstream multiplicities; |
---|
| 649 | polymakeFile.writeStringProperty("MAXIMAL_CONES",symCom.toString(symCom.getMinDim(),symCom.getMaxDim(),true,flags&FPF_group, &multiplicities,false,flags&FPF_tPlaneSort)); |
---|
| 650 | if(flags&FPF_multiplicities)polymakeFile.writeStringProperty("MULTIPLICITIES",multiplicities.str()); |
---|
| 651 | // log1 fprintf(Stderr,"Done producing list of maximal cones.\n"); |
---|
| 652 | } |
---|
| 653 | } |
---|
| 654 | #endif |
---|
| 655 | #if 0 |
---|
| 656 | if(flags&FPF_values) |
---|
| 657 | { |
---|
| 658 | { |
---|
| 659 | ZMatrix values; |
---|
| 660 | for(int i=0;i<linealitySpaceGenerators.getHeight();i++) |
---|
| 661 | { |
---|
| 662 | ZVector v(1); |
---|
| 663 | v[0]=evaluatePiecewiseLinearFunction(linealitySpaceGenerators[i]); |
---|
| 664 | values.appendRow(v); |
---|
| 665 | } |
---|
| 666 | polymakeFile.writeMatrixProperty("LINEALITY_VALUES",rowsToIntegerMatrix(values,1)); |
---|
| 667 | } |
---|
| 668 | { |
---|
| 669 | ZMatrix values; |
---|
| 670 | for(IntegerVectorList::const_iterator i=rays.begin();i!=rays.end();i++) |
---|
| 671 | { |
---|
| 672 | ZVector v(1); |
---|
| 673 | v[0]=evaluatePiecewiseLinearFunction(*i); |
---|
| 674 | values.push_back(v); |
---|
| 675 | } |
---|
| 676 | polymakeFile.writeMatrixProperty("RAY_VALUES",rowsToIntegerMatrix(values,1)); |
---|
| 677 | } |
---|
| 678 | } |
---|
| 679 | #endif |
---|
| 680 | |
---|
| 681 | |
---|
| 682 | // log1 fprintf(Stderr,"Producing final string for output.\n"); |
---|
| 683 | /* stringstream s; |
---|
| 684 | polymakeFile.writeStream(s); |
---|
| 685 | string S=s.str(); |
---|
| 686 | // log1 fprintf(Stderr,"Printing string.\n"); |
---|
| 687 | p->printString(S.c_str()); |
---|
| 688 | */// log1 fprintf(Stderr,"Done printing string.\n"); |
---|
| 689 | } |
---|
| 690 | |
---|
| 691 | ZCone SymmetricComplex::makeZCone(IntVector const &indices)const |
---|
| 692 | { |
---|
| 693 | ZMatrix generators(indices.size(),getAmbientDimension()); |
---|
| 694 | for(int i=0;i<indices.size();i++) |
---|
| 695 | generators[i]=vertices[indices[i]]; |
---|
| 696 | return ZCone::givenByRays(generators,linealitySpace); |
---|
| 697 | } |
---|
| 698 | } |
---|