cashlionjp / JeneticS

Genetic Algorithm Framework in JS
https://cashlionjp.github.io/JeneticS/
MIT License
8 stars 0 forks source link

Question about code sample in README #3

Closed vitkarpov closed 6 years ago

vitkarpov commented 6 years ago

Hi!

I'm looking at this piece of code:

Agent.prototype.live = function () {  // Example: Live function
    for (let i = 0; i < this.dna.length; i++) {
        if (this.dna[i] === evolve[i]) {
            this.score++;
        }
    }
};

What is evolve array here? Where is it from? 🤔

cashlionjp commented 6 years ago

In the case of the example, the evolve variable is just a string that holds the sentence we are trying to evolve - https://github.com/cashlionjp/JeneticS/blob/master/examples/toBeOrNotToBe/app.js#L37. If you apply this to another problem, you can choose to score the agent in any way that makes sense. I’ll be releasing a traveling salesman example soon where the dna is random points ( 2d ) and the score is determined by the length of the circuit. The shorter the circuit the higher the score!

cashlionjp commented 6 years ago

I've updated the readme to include the evolve declaration. Thanks for pointing that out!