giacomelli / GeneticSharp

GeneticSharp is a fast, extensible, multi-platform and multithreading C# Genetic Algorithm library that simplifies the development of applications using Genetic Algorithms (GAs).
MIT License
1.27k stars 332 forks source link

Change only one variable at a time freezing all others in GA #74

Closed debashis66 closed 3 years ago

debashis66 commented 4 years ago

I am trying to mimic large jumps (within the search space) and small jumps in the neighborhood changing only one parameter at a time (instead of allowing all variables to change at once). Is it possible to do this in GA using the available( mutation) operators where I can define different probability for the small and large changes or do I need to write my own implementation to achieve this ?

giacomelli commented 4 years ago

Yes, you will need to write your own implementation.

debashis66 commented 4 years ago

Thank you. Can you point me to an example I can use for custom operators and how we can pick up specific genes/ variables for mutation.

On Wed, Jun 3, 2020 at 4:31 PM Diego Giacomelli notifications@github.com wrote:

Yes, you will need to write your own implementation.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/giacomelli/GeneticSharp/issues/74#issuecomment-638122213, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANASQI2UC3P3STKRZSNBFY3RUYUPPANCNFSM4NROFCTA .

giacomelli commented 4 years ago

You can take a look at mutation operators developed on GeneticSharp itself.

ReverseSequenceMutation it's a really basic sample and TworsMutation is a good sample of how you can get specific genes.

debashis66 commented 4 years ago

Is there a better way to mutate only the genes for 1 parameter ?

    protected override void PerformMutate(IChromosome chromosome, float probability)
    {
        var fc = chromosome as FloatingPointChromosome;
        var values = fc.ToFloatingPoints(); 
        int index = RandomizationProvider.Current.GetInt(0, values .Length);

        if (RandomizationProvider.Current.GetDouble() <= probability)
        {
            var newValue = RandomizationProvider.Current.GetInt(minValue, maxValue);
            values[index] = (double)newValue;

            var newFc = new FloatingPointChromosome(minPositions, maxPositions, bits, decimals, values);

            for (int i = 0; i < chromosome.Length; i++)
                chromosome.ReplaceGene(i, newFc.GetGene(i));
        }

   }
giacomelli commented 3 years ago

Do you want to mutate a specific gene or only a random one?

giacomelli commented 3 years ago

Closing due to inactivity. Feel free to reopen in case you still need help.