genetic.js
// a and b must be encoded already
a and b must be encoded already
a and b must be encoded already
cross(a, b) {
    let rand = Math.random()
    if(rand > this.crossoverRate) {
      return [a, b]
    }
    let minLength = Math.min(a.length, b.length)
    let pos = Math.floor(Math.random() * minLength)
    let aPre = a.slice(0, pos)
    let bPre = b.slice(0, pos)
    let aPost = a.slice(pos)
    let bPost = b.slice(pos)
    return [aPre + bPost, bPre + aPost]
  }
cross ( a , b ) { let rand = Math . random ( ) if ( rand > this . crossoverRate ) { return [ a , b ] } let minLength = Math . min ( a . length , b . length ) let pos = Math . floor ( Math . random ( ) * minLength ) let aPre = a . slice ( 0 , pos ) let bPre = b . slice ( 0 , pos ) let aPost = a . slice ( pos ) let bPost = b . slice ( pos ) return [ aPre + bPost , bPre + aPost ] }
a and b must be encoded already
a and b must be encoded already