@zfunction/genetics-js
Version:
Genetic and evolutionary algorithms framework for the web
29 lines • 1.27 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 RouletteWheel = /** @class */ (function () {
function RouletteWheel() {
}
RouletteWheel.prototype.select = function (population, params, cumulativeProbabilityCallback) {
var mattingPool = [];
while (mattingPool.length !== params.selectionCount) {
var prob = utils_1.Generator.generateProbability(params.engine);
var index = 0;
var cumulativeProbability = cumulativeProbabilityCallback(population.getPopulationItem(index), index);
while (cumulativeProbability < prob) {
index += 1;
cumulativeProbability = cumulativeProbabilityCallback(population.getPopulationItem(index), index);
}
mattingPool.push(population.getPopulationItem(index).individual);
}
return mattingPool;
};
return RouletteWheel;
}());
exports.RouletteWheel = RouletteWheel;
//# sourceMappingURL=RouletteWheel.js.map