var GA = function(options) { this.id = options.id; this.pause = false; this.drawing = false; this.nodes = options.nodes; this.size = options.size; this.n = options.nodes.length; this.k = 5; this.sigma = options.sigma; this.init = options.init; this.crosstype = options.crosstype; this.crossrate = options.crossrate; this.muttype = options.muttype; this.mutrate = options.mutrate; this.genDelay = options.genDelay; this.showGraph = options.showGraph; this.showProgress = options.showProgress; this.showConvergence = options.showConvergence; this.best = 0; this.repeats = 0; this.edgeDistr = null; this.initEdgePcts(); }; GA.prototype.edgeCosts = function() { this.constant = 0; this.costMatrix = [] for(var i=0; i bestFitness) { bestFitness = this.pool[r].fitness; padre = r; } } return this.pool[padre]; }; GA.prototype.hasConverged = function() { var edges = []; for(var i=0; i 0.95; } GA.prototype.runGeneration = function(options) { if(this.drawing || (options.delay <= 0 && !options.waited)) { var that = this; var delay = this.drawing ? ('waited' in options && options.waited ? options.delay : that.n*options.delay) : this.genDelay; setTimeout(function() { options.waited = true; that.runGeneration(options); }, delay); } else { if(!this.pause) { options.waited = false; this.avgEdgePercentile(); this.crossover(); this.mutate(); this.pool.sort(function(a, b) { return b.fitness - a.fitness; }); var changed = this.pool[0].fitness > this.best; console.log(this.generation); this.best = Math.max(this.pool[0].fitness, this.best); console.log(this.best); this.generation++; if(changed) { this.top10 = 0; this.avg = 0; for(var i=0; i