abstract-genetic-solver
A simple asynchronous genetic solver that's agnostic about genome types, fitness functions, etc.
Installation
npm i abstract-genetic-solver
Usage
Here's a trivial solver that treats each genome as an array of 10 floats, and tries to maximize their sum.
var Solver = var solver = 10 // required methods that client must implementsolver Mathsolver MathsolvermeasureFitness = async genome // optional per-generation eventsolver { var best = solver console console} // start solvingsolverpaused = false
Note that measureFitness()
is async - this lets you calculate fitness values in a web worker, etc. The method can return a value synchronously of course, but it must be declared as async
.
Other settings
// number of individuals in each generationsolverpopulation = 100 // limit for simultaneous calls to measureFitness (0 => no limit)solvermaxSimultaneousCalls = 0 // chances of an individual mutating or crossing over each generationsolvermutationChance = 09solvercrossoverChance = 03 // new generations can retain N fittest individuals from the previoussolverkeepFittestCandidates = 3 // How strongly to prefer fitter candidates when evolving// 1 => choose from all candidates randomly// 2 => strong bias towards fitter candidatessolverrankSelectionBias = 15
Details
By Andy Hall, MIT license