Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poor randomization in the Genetic Algorithm Framework

Has anyone seen convincing results from the .Net Genetic Algorithm Framework?

I am seeing poor randomization in the Traveling Salesman Problem demo provided with the Genetic Algorithm Framework. The following call generates the same gene shuffle order across the x 100 seed chromosome population:

chromosome.Genes.ShuffleFast();

If I single step through the code the gene order looks randomized hence I suspect there is a time/Rdn() bug in ShuffleFast() or else I am overlooking a setup step.

I have tried to work around the problem by preshuffling the chromosome gene sequences and this produced a minor change in the TSP results. However the console log of the run still shows the GAF discovering only 4 potential solutions across 400 population generations. This is at odds with GA YouTube videos showing genetic algorithm implementations homing in on a suggested solution with a lot of jitter. I cite this as a further indication that the GAF has a systemic internal problem with random number generation.

The Genetic Algorithm Framework is very well documented via the authors Blog, so I am trying to keep an open mind as the reason.

Steps to reproduce = Download GAF from nuget, compile & debug the default project with a breakpoint after the create chromosomes for-loop, inspect population.Solutions. Windows 7, VS2015, .Net 4.5 & 4.61. Debug or Release.

like image 274
camelCase Avatar asked Dec 30 '15 12:12

camelCase


People also ask

What are the issues in genetic algorithm?

Genetic algorithms do not scale well with complexity. That is, where the number of elements which are exposed to mutation is large there is often an exponential increase in search space size. This makes it extremely difficult to use the technique on problems such as designing an engine, a house or a plane.

Is genetic algorithm random?

The genetic algorithm is a random-based classical evolutionary algorithm. By random here we mean that in order to find a solution using the GA, random changes applied to the current solutions to generate new ones. Note that GA may be called Simple GA (SGA) due to its simplicity compared to other EAs.

How can we solve optimization problem using genetic algorithm?

The genetic algorithm (GA) is a search heuristic that is routinely used to generate useful solutions to optimization and search problems. It generates solutions to optimization problems using techniques inspired by natural evolution, such as inheritance, mutation, selection, and crossover.

Is it advisable to apply GA's for all kinds optimization problems justify?

GAs are very general in nature, and just applying them to any optimization problem wouldn't give good results.


1 Answers

Looking at the code in a disassembler, there are two versions of ShuffleFast defined as extension methods: one takes a Random object as a parameter and the other creates a new one using the default constructor and uses that. They are otherwise identical, doing a standard Fisher–Yates shuffle.

So you need to construct your own Random and then pass it in:

Random r = new Random();
...
chromosome.Genes.ShuffleFast(r);
otherChromosome.Genes.ShuffleFast(r);
...

This way you've got only one stream of random numbers, and that stream is seeded based on the current time whenever you run your program.

like image 85
Matthew Strawbridge Avatar answered Sep 20 '22 05:09

Matthew Strawbridge