Created
September 9, 2018 00:43
-
-
Save kmaher9/853edaa221401c537f6acabab6ab01b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| this.evaluate = function() { | |
| var maxFitness = 0 | |
| for(var i = 0; i < this.populationSize; i++) { | |
| this.sticks[i].calculateFitness() // the distance from the target relative to current pos | |
| if (this.sticks[i].fitness > maxFitness) { | |
| maxFitness = this.sticks[i].fitness | |
| } | |
| } | |
| for(var i = 0; i < this.populationSize; i++) { | |
| this.sticks[i].fitness /= maxFitness // normalize the fitness value to be between 0 and 1 | |
| } | |
| this.pool = [] | |
| for(var i = 0; i < this.populationSize; i++) { | |
| var n = this.sticks[i].fitness * 100 // increase normalized value to between 0 and 100 | |
| for (var j = 0; j < n; j++) { | |
| this.pool.add(this.sticks[i]) // add the current gene to the pool relative to how fit it is | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment