// Based on an implementation from a correspondance with Bernd Rohde. void EvenSamplePairsStrategy::initializeStrategy(const ChemicalReaction &, const BBS &bbs) { size_t npos = bbs.size(); used_count.resize(npos); std::fill(used_count.begin(), used_count.end(), 0); var_used.resize(npos); for (size_t i = 0; i < npos; ++i) { var_used[i].resize(m_permutationSizes[i]); std::fill(var_used[i].begin(), var_used[i].end(), 0); } boost::uint64_t nmonomers = 0; for (size_t i = 0; i < bbs.size(); ++i) nmonomers += m_permutationSizes[i]; pair_used.resize(nmonomers); for (size_t i = 0; i < nmonomers; ++i) { pair_used[i].resize(nmonomers); std::fill(pair_used[i].begin(), pair_used[i].end(), 0); } pair_counts.resize(npos); for (size_t i = 0; i < npos; i++) { pair_counts[i].resize(npos); std::fill(pair_counts[i].begin(), pair_counts[i].end(), 0); } /* Initialize random number generator */ /* Find modulus */ for (M = 1; M < rdcast<size_t>(m_numPermutations); M = 2 * M) ; /* Set factor */ a = 5; b = 7; // control of random number and heuristics seed = 0; m_numPermutationsProcessed = 0; nslack = 0; // increase this to break evenness criteria rejected_period = 0; rejected_unique = 0; rejected_slack_condition = 0; rejected_bb_sampling_condition = 0; selected.clear(); // clear the selected (unique) set }
int main (void){ ofstream plik("wyniki.txt", ios_base::out); //InversiveGenerator (_MIN, _MAX, _SEED, _a, _b) //LinearGenerator (_MIN, _MAX, _SEED, _a, _b) //BBS (_p, _q, _MIN, _SEED) InversiveGenerator inwersyjny(0, 17, 0, 5, 1); LinearGenerator liniowy(0, 16, 0, 5, 1); BBS blum (11,11,0,5); cout << "\tICG\tLCG\tBBS" << endl; cout << "Min\t" << inwersyjny.getMin() << "\t" << liniowy.getMin() << "\t" << blum.getMin() << endl; cout << "Max\t" << inwersyjny.getMax() << "\t" << liniowy.getMax() << "\t" << blum.getMax() << endl; cout << "Seed\t" << inwersyjny.getSeed() << "\t" << liniowy.getSeed() << "\t" << blum.getSeed() << endl; cout << "I\t" << inwersyjny.getA() << "\t" << liniowy.getA() << "\t" << blum.getP() << endl; cout << "II\t" << inwersyjny.getB() << "\t" << liniowy.getB() << "\t" << blum.getQ() << endl; cout << endl << "Wylosowane liczby:" << endl; cout << "Generator liniowy:\t"; for (int i = 0; i < 10; i++) liniowy.print(); cout << endl; cout << "Generator inwersyjny:\t"; for (int i = 0; i < 10; i++) inwersyjny.print(); cout << endl; cout << "Generator Blum Blum Shub:\t"; for (int i = 0; i < 10; i++) blum.print(); cout << endl; cout << "Testy:" << endl; liniowy.setSeed(0); inwersyjny.setSeed(0); blum.setSeed(5); Test * array [] = { new statTest(&inwersyjny), new statTest(&liniowy), new statTest(&blum), new autoTest(&inwersyjny), new autoTest(&liniowy), new autoTest(&blum), new runsTest(&inwersyjny), new runsTest(&liniowy), new runsTest(&blum)}; for (int i = 0; i < 9; i++) { array[i]->runTest(); array[i]->displayResult(plik); } plik.close(); return 0; }
BBS removeNonmatchingReagents(const ChemicalReaction &rxn, BBS bbs, const EnumerationParams ¶ms) { PRECONDITION(bbs.size() <= rxn.getNumReactantTemplates(), "Number of Reagents not compatible with reaction templates"); BBS result; result.resize(bbs.size()); for (size_t reactant_idx = 0; reactant_idx < bbs.size(); ++reactant_idx) { size_t removedCount = 0; const unsigned int maxMatches = (params.reagentMaxMatchCount == INT_MAX) ? 0 : rdcast<unsigned int>(params.reagentMaxMatchCount); ROMOL_SPTR reactantTemplate = rxn.getReactants()[reactant_idx]; for (size_t reagent_idx = 0; reagent_idx < bbs[reactant_idx].size(); ++reagent_idx) { ROMOL_SPTR mol = bbs[reactant_idx][reagent_idx]; size_t matches = countMatches(*mol.get(), *reactantTemplate.get(), maxMatches); bool removeReagent = false; if (!matches || matches > rdcast<size_t>(params.reagentMaxMatchCount)) { removeReagent = true; } if (!removeReagent && params.sanePartialProducts) { // see if we have any sane products in the results std::vector<MOL_SPTR_VECT> partialProducts = rxn.runReactant(mol, reactant_idx); for (size_t productTemplate_idx = 0; productTemplate_idx < partialProducts.size(); ++productTemplate_idx) { int saneProducts = 0; for (size_t product_idx = 0; product_idx < partialProducts[productTemplate_idx].size(); ++product_idx) { try { RWMol *m = dynamic_cast<RWMol *>( partialProducts[productTemplate_idx][product_idx].get()); MolOps::sanitizeMol(*m); saneProducts++; } catch (...) { } } if (!saneProducts) { // if any product template has no sane products, we bail removeReagent = true; break; } } } if (removeReagent) removedCount++; else result[reactant_idx].push_back(mol); } if (removedCount) { BOOST_LOG(rdInfoLog) << "Removed " << removedCount << " non matching reagents at template " << reactant_idx << std::endl; } } return result; }