ladies and gentlemen.
I am not a mathematician, so go easy on me. I'm a programmer.
I have a database that I got from the Internet (USDA National Nutrient Database for Standard Reference), detailing the amount of each nutrient in each of a few thousand foodstuffs. I wanted to write a program that would be able to create a maximally nutritious meal based on this data.
For each nutrient, I have a target and two penalties - one for going over and one for going under the target (since, for example, it's a lot worse to get too much saturated fat than not enough). The goal is to minimize the sum of the penalties.
The meal can select from all the thousands of foodstuffs, but can only contain five or six.
I wrote the program in Java, implemented a genetic algorithm, specified my requirements, and let it run. It produced recommendations that were pure poison, and didn't seem to improve with time.
Maybe I just don't get genetic algorithms? Let's see what I did...
1) Create a population of randomly generated meals.
2) Normalize each one so it has 2000 calories, by multiplying the amount of each foodstuff proportionally.
3) Select the best 10% of meals to be parents.
4) Create a new generation - a few random to avoid local minima, the rest created by combining the numbers and amounts from the parents.
5) GOTO 2.
What other algorithm can I try? Someone advised me to use simplex algorithm, but I can't seem to explain to it (the implementation in Apache Commons Math) what my fitness function is. But he claimed it would be a natural fit, and I have even heard of someone who used simplex for exactly this.