Bad randomization in the genetic algorithm

Has anyone seen convincing results from a .Net Genetic Algorithm Scheme ?

I see poor randomization in the trial version of the problem salesman presented in the Genetic Algorithm. The following call generates the same gene shuffling order for the entire x 100 chromosome population:

chromosome.Genes.ShuffleFast(); 

If I take one step through the code, the gene order looks randomized, so I suspect there is a / Rdn () time error in ShuffleFast (), or I skip the setup step.

I tried to solve the problem by pre-pressing the sequences of the chromosome genes, and this caused minor changes in the results of the TSP. However, the console mileage magazine continues to show that GAF only detects 4 potential solutions for 400 generations of the population. This diverges from GA videos on YouTube that demonstrate the implementation of the genetic algorithm, offering a solution with great jitter. I cite this as yet another indication that GAF has a system internal problem with generating random numbers.

The genetic algorithm diagram is very well documented through the authors blog, so I try to keep an open mind as a reason.

Steps to play = Download GAF ​​from nuget, compile and debug the project by default with a breakpoint after creating chromosomes for the loop, inspect population.Solutions. Windows 7, VS2015, .Net 4.5 and 4.61. Debug or release.

+5
source share
2 answers

Considering the code in the 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 this. They are otherwise identical, performing the usual Fisher-Yates shuffle.

So, you need to create your own Random , and then pass it:

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

Thus, you have only one stream of random numbers, and this stream is seeded based on the current time whenever you run your program.

+2
source

Sorry for the late answer to the question. The question is really in GAF. The Shuffle method uses the System.Random number generator and creates a new one each time the method is called. This causes seeding problems. I fixed it (today) in GAF, and it will be in the next release. I suggest using the following code as a workaround.

 var rnd = GAF.Threading.RandomProvider.GetThreadRandom (); myList.ShuffleFast (rnd); 

Each random number generator created using the above code creates a random number generator with one seed per stream. This can then be passed to the Shuffle () method as described by Matthew.

+1
source

Source: https://habr.com/ru/post/1239492/


All Articles