9 #ifndef IMPMISC_METRIC_CLOSE_PAIRS_FINDER_H
10 #define IMPMISC_METRIC_CLOSE_PAIRS_FINDER_H
12 #include <IMP/misc/misc_config.h>
17 #include <boost/unordered_map.hpp>
21 IMPMISC_BEGIN_NAMESPACE
42 template <
class LowerBound,
class UpperBound>
50 typedef boost::unordered_map<ParticleIndex, Data> Index;
52 unsigned int index_size = std::min<unsigned int>(
53 1U, std::sqrt(static_cast<double>(inputs.size())));
54 #if IMP_COMPILER_HAS_RANDOM_SHUFFLE
55 std::random_shuffle(inputs.begin(), inputs.end());
61 inputs.begin() + index_size);
62 for (
unsigned int i = 0; i < index_size; ++i) {
66 for (
unsigned int i = 0; i < inputs.size(); ++i) {
67 double min_dist = std::numeric_limits<double>::max();
69 for (
unsigned int j = 0; j < indexes.size(); ++j) {
73 "The bounds are not ordered.");
76 if (cur_dist < min_dist) {
77 min_index = indexes[j];
81 ret[min_index].access_indexes().push_back(inputs[i]);
82 ret[min_index].set_width(std::min(min_dist, ret[min_index].get_width()));
84 for (
typename Index::const_iterator it = ret.begin(); it != ret.end();
93 for (
unsigned int i = 0; i < p.size(); ++i) {
94 for (
unsigned int j = 0; j < i; ++j) {
97 "The bounds are not ordered.");
109 for (
unsigned int i = 0; i < pa.size(); ++i) {
110 for (
unsigned int j = 0; j < pb.size(); ++j) {
113 "The bounds are not ordered.");
124 bool is_same)
const {
126 for (
typename Index::const_iterator ita = ia.begin(); ita != ia.end();
128 for (
typename Index::const_iterator itb = ib.begin(); itb != ib.end();
131 if (ita->first < itb->first)
continue;
132 if (ita->first == itb->first) {
133 ret += get_close_pairs_internal(m, ita->second.get_indexes());
140 "The bounds are not ordered.");
142 ita->second.get_width() - itb->second.get_width()) {
143 ret += get_close_pairs_internal(m, ita->second.get_indexes(),
144 itb->second.get_indexes());
153 std::string name =
"MetricClosePairsFinder%1%")
172 return get_close_pairs_internal(m, index, index,
true);
181 return get_close_pairs_internal(m, indexa, indexb,
false);
193 template <
class LowerBound,
class UpperBound>
199 IMPMISC_END_NAMESPACE
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
A base class for algorithms to find spatial proximities.
Functions and adaptors for dealing with particle indexes.
virtual IntPairs get_close_pairs(const algebra::BoundingBox3Ds &) const override
IMP::Vector< ParticleIndexPair > ParticleIndexPairs
#define IMP_FAILURE(message)
A runtime failure for IMP.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
#define IMP_LOG_VERBOSE(expr)
Class for storing model, its restraints, constraints, and particles.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
virtual IntPairs get_close_pairs(const algebra::BoundingBox3Ds &, const algebra::BoundingBox3Ds &) const override
virtual ParticleIndexPairs get_close_pairs(Model *m, const ParticleIndexes &pc) const override
return all close pairs among pc in model m
core::ClosePairsFinder * create_metric_close_pairs_finder(LowerBound lb, UpperBound ub)
virtual ParticleIndexPairs get_close_pairs(Model *m, const ParticleIndexes &pca, const ParticleIndexes &pcb) const override
return all close pairs among pc in model m
A nullptr-initialized pointer to an IMP Object.
A base class for algorithms to detect proximities.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Random number generators used by IMP.
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.
RandomNumberGenerator random_number_generator
A shared non-GPU random number generator.