Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ga.run() #9

Closed
langongjin opened this issue May 16, 2019 · 2 comments
Closed

ga.run() #9

langongjin opened this issue May 16, 2019 · 2 comments

Comments

@langongjin
Copy link

hi,

// running genetic algorithm
ga.run();

here ga.run() run the iterations inside until the termination. But I want to take the iteration out of ga.run(). That means ga.run() only feedback the populations, fitnesses, and best for a generation. For instance, I would like the code like

for (int generation = 0; generation < maxGenerations; generation++)
{
    ga.run(); //feedback the populations, fitnesses, and best for a generation
}

How can I do this?
Thanks!

@seaseestr
Copy link

It's inside the run function:
// starting population evolution
for (nogen = 1; nogen <= nbgen; ++nogen) {
// evolving population
pop.evolution();
// getting best current result
bestResult = pop(0)->getTotal();
// outputting results
if (output) print();
// checking convergence
if (tolerance != 0.0) {
if (fabs(bestResult - prevBestResult) < fabs(tolerance)) {
break;
}
prevBestResult = bestResult;
}
}

@langongjin
Copy link
Author

Thanks for the answer. I actually did it as you said months ago. Leave the idea to the next one who needs it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants