public void evaluate() { //throw new NotImplementedException(); genCount++; generationLeaderBoard = new SortedDictionary <double, ICandidate>(); //List<Tuple<ICandidate, double>> canidateFitness = new List<Tuple<ICandidate, double>>(); //Profiler.start("Fitness"); //population.ForEach((x) => canidateFitness.Add(new Tuple<ICandidate, double>(x, x.getFitness()))); //Profiler.stop("Fitness"); //Profiler.start("Ordering"); //canidateFitness = canidateFitness.OrderByDescending((x) => x.Item2).ToList(); //generationLeaderBoard = population.Select((x) => new Tuple<ICandidate, double>(x, x.getFitness())).OrderByDescending((x)=>x.Item2).ToList(); //population.ForEach((p) => generationLeaderBoard.addSorted(new Tuple<ICandidate, double>(p, p.getFitness()))); ICandidate[] aPop = population.ToArray(); for (int i = 0; i < aPop.Length; i++) { ICandidate candidate = aPop[i]; generationLeaderBoard.Add(candidate.getFitness(), candidate); } //Profiler.stop("Ordering"); //generationLeaderBoard = canidateFitness; //Profiler.start("Console IO"); if (genLogEvery > 0 && genCount % genLogEvery == 0) { KeyValuePair <double, ICandidate> topCanidateFitness = generationLeaderBoard.Last(); Console.WriteLine("[Genus]: Generation {0} ({1} Canidates) with the top candidate {2} with a score of {3}", genCount, population.Count, topCanidateFitness.Value.getDescription(), topCanidateFitness.Key); } //Profiler.stop("Console IO"); //Profiler.start("File IO"); if (fileLogEvery > 0 && genCount % fileLogEvery == 0) { if (fileStream == null) { fileStream = new FileStream(logFile, FileMode.OpenOrCreate); } KeyValuePair <double, ICandidate> topCanidateFitness = generationLeaderBoard.Last(); byte[] textdata = System.Text.Encoding.ASCII.GetBytes(topCanidateFitness.Key + " " + topCanidateFitness.Value.getGenome() + "\n"); fileStream.Write(textdata, 0, textdata.Length); } //Profiler.stop("File IO"); }