#ifndef BESTK_H #define BESTK_H #include "SuperBB.h" #include static float scoreSuperBB(const std::shared_ptr &sbb) { // return sbb->getRestraintsRatio(); // return sbb->weightedTransScore_; // Note: if you change this, you also needs to change in HierarchicalFold::tryToConnect which optimizes by // summing and comparing trans scores before trying to connect // return sbb->transScore_; return sbb->transScore_ * sbb->getRestraintsRatio(); } struct comp { bool operator()(const std::shared_ptr &lhs, const std::shared_ptr &rhs) const { return scoreSuperBB(lhs) < scoreSuperBB(rhs); } }; /** This class stores the best k permutations of a specific size implemented as inheriting from a multiset with shapred_ptr and the comp struct */ class BestK : public std::multiset, comp> { public: BestK(unsigned int k, bool toDel = true) : k_(k), curMinScore(-1) {} float score(const std::shared_ptr &sbb) const { return scoreSuperBB(sbb); } float minScore() const { return curMinScore; } float maxScore() const { if (size() == 0) return 0; return score(*rbegin()); } void setK(int k) { k_ = k; } bool push(std::shared_ptr in); bool push_cluster(std::shared_ptr in, double rmsd, std::vector> &identGroups); void cluster(BestK &clusteredBest, double rmsd, std::vector> &identGroups) const; virtual ~BestK() {} private: float internalMinScore() { if (size() < k_) return -1; return score(*begin()); } private: std::mutex _mu; unsigned int k_; float curMinScore; }; #endif /* BESTK_H */