@zfunction/genetics-js
Version:
Genetic and evolutionary algorithms framework for the web
60 lines • 2.05 kB
JavaScript
;
/*
* @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 });
/**
* ## Basic individual reader
* This class provides the basic implementation
* of the methods of the [[IndividualReader]]
* interface.
* @typeparam I is the type of the generated individual.
* @typeparam T is the value of the genes of the individual.
*/
var BaseIndividualReader = /** @class */ (function () {
function BaseIndividualReader() {
}
/**
* This method converts a token
* into the value of the individual
* genes.
* @param token of the individual.
* @return the value of the individual.
* @throws Error if there is an unexpected token.
*/
BaseIndividualReader.prototype.convertToken = function (token) {
var convertedToken = null;
this.tokenDefinition.forEach(function (tokenDefinition) {
if (tokenDefinition.token.test(token)) {
convertedToken = tokenDefinition.value(token);
}
});
if (convertedToken !== null) {
return convertedToken;
}
else {
throw new Error("Definition error: unexpected token " + token);
}
};
/**
* given an array of tokens this
* method converts into an array
* of individual values.
* @param tokens
* @return the genotype or array of
* values
*/
BaseIndividualReader.prototype.getGenotype = function (tokens) {
var _this = this;
var individualValues = [];
tokens.forEach(function (token) {
individualValues.push(_this.convertToken(token));
});
return individualValues;
};
return BaseIndividualReader;
}());
exports.BaseIndividualReader = BaseIndividualReader;
//# sourceMappingURL=BaseIndividualReader.js.map