@zfunction/genetics-js
Version:
Genetic and evolutionary algorithms framework for the web
32 lines • 1.46 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 });
var utils_1 = require("../../generator/utils");
var base_1 = require("../../individual/numeric/base");
var StochasticUniversalSamplingSe = /** @class */ (function () {
function StochasticUniversalSamplingSe() {
}
StochasticUniversalSamplingSe.prototype.select = function (population, params, cumulativeProbabilityCallback) {
var mattingPool = [];
var amount = 1.0 / params.selectionCount;
var prob = utils_1.Generator.generateFloating(new base_1.NumericRange(0.0, amount));
var index = 0;
while (mattingPool.length !== params.selectionCount) {
var individual = population.getPopulationItem(index).individual;
var cumulativeProbability = cumulativeProbabilityCallback(population.getPopulationItem(index), index);
while (prob <= cumulativeProbability) {
mattingPool.push(individual);
prob += amount;
}
index += 1;
}
return mattingPool;
};
return StochasticUniversalSamplingSe;
}());
exports.StochasticUniversalSamplingSe = StochasticUniversalSamplingSe;
//# sourceMappingURL=StochasticUniversalSamplingSe.js.map