UNPKG

@zfunction/genetics-js

Version:

Genetic and evolutionary algorithms framework for the web

58 lines 2.17 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. */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var integer_1 = require("../../../individual/numeric/integer/"); var base_1 = require("../base/"); /** * ## Integer Reader * Reads an [[IntegerIndividual]] from a definition. * The format of the definition is the following * ``` * 3 5 7 23 // OK * -4 -5 -8 // OK (Negative numbers allowed). * ``` */ var IntegerReader = /** @class */ (function (_super) { __extends(IntegerReader, _super); function IntegerReader() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.tokenDefinition = [ { token: /^[+-]?\d+$/, value: function (token) { return Number.parseInt(token, 10); }, }, ]; return _this; } /** * Reads a definition and converts * into an [[IntegerIndividual]]. * @param definition of the individual. * @return the read individual. * @throws Error if definition is not correct. */ IntegerReader.prototype.read = function (definition) { var genotype = this.getGenotype(this.tokenize(definition)); return new integer_1.IntegerIndividual(genotype); }; return IntegerReader; }(base_1.NumericReader)); exports.IntegerReader = IntegerReader; //# sourceMappingURL=IntegerReader.js.map