diff options
Diffstat (limited to 'geom_bottleneck/bottleneck/src')
-rw-r--r-- | geom_bottleneck/bottleneck/src/ann/ANN.cpp | 11 | ||||
-rw-r--r-- | geom_bottleneck/bottleneck/src/ann/bd_tree.cpp | 3 | ||||
-rw-r--r-- | geom_bottleneck/bottleneck/src/ann/kd_dump.cpp | 11 | ||||
-rw-r--r-- | geom_bottleneck/bottleneck/src/ann/kd_tree.cpp | 8 | ||||
-rw-r--r-- | geom_bottleneck/bottleneck/src/basic_defs.cpp | 13 | ||||
-rw-r--r-- | geom_bottleneck/bottleneck/src/bottleneck.cpp | 38 | ||||
-rw-r--r-- | geom_bottleneck/bottleneck/src/bound_match.cpp | 22 | ||||
-rw-r--r-- | geom_bottleneck/bottleneck/src/neighb_oracle.cpp | 2 |
8 files changed, 74 insertions, 34 deletions
diff --git a/geom_bottleneck/bottleneck/src/ann/ANN.cpp b/geom_bottleneck/bottleneck/src/ann/ANN.cpp index 7bae577..83c7ef6 100644 --- a/geom_bottleneck/bottleneck/src/ann/ANN.cpp +++ b/geom_bottleneck/bottleneck/src/ann/ANN.cpp @@ -30,9 +30,11 @@ #include <ciso646> // make VS more conformal #endif +#include <stdexcept> #include <cstdlib> // C standard lib defs #include <ANN/ANNx.h> // all ANN includes #include <ANN/ANNperf.h> // ANN performance +#include "def_debug_bt.h" @@ -80,10 +82,12 @@ void annPrintPt( // print a point int dim, // the dimension std::ostream &out) // output stream { +#ifndef FOR_R_TDA for (int j = 0; j < dim; j++) { out << pt[j]; if (j < dim-1) out << " "; } +#endif } //---------------------------------------------------------------------- @@ -197,11 +201,16 @@ bool ANNorthRect::intersects(const int dim, const ANNorthRect& r) const void annError(const char* msg, ANNerr level) { if (level == ANNabort) { +#ifndef FOR_R_TDA cerr << "ANN: ERROR------->" << msg << "<-------------ERROR\n"; - exit(1); +#endif + throw std::runtime_error(std::string("ANN: Error: ") + std::string(msg)); + //exit(1); } else { +#ifndef FOR_R_TDA cerr << "ANN: WARNING----->" << msg << "<-------------WARNING\n"; +#endif } } diff --git a/geom_bottleneck/bottleneck/src/ann/bd_tree.cpp b/geom_bottleneck/bottleneck/src/ann/bd_tree.cpp index 8c1ef6d..a5dd69c 100644 --- a/geom_bottleneck/bottleneck/src/ann/bd_tree.cpp +++ b/geom_bottleneck/bottleneck/src/ann/bd_tree.cpp @@ -31,6 +31,7 @@ #include "kd_split.h" // kd-tree splitting rules #include <ANN/ANNperf.h> // performance evaluation +#include "def_debug_bt.h" namespace geom_bt { //---------------------------------------------------------------------- @@ -43,6 +44,7 @@ void ANNbd_shrink::print( // print shrinking node int level, // depth of node in tree ostream &out) // output stream { +#ifndef FOR_R_TDA child[ANN_OUT]->print(level+1, out); // print out-child out << " "; @@ -61,6 +63,7 @@ void ANNbd_shrink::print( // print shrinking node out << "\n"; child[ANN_IN]->print(level+1, out); // print in-child +#endif } //---------------------------------------------------------------------- diff --git a/geom_bottleneck/bottleneck/src/ann/kd_dump.cpp b/geom_bottleneck/bottleneck/src/ann/kd_dump.cpp index 64db9a7..ecaf7ea 100644 --- a/geom_bottleneck/bottleneck/src/ann/kd_dump.cpp +++ b/geom_bottleneck/bottleneck/src/ann/kd_dump.cpp @@ -33,6 +33,7 @@ #include "kd_tree.h" // kd-tree declarations #include "bd_tree.h" // bd-tree declarations +#include "def_debug_bt.h" using namespace std; // make std:: available @@ -101,6 +102,7 @@ namespace geom_bt { // ... (repeated n_bnds times) //---------------------------------------------------------------------- +#ifndef FOR_R_TDA void ANNkd_tree::Dump( // dump entire tree ANNbool with_pts, // print points as well? ostream &out) // output stream @@ -132,20 +134,24 @@ namespace geom_bt { } out.precision(0); // restore default precision } +#endif void ANNkd_split::dump( // dump a splitting node ostream &out) // output stream { +#ifndef FOR_R_TDA out << "split " << cut_dim << " " << cut_val << " "; out << cd_bnds[ANN_LO] << " " << cd_bnds[ANN_HI] << "\n"; child[ANN_LO]->dump(out); // print low child child[ANN_HI]->dump(out); // print high child +#endif } void ANNkd_leaf::dump( // dump a leaf node ostream &out) // output stream { +#ifndef FOR_R_TDA if (this == KD_TRIVIAL) { // canonical trivial leaf node out << "leaf 0\n"; // leaf no points } @@ -156,17 +162,20 @@ namespace geom_bt { } out << "\n"; } +#endif } void ANNbd_shrink::dump( // dump a shrinking node ostream &out) // output stream { +#ifndef FOR_R_TDA out << "shrink " << n_bnds << "\n"; for (int j = 0; j < n_bnds; j++) { out << bnds[j].cd << " " << bnds[j].cv << " " << bnds[j].sd << "\n"; } child[ANN_IN]->dump(out); // print in-child child[ANN_OUT]->dump(out); // print out-child +#endif } //---------------------------------------------------------------------- @@ -441,7 +450,9 @@ namespace geom_bt { } else { annError("Illegal node type in dump file", ANNabort); +#ifndef FOR_R_TDA exit(0); // to keep the compiler happy +#endif } } } diff --git a/geom_bottleneck/bottleneck/src/ann/kd_tree.cpp b/geom_bottleneck/bottleneck/src/ann/kd_tree.cpp index ad3a82d..e8f7f63 100644 --- a/geom_bottleneck/bottleneck/src/ann/kd_tree.cpp +++ b/geom_bottleneck/bottleneck/src/ann/kd_tree.cpp @@ -38,6 +38,7 @@ #include "kd_split.h" // kd-tree splitting rules #include "kd_util.h" // kd-tree utilities #include <ANN/ANNperf.h> // performance evaluation +#include "def_debug_bt.h" namespace geom_bt { //---------------------------------------------------------------------- @@ -75,6 +76,7 @@ void ANNkd_split::print( // print splitting node int level, // depth of node in tree ostream &out) // output stream { +#ifndef FOR_R_TDA child[ANN_HI]->print(level+1, out); // print high child out << " "; for (int i = 0; i < level; i++) // print indentation @@ -85,13 +87,14 @@ void ANNkd_split::print( // print splitting node out << " np=" << actual_num_points; out << "\n"; child[ANN_LO]->print(level+1, out); // print low child +#endif } void ANNkd_leaf::print( // print leaf node int level, // depth of node in tree ostream &out) // output stream { - +#ifndef FOR_R_TDA out << " "; for (int i = 0; i < level; i++) // print indentation out << ".."; @@ -107,8 +110,10 @@ void ANNkd_leaf::print( // print leaf node } out << ">\n"; } +#endif } +#ifndef FOR_R_TDA void ANNkd_tree::Print( // print entire tree ANNbool with_pts, // print points as well? ostream &out) // output stream @@ -128,6 +133,7 @@ void ANNkd_tree::Print( // print entire tree root->print(0, out); // invoke printing at root } } +#endif //---------------------------------------------------------------------- // kd_tree statistics (for performance evaluation) diff --git a/geom_bottleneck/bottleneck/src/basic_defs.cpp b/geom_bottleneck/bottleneck/src/basic_defs.cpp index e09b119..76e6cc5 100644 --- a/geom_bottleneck/bottleneck/src/basic_defs.cpp +++ b/geom_bottleneck/bottleneck/src/basic_defs.cpp @@ -20,6 +20,7 @@ #include <algorithm> #include <cfloat> +#include "def_debug_bt.h" #include "basic_defs_bt.h" namespace geom_bt { @@ -36,6 +37,7 @@ bool Point::operator!=(const Point& other) const return !(*this == other); } +#ifndef FOR_R_TDA std::ostream& operator<<(std::ostream& output, const Point p) { output << "(" << p.x << ", " << p.y << ")"; @@ -51,6 +53,7 @@ std::ostream& operator<<(std::ostream& output, const PointSet& ps) output << "\b\b }"; return output; } +#endif double sqrDist(const Point& a, const Point& b) { @@ -90,6 +93,7 @@ bool DiagramPoint::operator!=(const DiagramPoint& other) const return !(*this == other); } +#ifndef FOR_R_TDA std::ostream& operator<<(std::ostream& output, const DiagramPoint p) { if ( p.type == DiagramPoint::DIAG ) { @@ -109,6 +113,7 @@ std::ostream& operator<<(std::ostream& output, const DiagramPointSet& ps) output << "\b\b }"; return output; } +#endif DiagramPoint::DiagramPoint(double xx, double yy, Type ttype, IdType uid) : x(xx), @@ -116,14 +121,8 @@ DiagramPoint::DiagramPoint(double xx, double yy, Type ttype, IdType uid) : type(ttype), id(uid) { - //if ( xx < 0 ) - //throw "Negative x coordinate"; - //if ( yy < 0) - //throw "Negative y coordinate"; - //if ( yy < xx ) - //throw "Point is below the diagonal"; if ( yy == xx and ttype != DiagramPoint::DIAG) - throw "Point on the main diagonal must have DIAG type"; + throw std::runtime_error("Point on the main diagonal must have DIAG type"); } diff --git a/geom_bottleneck/bottleneck/src/bottleneck.cpp b/geom_bottleneck/bottleneck/src/bottleneck.cpp index a5009c5..365995a 100644 --- a/geom_bottleneck/bottleneck/src/bottleneck.cpp +++ b/geom_bottleneck/bottleneck/src/bottleneck.cpp @@ -151,7 +151,7 @@ double bottleneckDistExact(DiagramPointSet& A, DiagramPointSet& B) const double approxDist = 0.5 * ( interval.first + interval.second); const double minDist = interval.first; const double maxDist = interval.second; - //std::cerr << std::setprecision(15) << "minDist = " << minDist << ", maxDist = " << maxDist << std::endl; + //std::cout << std::setprecision(15) << "minDist = " << minDist << ", maxDist = " << maxDist << std::endl; if ( delta == 0 ) { return interval.first; } @@ -163,17 +163,17 @@ double bottleneckDistExact(DiagramPointSet& A, DiagramPointSet& B) pointsA.push_back(ptA); } - //std::vector<double> killDist; - //for(auto ptA : A) { - //for(auto ptB : B) { - //if ( distLInf(ptA, ptB) > minDist and distLInf(ptA, ptB) < maxDist) { - //killDist.push_back(distLInf(ptA, ptB)); - //std::cout << ptA << ", " << ptB << std::endl; + //std::vector<double> killdist; + //for(auto pta : a) { + //for(auto ptb : b) { + //if ( distlinf(pta, ptb) > mindist and distlinf(pta, ptb) < maxdist) { + //killdist.push_back(distlinf(pta, ptb)); + //std::cout << pta << ", " << ptb << std::endl; //} //} //} - //std::sort(killDist.begin(), killDist.end()); - //for(auto d : killDist) { + //std::sort(killdist.begin(), killdist.end()); + //for(auto d : killdist) { //std::cout << d << std::endl; //} //std::cout << "*************" << std::endl; @@ -257,7 +257,7 @@ double bottleneckDistExact(DiagramPointSet& A, DiagramPointSet& B) std::sort(yCentersVec.begin(), yCentersVec.end(), compLambda); - // std::cout << "Sorted vector of y-centers:" << std::endl; + // std::cout << "Sorted vector of y-centers:" << std::endl; //for(auto coordPtPair : yCentersVec) { //std::cout << coordPtPair.first << ", id = " << coordPtPair.second.id << std::endl; //} @@ -271,13 +271,6 @@ double bottleneckDistExact(DiagramPointSet& A, DiagramPointSet& B) std::make_pair(ptB.getRealY() - delta, ptB), compLambda); - //if (ptB.id == 316) { - //std::cout << itStart - yCentersVec.begin() << " " << distLInf(itStart->second, ptB) << std::endl; - //std::cout << "maxDist = " << maxDist << std::endl; - //std::cout << "minDist = " << minDist << std::endl; - //double pwDistDebug = distLInf(itStart->second, ptB); - //std::cout << ( pwDistDebug >= minDist and pwDistDebug <= maxDist) << std::endl; - //} for(auto iterA = itStart; iterA < yCentersVec.end(); ++iterA) { if ( ptB.getRealY() < iterA->first - delta) { @@ -286,19 +279,16 @@ double bottleneckDistExact(DiagramPointSet& A, DiagramPointSet& B) double pwDist = distLInf(iterA->second, ptB); //std::cout << 1000*minDist << " <= " << 1000*pwDist << " <= " << 1000*maxDist << std::endl; if (pwDist >= minDist and pwDist <= maxDist) { - //if (ptB.id == 316) { - //std::cout << "adding " << pwDist << std::endl; - //} pairwiseDist.push_back(pwDist); } } } } - //std::cerr << "pairwiseDist.size = " << pairwiseDist.size() << " out of " << A.size() * A.size() << std::endl; + //std::cout << "pairwiseDist.size = " << pairwiseDist.size() << " out of " << A.size() * A.size() << std::endl; std::sort(pairwiseDist.begin(), pairwiseDist.end()); //for(auto ddd : pairwiseDist) { - //std::cerr << std::setprecision(15) << ddd << std::endl; + //std::cout << std::setprecision(15) << ddd << std::endl; //} return bottleneckDistExactFromSortedPwDist(A, B, pairwiseDist); @@ -516,7 +506,9 @@ bool readDiagramPointSet(const char* fname, std::vector<std::pair<double, double result.clear(); std::ifstream f(fname); if (!f.good()) { +#ifndef FOR_R_TDA std::cerr << "Cannot open file " << fname << std::endl; +#endif return false; } std::string line; @@ -541,7 +533,9 @@ bool readDiagramPointSet(const char* fname, std::vector<std::pair<double, double double x, y; std::istringstream iss(line); if (not(iss >> x >> y)) { +#ifndef FOR_R_TDA std::cerr << "Error in file " << fname << ", line number " << lineNumber << ": cannot parse \"" << line << "\"" << std::endl; +#endif return false; } result.push_back(std::make_pair(x,y)); diff --git a/geom_bottleneck/bottleneck/src/bound_match.cpp b/geom_bottleneck/bottleneck/src/bound_match.cpp index 06d3b67..a9ec93a 100644 --- a/geom_bottleneck/bottleneck/src/bound_match.cpp +++ b/geom_bottleneck/bottleneck/src/bound_match.cpp @@ -18,9 +18,12 @@ along with GeomBottleneck. If not, see <http://www.gnu.org/licenses/>. */ -#include <iostream> #include <assert.h> +#include "def_debug_bt.h" #include "bound_match.h" +#ifndef FOR_R_TDA +#include <iostream> +#endif namespace geom_bt { /*static void printDebug(//bool isDebug, std::string s)*/ @@ -82,6 +85,7 @@ namespace geom_bt { //#endif /*}*/ +#ifndef FOR_R_TDA std::ostream& operator<<(std::ostream& output, const Matching& m) { output << "Matching: " << m.AToB.size() << " pairs ("; @@ -94,6 +98,7 @@ std::ostream& operator<<(std::ostream& output, const Matching& m) } return output; } +#endif void Matching::sanityCheck() const { @@ -103,8 +108,11 @@ void Matching::sanityCheck() const auto bToAPair = BToA.find(aToBPair.second); assert(bToAPair != BToA.end()); if (aToBPair.first != bToAPair->second) { +#ifndef FOR_R_TDA std::cerr << "failed assertion, in aToB " << aToBPair.first; std::cerr << ", in bToA " << bToAPair->second << std::endl; +#endif + assert(false); } assert( aToBPair.first == bToAPair->second); } @@ -151,7 +159,9 @@ void Matching::checkAugPath(const Path& augPath) const for(size_t idx = 0; idx < augPath.size(); ++idx) { bool mustBeExposed { idx == 0 or idx == augPath.size() - 1 }; if (isExposed(augPath[idx]) != mustBeExposed) { +#ifndef FOR_R_TDA std::cerr << "mustBeExposed = " << mustBeExposed << ", idx = " << idx << ", point " << augPath[idx] << std::endl; +#endif } assert( isExposed(augPath[idx]) == mustBeExposed ); DiagramPoint matchedVertex {0.0, 0.0, DiagramPoint::DIAG, 1}; @@ -275,10 +285,12 @@ bool BoundMatchOracle::buildAugmentingPath(const DiagramPoint startVertex, Path& // layer DiagramPoint nextVertexA {0.0, 0.0, DiagramPoint::DIAG, 1}; if (!M.getMatchedVertex(nextVertexB, nextVertexA)) { +#ifndef FOR_R_TDA std::cerr << "Vertices in even layers must be matched! Unmatched: "; std::cerr << nextVertexB << std::endl; std::cerr << evenLayerIdx << "; " << layerGraph.size() << std::endl; - throw "Unmatched vertex in even layer"; +#endif + throw std::runtime_error("Unmatched vertex in even layer"); } else { assert( ! (nextVertexA.getRealX() == 0 and nextVertexA.getRealY() == 0) ); result.push_back(nextVertexA); @@ -383,8 +395,10 @@ bool BoundMatchOracle::buildMatchingForThreshold(const double r) } if (augmentingPaths.empty()) { //printDebug(isDebug,"augmenting paths must exist, but were not found!", M); +#ifndef FOR_R_TDA std::cerr << "augmenting paths must exist, but were not found!" << std::endl; - throw "bad epsilon?"; +#endif + throw std::runtime_error("bad epsilon?"); } // swap all augmenting paths with matching to increase it //printDebug(isDebug,"before increase with augmenting paths:", M); @@ -403,6 +417,7 @@ bool BoundMatchOracle::buildMatchingForThreshold(const double r) void BoundMatchOracle::printLayerGraph(void) { #ifdef DEBUG_BOUND_MATCH +#ifndef FOR_R_TDA for(auto& layer : layerGraph) { std::cout << "{ "; for(auto& p : layer) { @@ -411,6 +426,7 @@ void BoundMatchOracle::printLayerGraph(void) std::cout << "\b\b }" << std::endl; } #endif +#endif } void BoundMatchOracle::buildLayerGraph(double r) diff --git a/geom_bottleneck/bottleneck/src/neighb_oracle.cpp b/geom_bottleneck/bottleneck/src/neighb_oracle.cpp index 40d043f..5005bc4 100644 --- a/geom_bottleneck/bottleneck/src/neighb_oracle.cpp +++ b/geom_bottleneck/bottleneck/src/neighb_oracle.cpp @@ -184,8 +184,10 @@ void NeighbOracleAnn::deletePoint(const DiagramPoint& p) diagonalPoints.erase(p, false); kdTree->delete_point(pointIdx); #ifdef DEBUG_NEIGHBOUR_ORACLE +#ifndef FOR_R_TDA kdTree->Print(ANNtrue, std::cout); #endif +#endif } bool NeighbOracleAnn::getNeighbour(const DiagramPoint& q, DiagramPoint& result) const |