145 unsigned int pickSize,
147 int seed,
double &threshold)
const {
152 if (poolSize < pickSize) {
158 unsigned int memsize = (
unsigned int)(poolSize *
sizeof(
MaxMinPickInfo));
159 std::unique_ptr<MaxMinPickInfo[]> pinfo(
new MaxMinPickInfo[memsize]);
160 memset(pinfo.get(), 0, memsize);
162 picks.reserve(pickSize);
163 unsigned int picked = 0;
164 unsigned int pick = 0;
167 if (firstPicks.empty()) {
169 typedef boost::mt19937 rng_type;
170 typedef boost::uniform_int<> distrib_type;
171 typedef boost::variate_generator<rng_type &, distrib_type> source_type;
173 distrib_type dist(0, poolSize - 1);
175 generator.seed(
static_cast<rng_type::result_type
>(seed));
177 generator.seed(std::random_device()());
179 source_type randomSource(generator, dist);
180 pick = randomSource();
182 picks.push_back(
pick);
184 pinfo[
pick].picks = 1;
188 for (RDKit::INT_VECT::const_iterator pIdx = firstPicks.begin();
189 pIdx != firstPicks.end(); ++pIdx) {
190 pick =
static_cast<unsigned int>(*pIdx);
191 if (
pick >= poolSize) {
194 picks.push_back(
pick);
195 pinfo[
pick].picks = 1;
200 if (picked >= pickSize) {
205 unsigned int pool_list = 0;
206 unsigned int *prev = &pool_list;
208 for (
unsigned int i = 0; i < poolSize; i++) {
209 if (pinfo[i].picks == 0) {
211 prev = &pinfo[i].next;
216 unsigned int poolIdx;
217 unsigned int pickIdx;
224 pinfo[poolIdx].dist_bound = func(poolIdx, pickIdx);
225 pinfo[poolIdx].picks = 1;
226 prev = &pinfo[poolIdx].next;
227 }
while (*prev != 0);
230 double maxOFmin = -1.0;
231 double tmpThreshold = -1.0;
232 while (picked < pickSize) {
233 unsigned int *pick_prev =
nullptr;
238 double minTOi = pinfo[poolIdx].dist_bound;
239 if (minTOi > maxOFmin) {
240 unsigned int pi = pinfo[poolIdx].picks;
241 while (pi < picked) {
242 unsigned int picki = picks[pi];
244 double dist = func(poolIdx, picki);
246 if (dist <= minTOi) {
248 if (minTOi <= maxOFmin) {
253 pinfo[poolIdx].dist_bound = minTOi;
254 pinfo[poolIdx].picks = pi;
255 if (minTOi > maxOFmin) {
261 prev = &pinfo[poolIdx].next;
262 }
while (*prev != 0);
265 if (maxOFmin <= threshold && threshold >= 0.0) {
268 tmpThreshold = maxOFmin;
270 *pick_prev = pinfo[
pick].next;
271 picks.push_back(
pick);
275 threshold = tmpThreshold;
RDKit::INT_VECT pick(const double *distMat, unsigned int poolSize, unsigned int pickSize, RDKit::INT_VECT firstPicks, int seed=-1) const
Contains the implementation for the MaxMin diversity picker.