UNPKG

@zfunction/genetics-js

Version:

Genetic and evolutionary algorithms framework for the web

63 lines 2.48 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 floating_1 = require("../../../individual/numeric/floating/"); var base_1 = require("../base/"); /** * ## Floating Individual reader * Implements a reader for floating individuals. * The format of this individuals is the following: * ``` * 3 -4 8 9 // OK (integer number are floating) * 3.45 845.5 // OK (fixed point notation) * 3e-2 4E-9 // OK (scientific notation allowed) * ``` */ var FloatingReader = /** @class */ (function (_super) { __extends(FloatingReader, _super); function FloatingReader() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.tokenDefinition = [ { token: /^[+-]?\d+(?:(?:\.\d+)?(?:[Ee][+-]?\d+)?)?$/, value: function (token) { return Number.parseFloat(token); }, }, { token: /^[+-]?\.\d+(?:[Ee][+-]?\d+)?$/, value: function (token) { return Number.parseFloat(token); }, }, ]; return _this; } /** * Reads a definition and converts * into an [[FloatingIndividual]]. * @param definition of the individual. * @return the read individual. * @throws Error if definition is not correct. */ FloatingReader.prototype.read = function (definition) { var genotype = this.getGenotype(this.tokenize(definition)); return new floating_1.FloatingIndividual(genotype); }; return FloatingReader; }(base_1.NumericReader)); exports.FloatingReader = FloatingReader; //# sourceMappingURL=FloatingReader.js.map