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.27k stars 332 forks source link

External loop control #53

Closed constructor-igor closed 5 years ago

constructor-igor commented 5 years ago

Hi,

We made feasibility of GeneticSharp and now we investigate how GeneticSharp can be integrated with our system and found a next issue: our system manages external loop and requires to get population to calculate Fitness and set calcualted Fitness values to algorithm. So, I cannot calculate fitness in CreateNewGeneration (as suggested in #45).

sample of pseudo code:

while (geneticAlgoritm.InProgress){
    population = geneticAlgoritm.GetPopulation();
    CalculateFitness(population) // [our code] calculate and set Fitness value to each chromosome
    geneticAlgoritm.SetFitness(population)
}

Looks, I need find loop inside GeneticSharp and, somehow, to re-implement for our control. Please, could you help me to understand what is the easiest way to implement the feature and I'll try to do it.

thank you, Igor.

giacomelli commented 5 years ago

Part of the loop is performed here: https://github.com/giacomelli/GeneticSharp/blob/master/src/GeneticSharp.Domain/GeneticAlgorithm.cs#L315

and here: https://github.com/giacomelli/GeneticSharp/blob/master/src/GeneticSharp.Domain/GeneticAlgorithm.cs#L356

However, I did not understand why you cannot use the solution from #45, because as you can see here every generation evolved calls the Population.CreateNewGeneration(newGenerationChromosomes).

Please, could you explain better why you cannot use CreateNewGeneration?

constructor-igor commented 5 years ago

thank you for information. I'll investigate it. Because design of our system, I cannot inject "fitness calculator" inside ExternalEvaluationPopulation. External loop should get population, calculate fitness outside of any "genetic classes" and inject calculate fitness inside genetic to generate new population.

while (geneticAlgoritm.InProgress){
    population = geneticAlgoritm.GetPopulation();  // get population
    CalculateFitness(population) // [our code] calculate and set Fitness value to each chromosome
    geneticAlgoritm.SetFitness(population) // set fitness
}
constructor-igor commented 5 years ago

I investigated code in your suggestion. Now, I better understand how can I change code for our integration. Thank you!

giacomelli commented 5 years ago

Nice! Let me know if you will need any advice in the future and whether your integration worked.

constructor-igor commented 5 years ago

Please, could you help me to understand next issue: I cannot compile class GeneticAlgorithm, because a error in line: https://github.com/giacomelli/GeneticSharp/blob/ac17144427e31f2a073cac87a79ae14a4912e013/src/GeneticSharp.Domain/GeneticAlgorithm.cs#L427

image