1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
/**************************************************************************
* *
* Regina - A Normal Surface Theory Calculator *
* Computational Engine *
* *
* Copyright (c) 1999-2008, Ben Burton *
* For further details contact Ben Burton (bab@debian.org). *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public *
* License along with this program; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
**************************************************************************/
/* end stub */
#include <algorithm>
#include <sstream>
#include "census/ncensus.h"
#include "census/ngluingpermsearcher.h"
#include "progress/nprogressmanager.h"
#include "progress/nprogresstypes.h"
#include "triangulation/ntriangulation.h"
#include "utilities/memutils.h"
namespace regina {
const int NCensus::PURGE_NON_MINIMAL = 1;
const int NCensus::PURGE_NON_PRIME = 2;
const int NCensus::PURGE_NON_MINIMAL_PRIME = 3;
/**< PURGE_NON_MINIMAL_PRIME = PURGE_NON_MINIMAL | PURGE_NON_PRIME */
const int NCensus::PURGE_P2_REDUCIBLE = 4;
unsigned long NCensus::formCensus(NPacket* parent, unsigned nTetrahedra,
NBoolSet finiteness, NBoolSet orientability, NBoolSet boundary,
int nBdryFaces, int whichPurge, AcceptTriangulation sieve,
void* sieveArgs, NProgressManager* manager) {
// If obviously nothing is going to happen but we won't realise
// it until we've actually generated the face pairings, change
// nTetrahedra to 0 so we'll realise it immediately once the new
// thread starts.
if (finiteness == NBoolSet::sNone || orientability == NBoolSet::sNone)
nTetrahedra = 0;
// Start the census!
NProgressMessage* progress;
if (manager) {
progress = new NProgressMessage("Starting census generation...");
manager->setProgress(progress);
} else
progress = 0;
NCensus* census = new NCensus(parent, finiteness, orientability,
whichPurge, sieve, sieveArgs, progress);
if (manager) {
NFacePairing::findAllPairings(nTetrahedra, boundary, nBdryFaces,
NCensus::foundFacePairing, census, true);
return 0;
} else {
NFacePairing::findAllPairings(nTetrahedra, boundary, nBdryFaces,
NCensus::foundFacePairing, census, false);
unsigned long ans = census->whichSoln - 1;
delete census;
return ans;
}
}
unsigned long NCensus::formPartialCensus(const NFacePairing* pairing,
NPacket* parent, NBoolSet finiteness, NBoolSet orientability,
int whichPurge, AcceptTriangulation sieve, void* sieveArgs) {
// Is it obvious that nothing will happen?
if (finiteness == NBoolSet::sNone || orientability == NBoolSet::sNone)
return 0;
// Make a list of automorphisms.
NFacePairingIsoList autos;
pairing->findAutomorphisms(autos);
// Select the individual gluing permutations.
NCensus census(parent, finiteness, orientability, whichPurge,
sieve, sieveArgs, 0);
NGluingPermSearcher::findAllPerms(pairing, &autos,
! census.orientability.hasFalse(), ! census.finiteness.hasFalse(),
census.whichPurge, NCensus::foundGluingPerms, &census);
// Clean up.
std::for_each(autos.begin(), autos.end(), FuncDelete<NIsomorphismDirect>());
return census.whichSoln - 1;
}
NCensus::NCensus(NPacket* newParent, const NBoolSet& newFiniteness,
const NBoolSet& newOrientability, int newWhichPurge,
AcceptTriangulation newSieve, void* newSieveArgs,
NProgressMessage* newProgress) : parent(newParent),
finiteness(newFiniteness), orientability(newOrientability),
whichPurge(newWhichPurge), sieve(newSieve), sieveArgs(newSieveArgs),
progress(newProgress), whichSoln(1) {
}
void NCensus::foundFacePairing(const NFacePairing* pairing,
const NFacePairingIsoList* autos, void* census) {
NCensus* realCensus = static_cast<NCensus*>(census);
if (pairing) {
// We've found another face pairing.
if (realCensus->progress)
realCensus->progress->setMessage(pairing->toString());
// Select the individual gluing permutations.
NGluingPermSearcher::findAllPerms(pairing, autos,
! realCensus->orientability.hasFalse(),
! realCensus->finiteness.hasFalse(),
realCensus->whichPurge, NCensus::foundGluingPerms, census);
} else {
// Census generation has finished.
if (realCensus->progress) {
realCensus->progress->setMessage("Finished.");
realCensus->progress->setFinished();
delete realCensus;
}
}
}
void NCensus::foundGluingPerms(const NGluingPermSearcher* perms, void* census) {
if (perms) {
// We've found another permutation set.
// Triangulate and see what we've got.
NTriangulation* tri = perms->triangulate();
NCensus* realCensus = static_cast<NCensus*>(census);
bool ok = true;
if (! tri->isValid())
ok = false;
else if ((! realCensus->finiteness.hasFalse()) && tri->isIdeal())
ok = false;
else if ((! realCensus->finiteness.hasTrue()) && (! tri->isIdeal()))
ok = false;
else if ((! realCensus->orientability.hasTrue()) && tri->isOrientable())
ok = false;
else if (realCensus->sieve &&
! realCensus->sieve(tri, realCensus->sieveArgs))
ok = false;
if (ok) {
// Put it in the census!
// Make sure it has a charming label.
std::ostringstream out;
out << "Item " << realCensus->whichSoln;
tri->setPacketLabel(realCensus->parent->makeUniqueLabel(
out.str()));
realCensus->parent->insertChildLast(tri);
realCensus->whichSoln++;
} else {
// Bad triangulation.
delete tri;
}
}
}
bool NCensus::mightBeMinimal(NTriangulation* tri, void*) {
if (! tri->hasBoundaryFaces()) {
// No boundary faces.
// Tests specific to closed finite orientable triangulations:
if (tri->isOrientable() && (! tri->isIdeal())) {
// Check for too many vertices.
if (tri->getNumberOfVertices() > 1 &&
tri->getNumberOfTetrahedra() > 2)
return false;
}
// Check for obvious simplifications.
if (tri->simplifyToLocalMinimum(false))
return false;
}
return true;
}
} // namespace regina
|