/// <summary> /// Fitness function calculating /// </summary> /// <param name="generation"></param> /// <param name="unsafeMode"></param> /// <returns></returns> private List <FitnessFunction> CalculateFitnessFunctionValues(List <List <double> > generation, bool unsafeMode) { // Creating real neural networks by weights lists: List <NeuralNetworkGeneticAlg> networksList = generation.Select(t => new NeuralNetworkGeneticAlg(t, NetworkStructure)).ToList(); // Calculating values: List <FitnessFunction> fitnessFuncValues = new List <FitnessFunction>(); Parallel.For(0, networksList.Count, i => { FitnessFunction fitnessFunction = new FitnessFunction { ChromosomeIndex = i }; fitnessFunction.CalculateValue(networksList[i], InputDatasets, OutputDatasets, unsafeMode); lock (_sync) { fitnessFuncValues.Add(fitnessFunction); } }); return(fitnessFuncValues); }