need assistance in building binary genetic string using Genetic Algorithm IN C#?

Viewed 17

I am working on sample test scenario in Core C# base of genetic algorithm where i need to Find Binary Genetic String. i am confused in understanding implementation of Genetic algorithm

I have below fitness function

    private static Func<string, double> Fitness(string goal)
    {
        return new Func<string, double>(chromosome => {
            double total = 0;
          
            for (int i = 0; i < goal.Length; i++)
            {
                if (goal[i] != chromosome[i])
                {
                    total++;
                }
            }
          
            return 1.0 / (total + 1);
        });
    }

I need to complete a below function which Find Binary Genetic String which accepts above function parameter as input also other parameter is probMutation and probCrossover are provided floating point numbers that represent the chance of their respective modification occuring.

public static string FindBinaryGeneticString(Func<string, double> fitness, 
                                                 int length, double probCrossover, 
                                                 double probMutation)
    {
       //need to complete logic here
    }

Above function should return a binary string of '0' and '1' of chromosome Length that has a fitness score of 1 as computed by getFitness.

Can any one help me to iterate over this function logic ??

0 Answers
Related