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