Skip to content
Diego Giacomelli edited this page Jan 24, 2019 · 11 revisions

Performance tips

  • If you need to run a long term GA, use PerformanceGenerationStrategy.
population.GenerationStrategy = new PerformanceGenerationStrategy();
  • If your chromosomes have any external resource, like a bitmap or a file, remember to dispose of those resources.

Generation strategy

Population class has a property called GenerationStrategy, this property receives an implementation of IGenerationStrategy interface. The generation strategy is responsible for some key points of generation behavior inside a population and can affect the performance.

There two ways to keep track of generation on a population:

  • TrackingGenerationStrategy: an IGenerationStrategy's implementation that keeps all generations to further evaluation. This strategy can be slow and can suffer from OutOfMemoryException when you have a great population and a long-term termination.
  • PerformanceGenerationStrategy: an IGenerationStrategy's implementation which takes into account the performance and just keeps the last one generations in the population. This strategy is not good for tracking all the generations but is the best one when you have a very long-term termination.

If you need to further evaluation of all generations of the GA, use TrackingGenerationStrategy, otherwise use PerformanceGenerationStrategy. By default, PerformanceGenerationStrategy will keep only one generation in the Population.Generations list and release all old generation to the garbage collector.

LinearTaskExecutor vs ParallelTaskExecutor vs TplTaskExecutor

If you have a light fitness function, that runs very fast, let say about some microseconds or milliseconds, in this case, you should use LinearTaskExecutor as the GeneticAlgorithm.TaskExecutor because the cost of start threads using ParallelTaskExecutor or TplTaskExecutor will be greater than time to execute fitness evaluate in a linear fashion.

If you have a heavy fitness function that runs about seconds or minutes, in those cases you really should use ParallelTaskExecutor or TplTaskExecutor.

Benchmarks

We have a page showing the benchmarks that measure many aspects of GeneticSharp, comparing release versions: Benchmarks page.

Clone this wiki locally