giacomelli / GeneticSharp

GeneticSharp is a fast, extensible, multi-platform and multithreading C# Genetic Algorithm library that simplifies the development of applications using Genetic Algorithms (GAs).
MIT License
1.26k stars 330 forks source link

Resume GA when instantiated using a population with GenerationsNumber > 0 #119

Closed elpht closed 5 months ago

elpht commented 5 months ago

I'm working on a GA that takes quite long to calculate the fitness of each chromosome due to the nature of the problem. Therefore, after generation ran I serialize the population (custom serializable population that I implemented) so that it's possible to resume later the algorithm even if the computer where it runs has to be switched off.

So far I managed to overcome all problems I found except one: when I instantiate a GA using a deserialized population and try to resume, the field m_stopwatch isn't initialized, thus causing an exception.

Well, I could also have my own GA implementation, copying the one provided by the library and fixing the initialization of the Stopwatch, but I thought it would be pretty straightforward to modify the existing implementation to allow resuming the GA instance without being previously started. Would you see it senseful?

giacomelli commented 5 months ago

It would be useful. You can just make a pull request with your fix, I'll review it (please check our contributing page before)

Or you can try to use a custom population with your deserialized genes like this one: https://github.com/giacomelli/GeneticSharp/issues/9#issuecomment-246120699

giacomelli commented 5 months ago

Closed by PR #120