UNPKG

@syntest/search

Version:

The common core of the SynTest Framework

48 lines 2.21 kB
"use strict"; /* * Copyright 2020-2023 Delft University of Technology and SynTest contributors * * This file is part of SynTest Framework - SynTest Core. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DefaultProcreation = void 0; const prng_1 = require("@syntest/prng"); const TournamentSelection_1 = require("../selection/TournamentSelection"); const Procreation_1 = require("./Procreation"); class DefaultProcreation extends Procreation_1.Procreation { generateOffspringPopulation(populationSize, population) { const offspring = []; const rounds = Math.max(2, Math.round(populationSize / 5)); while (offspring.length < populationSize) { const parentA = (0, TournamentSelection_1.tournamentSelection)(population, rounds); const parentB = (0, TournamentSelection_1.tournamentSelection)(population, rounds); if (prng_1.prng.nextDouble(0, 1) <= this.crossover.crossoverEncodingProbability) { const children = this.crossover.crossOver([parentA, parentB]); for (const child of children) { offspring.push(this.mutateFunction(this.sampler, child)); } } else { offspring.push(this.mutateFunction(this.sampler, parentA), this.mutateFunction(this.sampler, parentB)); } } for (let index = 0; index < Math.ceil(populationSize * 0.2); index++) { offspring.push(this.sampler.sample()); } return offspring; } } exports.DefaultProcreation = DefaultProcreation; //# sourceMappingURL=DefaultProcreation.js.map