GA algorithm in jit.gen

Conall Ó Maoláin's icon

Hello,
I have been playing around with versions of a genetic algorithm from Daniel Schiffman's Nature of Code.
I first made a js version of this sketch: https://editor.p5js.org/natureofcode/sketches/q4F192JCV
and wanted to try something similar with jit.gen. The matrix values average out over time but they don't seem to move towards the target value. Is this to be expected when using this type of algorithm? The js version produces "incorrect" results too just because certain characters get selected and reproduce.
My first thought is that the "selection" gen subpatch is the problem since it uses a while loop and increments through the matrix but because it's in a gen patch the operation is being done per pixel.
Maybe there are similar implementations of this type of algorithm out there.

Thanks!

evolution.js
js 1.48 KB

Member.js
js 1.07 KB
Max Patch
Copy patch and select New From Clipboard in Max.