which is pretty straightforward. We will try to find best values to maximize value of entire function - which, as you could easily see are a = 1, b = 1 and c = 1 with optimal function value equals to 3 (we assume that a, b and c belongs to interval [0,1)).

A possible set of (a,b,c) values we will call a 'solution'.

All solutions in genetic are treated as hash objects without function members.

Note: don't use field named score - it's reserved for internal use

All code for the example could be found in 'test/mytest.js' file as a part of the package. Feel free to use it as a template for your solutions.

To use genetic you need to provide several functions specific to your problem, and pass them as members of options object used as an argument to genetic.Task class constructor.

Function to mutate solution. Probability of mutation is defined by mutateProbability field of options object (see below).
Mutation is used to slightly alter one of your existing solution (mostly random) to provide diversity in you developing population.

Note: It will be better, if you create a new solution object instead of modifying original, passed as argument

Arguments

solution - existing solution to mutate

callback(mutatedSolution) - function to call with you new mutated solution as argument

Example

For our example it randomly changes one of our solution field to random one. It also could be not modified at all, but it's not an issue for our example. For real problems you better to ensure that some changes will be made actually.

This is a syncronous function which determines how long genetic algorithm will work. During the process it will act as a 'until' criteria - so algorithm stops, when this function returns true.

Note: this function will work in context of our Task (this = Task object), so you could refer to Task object fields to determine time to stop. You could inspect source code of '/lib/genetic/Task.js' to figure out possible data to determine your stopping condition on.

Example

In our example we will just iterate our algorithm for limited number of times. Do write it, we use Task field named generation that acts like a counter for number of current generation. So, to run for 100 generations we will write it as follows:

function stopCriteria() {
return (this.generation == 100)
}

Other options to stopping criterias is a time bounds, founding stable solutions, and other - you could look in the appropriate papers and books for ideas. I will try to implement some standard realizations you could use as part of the library to avoid writing this function each time manually.

Genetic implements sophisticated event model so you can control how your optimization process works. I will fill this chapter later. Meanwhile you could examine shipped sample - look in 'test/mytest.js' file.