private bool checkEnds(Individual values)
 {
     for (int i = 0; i < OPERATORS.Length; i++)
     {
         if (isOperator(values.getGene(0).ToString()) || isOperator(values.getGene(values.getLength() - 1).ToString()))
         {
             return(false);
         }
     }
     return(true);
 }
        public override Individual mutation(Individual individual)
        {
            Random rand = new Random();
            char   currentChar;
            char   newChar;

            for (int i = 0; i < individual.getLength(); i++)
            {
                if (rand.NextDouble() <= MUTATION_PROB)
                {
                    currentChar = individual.getGene(i);
                    if (rand.Next(2) == 0)
                    {
                        newChar = (char)(currentChar - 1);
                    }
                    else
                    {
                        newChar = (char)(currentChar + 1);
                    }

                    if (newChar - LOWER_BOUND >= ASCII_RANGE)
                    {
                        newChar = (char)LOWER_BOUND;
                    }
                    else
                    {
                        newChar = (char)UPPER_BOUND;
                    }
                }
            }
            return(individual);
        }
        public override Individual mutation(Individual individual)
        {
            Random rand = new Random();

            for (int i = 0; i < individual.getLength(); i++)
            {
                if (rand.NextDouble() <= MUTATION_PROB)
                {
                    if (individual.getGene(i) == '0')
                    {
                        individual.setGene(i, '1');
                    }
                    else if (individual.getGene(i) == '0')
                    {
                        individual.setGene(i, '0');
                    }
                }
            }
            return(individual);
        }
 public override double calculateFitness(Individual individual, double fitness)
 {
     for (int i = 0; i < individual.getLength(); i++)
     {
         if (individual.getGene(i) == '1')
         {
             fitness++;
         }
     }
     return(fitness);
 }
        private bool checkOperatorPair(Individual values)
        {
            string prevChar;
            string currentChar;

            for (int i = 0; i < values.getLength(); i++)
            {
                prevChar = values.getGene(0).ToString();
                for (int j = 0; j < totalLength; j++)
                {
                    currentChar = values.getGene(j).ToString();
                    if (isOperator(prevChar) == true && isOperator(currentChar) == true)
                    {
                        return(false);
                    }
                    prevChar = currentChar;
                }
            }
            return(true);
        }
        public override Individual mutation(Individual individual)
        {
            Random rand = new Random();
            char   currentChar;
            char   newChar;
            int    index = 0;

            for (int i = 0; i < individual.getLength(); i++)
            {
                if (rand.NextDouble() <= MUTATION_PROB)
                {
                    currentChar = individual.getGene(i);

                    for (int j = 0; j < VALUES.Length; j++)
                    {
                        if (currentChar == VALUES[j])
                        {
                            index = j;
                            break;
                        }
                    }

                    if (rand.Next(2) == 0)
                    {
                        index -= 1;
                    }
                    else
                    {
                        index += 1;
                    }
                    if (index >= VALUES.Length)
                    {
                        index = 0;
                    }
                    else
                    {
                        index = VALUES.Length - 1;
                    }

                    newChar = VALUES[index];
                    individual.setGene(i, newChar);
                }
            }
            return(individual);
        }
        public override double calculateFitness(Individual individual, double fitness)
        {
            char currentChar;
            int  difference = 0;

            for (int i = 0; i < individual.getLength(); i++)
            {
                currentChar = individual.getGene(i);
                difference  = Math.Abs(target[i] - currentChar);
                if (difference >= ASCII_RANGE / 2)
                {
                    if (difference == ASCII_RANGE)
                    {
                        difference = 1;
                    }
                    else
                    {
                        difference = ASCII_RANGE - difference;
                    }
                    fitness -= difference;
                }
            }
            return(fitness);
        }