Hey there! I’ve committed a new class on JenPop, and it’s called “Individual”. It was made to represent the rules of typical genetic algorithms:

I’ve read a bit more on the subject and figured that genetic algorithms, although being able to achieve good solutions with little computing, are only suitable for problems where brute-forcing isn’t feasible. For instance, they do a nice job on combinatorial problemsÂ such as the classic knapsack problem, where you have a list of items with value **v**Â and weight **w**, and you must figure what’s the maximum value you can carry in a knapsack of capacity **w****c**Â by combining different amounts of those items.

And that problem was chosen to serve as the first example. At this kind of problem, a naive approach can easily become unfeasible as the input list grows. With an evolutionary approachÂ **there’s a bigger probability** that it will result in a better solution, given the same time limits. And even if the solution isn’t better, it will be a decent solution. The more time you let it roll, bigger is the chance of getting a great result.

For the classic scenarioÂ with a knapsack with wc = 15, and a (v,w) item list of (4, 12), (2, 2), (2, 1), (1, 1), (10, 4), I was able to achieve the following results:

30 iterations:Â Best result was { 0, 0, 4, 0, 2 } (v 28, w 12)

100 iterations:Â Best result was { 0, 3, 0, 9, 0 } (v 15, w 15)

500 iterations:Â Best result was { 0, 7, 1, 0, 0 } (v 16, w 15)

1000 iterations:Â Best result was { 0, 3, 4, 4, 0 } (v 18, w 14)

3000 iterations:Â Best result was { 0, 1, 1, 5, 1 } (v 19, w 12)

5000 iterations:Â Best result was { 0, 0, 5, 2, 2 } (v 32, w 15)

You can see that while none of those runs delivered the optimal solution, which would beÂ { 0, 0, 3, 0, 3 } (v 36, w 15), they got close enough to provide good solutions. Also, it becomes clear that randomism takes a nice part in this, giving us the chance of achieving a great solution with only 30 iterations. These results also show that the more you let it run, bigger is the chance of getting better results.

Anyway, see you! ðŸ˜€