UNPKG

@syntest/search

Version:

The common core of the SynTest Framework

59 lines 2.04 kB
"use strict"; /* * Copyright 2020-2021 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.RandomSearch = void 0; const logging_1 = require("@syntest/logging"); const SearchAlgorithm_1 = require("./SearchAlgorithm"); /** * Random Search algorithm that adds new encodings when these explore a new area of the search domain. * * @author Mitchell Olsthoorn */ class RandomSearch extends SearchAlgorithm_1.SearchAlgorithm { /** * Constructor. * * @param encodingSampler The encoding sampler */ constructor(objectiveManager, encodingSampler) { super(objectiveManager); RandomSearch.LOGGER = (0, logging_1.getLogger)("RandomSearch"); this._encodingSampler = encodingSampler; } /** * @inheritDoc * @protected */ _initialize() { RandomSearch.LOGGER.debug("Initializing"); } /** * @inheritDoc * @protected */ async _iterate(budgetManager, terminationManager) { // Sample a new random encoding const randomEncoding = this._encodingSampler.sample(); this._population = [randomEncoding]; // Evaluate the new encoding await this._objectiveManager.evaluateMany(this._population, budgetManager, terminationManager); } } exports.RandomSearch = RandomSearch; //# sourceMappingURL=RandomSearch.js.map