UNPKG

@syntest/core

Version:

The common core of the SynTest Framework

100 lines 4.01 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. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RandomSearchFactory = exports.RandomSearch = void 0; const SearchAlgorithm_1 = require("./SearchAlgorithm"); const SimpleObjectiveManager_1 = require("../objective/managers/SimpleObjectiveManager"); /** * 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 eventManager The event manager * @param encodingSampler The encoding sampler * @param runner The encoding execution runner */ constructor(eventManager, objectiveManager, encodingSampler) { super(eventManager, objectiveManager); this._encodingSampler = encodingSampler; } /** * @inheritDoc * @protected */ _initialize( // eslint-disable-next-line @typescript-eslint/no-unused-vars budgetManager, // eslint-disable-next-line @typescript-eslint/no-unused-vars terminationManager // eslint-disable-next-line @typescript-eslint/no-empty-function ) { } /** * @inheritDoc * @protected */ _iterate(budgetManager, terminationManager) { return __awaiter(this, void 0, void 0, function* () { // Sample a new random encoding const randomEncoding = this._encodingSampler.sample(); // Evaluate the new encoding yield this._objectiveManager.evaluateOne(randomEncoding, budgetManager, terminationManager); }); } } exports.RandomSearch = RandomSearch; /** * Factory plugin for RandomSearch * * @author Dimitri Stallenberg */ class RandomSearchFactory { constructor() { this.name = "RandomSearch"; } // This function is not implemented since it is an internal plugin // eslint-disable-next-line @typescript-eslint/no-empty-function register() { } createSearchAlgorithm(options) { if (!options.eventManager) { throw new Error("RandomSearch requires eventManager option."); } if (!options.encodingSampler) { throw new Error("RandomSearch requires encodingSampler option."); } if (!options.runner) { throw new Error("RandomSearch requires runner option."); } return new RandomSearch(options.eventManager, new SimpleObjectiveManager_1.SimpleObjectiveManager(options.runner), options.encodingSampler); } } exports.RandomSearchFactory = RandomSearchFactory; //# sourceMappingURL=RandomSearch.js.map