public static Func<Tuple<IInd, IInd>> SelectTwoParents(IInd[] population, double[] fitnesses)
        {
            _population = population;
            _fitnesses = fitnesses;
            _tournamentSize = (int)Math.Round(_population.Length * 0.1);

            Func<Tuple<IInd, IInd>> res = TournamentSelection;
            return res;
        }
 public static double ComputeFitness(IInd inputInd)
 {
     //Convert StringInd.Value to a string of bits, for each 1 in the bits array add 1 to the fitness,
     //divide the fitness by the amount of bits
     Char[] bits = inputInd.ToCharArray();
     var fitness = bits.Where(x => x == '1').Sum(x => 1.0);
     fitness = fitness/bits.Length;            
     return fitness;
 }
        public static double ComputeFitness(IInd inputInd)
        {
            double[] squaredErrors = new double[_dataSet.Count];

            for (int i = 0; i < _dataSet.Count; i++)
            {
                double sP = 0;
                var line = _dataSet[i];
                for (int j = 0; j < line.Length-1; j++)
                {
                    var dataValue = line[j];
                    var indValue = inputInd.getDoubleArray()[j];
                    sP += (dataValue*indValue);
                }
                squaredErrors[i] = Math.Pow((line[line.Length - 1] - sP), 2);
            }

            return squaredErrors.Sum();
        }
 public static IInd Mutation(IInd inpStringInd, double rate)
 {
     Char[] inpBits = inpStringInd.ToCharArray();
     for (int i = 0; i < inpBits.Length; i++)
     {
         var r = Rand.NextDouble();
         if (r <= rate)
         {
             switch (inpBits[i])
             {
                 case '0':
                     inpBits[i] = '1';
                     break;
                 case '1':
                     inpBits[i] = '0';
                     break;
             }
         }
     }
     IInd res = new StringInd(new string(inpBits));
     return res;
 }
        public static IInd Mutation(IInd inpStringInd, double rate)
        {
            double[] values = inpStringInd.getDoubleArray();
            for (int i = 0; i < values.Length; i++)
            {
                var r = Rand.NextDouble();
                if (r <= rate)
                {
                    values[i] = Rand.NextDouble() * (maxVal - minVal) + minVal;
                }
            }
            IInd res = new DoubleInd(values);
            return res;

        }