I’ve been working on my simple genetic algorithm in LabVIEW and struggling with memory. This was caused by a poor implementation of roulette wheel selection. I essentially created a very large array and randomly picked two parents from this array. The array contained multiple entries of each chromosome that was determined by it’s fitness score. This worked well enough for small populations and small fitness scores, but once things got big…

In this version, I implement a much improved roulette wheel selection algorithm. This is the algorithm documented on Marik Obitkos pages. The improvement was amazing. I found the new implementation gave me a 570x improvement with a population of 1500! And all my memory problems were gone. Developing the new implementation was a little frustrating. LabVIEW likes to make things simple and handle all the details for you such as variable type. This caused me a few headaches… The fitness score was implemented as a 16 bit signed integer. When I was calculating the sum of all fitness scores it was causing an overflow, but not raising any errors or warnings about this. The symptom I was seeing was that only one chromosome would make it through the selection process after a few runs. It wasn’t even the most fit one! After a lot of debugging, I saw this overflow. My next challenge was to convince LabVIEW to use an unsigned 32 bit integer to hold the data. I had to typecast the data going into the calculate sum vi in order to do this.
Here is version 3 with the new implementation of the selection algorithm.

Two weeks ago, I posted a simple genetic algorithm in LabVIEW. Since then, I’ve found a few bugs and yet more memory problems. In LabVIEW 8, the original ran fine. In LabVIEW 7.1, it would crash with large initial populations. I’ve managed to eliminate the memory problems by moving items to a subVI again. This is the updated version.
I also want to say thanks to IlliGAL Blogging for sending some traffic my way. They run an interesting blog covering the latest news in genetic algorithms.

I haven’t posted anything in a while…. I guess I’m just keeping myself busy. One of the things I’ve been working on is learning to use LabVIEW.

Genetic Algorithms caught my eye when I was younger and I decided that I would see what it would take to implement a simple genetic algorithm in LabVIEW. What I learned is that for simple things, LabVIEW is fast and easy. For bigger things, you have to understand the same issues as you do in C. The difference is that all these issues are side effects.

Memory was the biggest problem I had in this project. Once I got over the concept of data flow programming things went together really fast. Then I tried to run it with a large dataset of 2000 genes. After a few hours and a few hundred generations, LabVIEW blew up with a single error box telling me I was out of memory. Great. Where did it happen? But, like the wonderful Mac that LabVIEW grew up on, it wasn’t going to tell me where, it just apologized and died a quick death.

After a little searching, I learned that Build Array created copies and instead I should use Insert Into Array because it didn’t. This helped, but it still ran out of memory. Next I found that moving sections of my diagram to sub-VIs helped. Memory was only freed when a LabVIEW exits a VI. Nice to know.

I enjoy using LabVIEW. It is fast, it is easy. But like all programming languages, it’s only as good as the programmer.