UNPKG

@adrianperea/genie.js

Version:

A highly flexible, data-agnostic, and UI-independent Genetic Algorithm Library

49 lines (39 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Individual = void 0; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var Individual = /*#__PURE__*/function () { function Individual() { var dna = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; _classCallCheck(this, Individual); this.fitness = 0; this.dna = Array.isArray(dna) ? dna : [dna]; } _createClass(Individual, [{ key: "getDna", value: function getDna(index) { return this.dna[index].genes; } }, { key: "addChromosome", value: function addChromosome(chromosome) { this.dna.push(chromosome); } }, { key: "fromTheLikenessOf", value: function fromTheLikenessOf() { var likeness = new Individual(); this.dna.forEach(function (chromosome) { likeness.addChromosome(chromosome.createRandomCopy()); }); likeness.fitness = 0; return likeness; } }]); return Individual; }(); exports.Individual = Individual;