UNPKG

@zfunction/genetics-js

Version:

Genetic and evolutionary algorithms framework for the web

58 lines 2.13 kB
"use strict"; /* * @license * Copyright (c) 2019 Cristian Abrante. All rights reserved. * Licensed under the MIT License. See LICENSE in the project root for license information. */ Object.defineProperty(exports, "__esModule", { value: true }); /** * ## BaseIndividualGenerator * This class provides with the basic features of a * individual generator. */ var BaseIndividualGenerator = /** @class */ (function () { function BaseIndividualGenerator() { } /** * Checks if a given individual length is in range. * @param length that is going to be evaluated. * @return `true` is length is greater than zero and `false` * otherwise. */ BaseIndividualGenerator.lengthIsInRange = function (length) { return length >= 0; }; /** * Throws an exception if length is not in range. * @param length that is going to be checked. * @throws RangeError if length is not in range. */ BaseIndividualGenerator.checkLength = function (length) { if (!this.lengthIsInRange(length)) { throw new RangeError("BaseIndividualGenerator: length " + length + " is not valid."); } }; /** * Generates the genotype given the params * of the generator. * @param params of the generator. */ BaseIndividualGenerator.prototype.generateGenotype = function (params) { var _this = this; return Array.from(new Array(params.length), function (_, index) { return _this.generateGene(params, index); }); }; /** * Generates an individual given some * params. * @param params for the generator. * @throws RangeError if length of the params * is not in range. */ BaseIndividualGenerator.prototype.generateWith = function (params) { BaseIndividualGenerator.checkLength(params.length); return this.construct(this.generateGenotype(params), params); }; return BaseIndividualGenerator; }()); exports.BaseGenerator = BaseIndividualGenerator; //# sourceMappingURL=BaseGenerator.js.map