本文整理汇总了C++中Generation::addMolecule方法的典型用法代码示例。如果您正苦于以下问题:C++ Generation::addMolecule方法的具体用法?C++ Generation::addMolecule怎么用?C++ Generation::addMolecule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Generation
的用法示例。
在下文中一共展示了Generation::addMolecule方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[]) {
if (argc < 5) {
std::cout << argv[0] << " <numberOfGenerations> <sizeOfPopulation> <numberOfAtoms> <percentageMutation>" << std::endl;
return EXIT_FAILURE;
}
std::fstream out;
out.open("../results/ga-out", std::ios::out);
assert(out.is_open());
int maxDistance = 1000;
int numberOfGenerations = std::stoi(argv[1]);
int sizeOfPopulation = std::stoi(argv[2]);
int numberOfAtoms = std::stoi(argv[3]);
int percentage = std::stoi(argv[4]);
Randomize* randomize = new Randomize();
Evolution* evolution = new Evolution();
out << "genetico" << std::endl;
out << numberOfAtoms << std::endl;
// generate random generation
Generation* pGen = randomize->randomGeneration(maxDistance, sizeOfPopulation, numberOfAtoms);
Molecule** pMol = pGen->molecules();
// calculate potential
for (int i = 0; i < sizeOfPopulation; i++) {
Molecule* m = pMol[i];
m->setPotential(evolution->lennardJones(m));
}
// ordering molecules
QuickSort<Molecule>::sort(pMol, 0, sizeOfPopulation - 1);
Atom** pAtom = pMol[0]->atoms();
for (int i = 0; i < pMol[0]->numberOfAtoms(); i++) {
out << "Au" << "\t" << pAtom[i]->_x << "\t" << pAtom[i]->_y << "\t" << pAtom[i]->_z << std::endl;
}
// calculates next generations
Molecule* idv1 = NULL;
Molecule* idv2 = NULL;
Generation* nGen = NULL;
Molecule** nMol = NULL;
int generationID = 1;
while (numberOfGenerations > 0) {
// create new generation
nGen = new Generation(generationID);
for (int i = 0; i < sizeOfPopulation; i++) {
// select individuals
idv1 = pMol[randomize->randomInt(sizeOfPopulation)];
idv2 = pMol[randomize->randomInt(sizeOfPopulation)];
// create new individual
nGen->addMolecule(*evolution->reprodution(idv1, idv2, maxDistance, percentage));
}
delete pGen;
pGen = nGen;
pMol = pGen->molecules();
// calculate potential
for (int i = 0; i < sizeOfPopulation; i++) {
Molecule* m = pMol[i];
m->setPotential(evolution->lennardJones(m));
}
// ordering molecules
QuickSort<Molecule>::sort(pMol, 0, sizeOfPopulation - 1);
pAtom = pMol[0]->atoms();
for (int j = 0; j < pMol[0]->numberOfAtoms(); j++) {
out << "Au" << "\t" << pAtom[j]->_x << "\t" << pAtom[j]->_y << "\t" << pAtom[j]->_z << std::endl;
}
// increment
generationID++;
numberOfGenerations--;
}
out.close();
delete pGen;
// delete nGen;
delete randomize;
delete evolution;
return EXIT_SUCCESS;
}