diff --git a/dist/genome.min.js b/dist/genome.min.js index 4aa5fb3..9395959 100644 --- a/dist/genome.min.js +++ b/dist/genome.min.js @@ -1 +1 @@ -!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o=e();for(var s in o)("object"==typeof exports?exports:t)[s]=o[s]}}(window,function(){return function(o){var s={};function n(t){if(s[t])return s[t].exports;var e=s[t]={i:t,l:!1,exports:{}};return o[t].call(e.exports,e,e.exports,n),e.l=!0,e.exports}return n.m=o,n.c=s,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(o,s,function(t){return e[t]}.bind(null,s));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=o(1),s=function(){function s(t){void 0===t&&(t=null),this.genes=[],this.constants=[],this.fitness=0,t&&this.initializeGenes(t)}return s.prototype.initializeGenes=function(t){var o=this;t.getProperties().map(function(t){var e=new n.Gene(t);o.genes.push(e)}),t.getConstants().map(function(t){var e=new n.Gene(t);o.constants.push(e)})},s.prototype.computeFitness=function(t){this.fitness=t(this.genes,this.constants)},s.fromDNA=function(t,e){var o=new s;return o.genes=[],o.constants=[],t.map(function(t){var e=s.copyGene(t);o.genes.push(e)}),e.map(function(t){var e=s.copyGene(t);o.constants.push(e)}),o},s.copyGene=function(t){return Object.assign(Object.create(Object.getPrototypeOf(t)),t)},s.prototype.mutate=function(){var t=Math.floor(Math.random()*this.genes.length);this.genes[t].mutate()},s.prototype.getFitness=function(){return this.fitness},s.prototype.getLength=function(){return this.genes.length},s.prototype.getGenes=function(){return this.genes},s.prototype.getConstants=function(){return this.constants},s}();e.Chromosome=s},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(t){this.factor=t,this.value=Math.random()}return t.prototype.get=function(){return this.value*this.factor},t.prototype.mutate=function(){this.value=Math.random()},t}();e.Gene=s},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var s,n,r=function(){function s(){}return s.dispatch=function(e,o){void 0===o&&(o={}),s.listeners.map(function(t){t.eventType===e&&t.callback(o)})},s.on=function(t,e){s.listeners.push({eventType:t,callback:e})},s.listeners=[],s}();e.GenomeEvent=r,(n=s||(s={})).GENOME_EVENT_GENERATION_BEGIN="GENOME_EVENT_GENERATION_BEGIN",n.GENOME_EVENT_POPULATION_CREATED="GENOME_EVENT_POPULATION_CREATED",n.GENOME_EVENT_GENERATION_END="GENOME_EVENT_GENERATION_END",n.GENOME_EVENT_GENERATION_FINISH="GENOME_EVENT_GENERATION_FINISH",e.GenomeEventType=s},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var s=o(4);e.Population=s.Population;var n=o(0);e.Chromosome=n.Chromosome;var r=o(1);e.Gene=r.Gene;var i=o(5);e.Blueprint=i.Blueprint;var u=o(2);e.GenomeEvent=u.GenomeEvent,e.GenomeEventType=u.GenomeEventType},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var h=o(0),s=o(2),n=function(){function t(t,e){this.index=0,this.size=t,this.blueprint=e,this.chromosomes=[],this.bestChromosome=new h.Chromosome,this.sumFitness=0,this.mutationRate=.01,this.stopAt=null,this.cutOff=.3,this.initializeChromosomes()}return t.prototype.initializeChromosomes=function(){for(var t=0;te.getFitness()?-1:1})},t.prototype.selectBestChromosomes=function(){var e=this,t=Math.floor(this.chromosomes.length*this.cutOff);this.chromosomes.splice(this.chromosomes.length-t),this.sumFitness=0,this.chromosomes.map(function(t){e.sumFitness+=t.getFitness()})},t.prototype.crossoverChromosomes=function(){for(var t=[],e=this.chromosomes.length;e=this.stopAt));e+=1);s.GenomeEvent.dispatch(s.GenomeEventType.GENOME_EVENT_GENERATION_FINISH,this.chromosomes)},t.prototype.getGenerationNumber=function(){return this.index},t.prototype.getBestChromosome=function(){return this.bestChromosome},t.prototype.process=function(){var e=this;s.GenomeEvent.dispatch(s.GenomeEventType.GENOME_EVENT_GENERATION_BEGIN,this.chromosomes),this.shuffleChromosomes(),this.chromosomes.map(function(t){t.computeFitness(e.fitnessCalculation)}),this.sortChromosomes(),this.selectBestChromosomes(),this.crossoverChromosomes(),this.mutateChromosomes(),this.keepBestChromosome(),s.GenomeEvent.dispatch(s.GenomeEventType.GENOME_EVENT_GENERATION_END,this.chromosomes)},t}();e.Population=n},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(){this.properties=[],this.constants=[]}return t.prototype.add=function(t,e){void 0===e&&(e=1);for(var o=0;oe.getFitness()?-1:1})},t.prototype.selectBestChromosomes=function(){var e=this,t=Math.floor(this.chromosomes.length*this.cutOff),o=this.chromosomes.slice(this.chromosomes.length-t),s=this.chromosomes.slice(0,this.chromosomes.length-t+1);o.map(function(t){t.kill()}),this.sumFitness=0,s.map(function(t){e.sumFitness+=t.getFitness()})},t.prototype.crossoverChromosomes=function(){for(var t=this.chromosomes.filter(function(t){return t.isKilled}),e=this.chromosomes.filter(function(t){return!t.isKilled}),o=0;o=this.stopAt));e+=1);n.GenomeEvent.dispatch(n.GenomeEventType.GENOME_EVENT_GENERATION_FINISH,this.chromosomes)},t.prototype.getGenerationNumber=function(){return this.index},t.prototype.getBestChromosome=function(){return this.bestChromosome},t.prototype.process=function(){var e=this;n.GenomeEvent.dispatch(n.GenomeEventType.GENOME_EVENT_GENERATION_BEGIN,this.chromosomes),this.shuffleChromosomes(),this.chromosomes.map(function(t){t.computeFitness(e.fitnessCalculation)}),this.sortChromosomes(),this.selectBestChromosomes(),this.crossoverChromosomes(),this.mutateChromosomes(),this.keepBestChromosome(),n.GenomeEvent.dispatch(n.GenomeEventType.GENOME_EVENT_GENERATION_END,this.chromosomes)},t}();e.Population=i},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(){this.properties=[],this.constants=[]}return t.prototype.add=function(t,e){void 0===e&&(e=1);for(var o=0;o