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