/// <summary> /// Main postcript function to store best results /// </summary> private void workerProgressChanged(object sender, ProgressChangedEventArgs e) { try { IChromosome bestChromosome = GA.Population.BestChromosome; //BASIC GADataSet ds = GARow.Table.DataSet as GADataSet; GADataSet.SolutionsRow currentSolution; currentSolution = ds.Solutions.NewSolutionsRow(); currentSolution.Initialize(bestChromosome.GetGenes()); currentSolution.ProblemID = PROBLEMID; //this is the most important function to override, does the fitness calc FillBasic(ref currentSolution); GeneticAlgorithm ga = GA; //fill GA data to row GARow.Update(ref ga); //report GA stuff //define filter function by genotype Func <GADataSet.SolutionsRow, bool> funcion; funcion = Aid.FilterByGenotype(ref hashListOfGenotypes, ref listOfSolutions); //execute filter function by genotype funcion(currentSolution); //the listOfSolutions contains the list of rows that need to be added //these rows are flagged ShouldDelete = false //REPONER ESTO if (!currentSolution.ShouldDelete) { ds.Solutions.AddSolutionsRow(currentSolution); GARow.FillGADataToSolution(ref currentSolution); } //callBack MEthod to Form or User Control CallBack.Invoke(); } catch (Exception ex) { throw ex; } }
/// <summary> /// Configure the Genetic Algorithm /// </summary> public virtual void RunConfiguration() { // Initialize(); //IMPORTANT // crossover = new CycleCrossover(); IChromosome adam = CreateChromosome(); IPopulation population = new Population(probabilities.minPop, probabilities.maxPop, adam); population.GenerationStrategy = new PerformanceGenerationStrategy(); //population.GenerationStrategy = new TrackingGenerationStrategy(); IFitness fitness = CreateFitness(); GeneticAlgorithm ga; ga = new GeneticAlgorithm(population, fitness, config.Selection, config.Crossover, config.Mutation); ga.Termination = config.Termination; if (config.Reinsertion != null) { ga.Reinsertion = config.Reinsertion; } // ga.Termination = new GenerationNumberTermination(probabilities.maxPop); ga.MutationProbability = probabilities.mutationProb; ga.CrossoverProbability = probabilities.crossProb; // ga.TaskExecutor = null; ga.TaskExecutor = new SmartThreadPoolTaskExecutor() { MinThreads = 10, MaxThreads = 70 }; GARow.Initialize(ref ga); //initialize GARow.ConfigTypes(ref config); // types ids GARow.ConfigTypesNames(ref ga); // types names, change with ids only GA = ga; }