public ISolution Start() { ISolution solution = problem.InitializeStart(); solution.ConsoleWrite(); int currentIteration = 0; while (!problem.CanStop()) { ISolution newSolution = problem.GetSolutionAtDistance(solution, this.epszilon); int fNew = problem.Fitness(newSolution); int fCurrent = problem.Fitness(solution); if (fNew < fCurrent) { solution = newSolution; Console.WriteLine(); Console.WriteLine(currentIteration); Console.WriteLine(solution.ToString()); solution.ConsoleWrite(); Console.WriteLine("Fitnesz: " + fNew); } currentIteration++; } Console.WriteLine("Done"); return(solution); }
public ISolution Start() { var population = this.problem.InitializeStart(this.numberOfInitParents); var evaulation = this.problem.Evaulate(population); ISolution best = this.BestSelect(evaulation); while (!this.problem.CanStop()) { IParentsAndMAtingPool parentsAndMatingPool = this.problem.SelectParents(population, this.numberOfSelectParents); bool noMore = false; while (parentsAndMatingPool.Parents.Count() < this.numberOfNewParents && !noMore) { IEnumerable <ISolution> selected = this.problem.Selection(parentsAndMatingPool.MatingPool, this.numberOfParentsK); if (selected.Count() > 0) { ISolution c = this.problem.CrossOver(selected); c = this.problem.Mutate(c); parentsAndMatingPool.Parents.Add(c); } else { noMore = true; } } population = parentsAndMatingPool.Parents; evaulation = this.problem.Evaulate(population); best = this.BestSelect(evaulation); //var ki = best; //Console.WriteLine(); ////Console.WriteLine(currentIteration); //Console.WriteLine(ki.ToString()); //ki.ConsoleWrite(); //Console.WriteLine("Fitnesz: " + this.problem.Fitness(ki)); } Console.WriteLine(); Console.WriteLine(best.ToString()); best.ConsoleWrite(); Console.WriteLine("Fitnesz: " + this.problem.Fitness(best)); return(best); }