BuildSapsAlgorithmTuner(
            AlgorithmTunerConfiguration tunerConfig,
            string trainingInstanceFolder,
            string testInstanceFolder,
            SapsRunnerConfiguration runnerConfig)
        {
            var tuner = new AlgorithmTuner <SapsRunner, InstanceSeedFile, RuntimeResult, TLearnerModel, TPredictorModel, TSamplingStrategy>(
                targetAlgorithmFactory: new SapsRunnerFactory(runnerConfig.PathToExecutable, tunerConfig.CpuTimeout),
                runEvaluator: new SortByRuntime(runnerConfig.FactorParK),
                trainingInstances: SapsUtils.CreateInstances(trainingInstanceFolder, runnerConfig.NumberOfSeeds, runnerConfig.RngSeed),
                parameterTree: SapsUtils.CreateParameterTree(),
                configuration: tunerConfig);

            if (!string.IsNullOrWhiteSpace(testInstanceFolder))
            {
                tuner.SetTestInstances(SapsUtils.CreateInstances(testInstanceFolder, runnerConfig.NumberOfSeeds, runnerConfig.RngSeed));
            }

            return(tuner);
        }
Exemple #2
0
        BuildSapsAlgorithmTuner(
            AlgorithmTunerConfiguration tunerConfig,
            string trainingInstanceFolder,
            string testInstanceFolder,
            SapsRunnerConfiguration runnerConfig)
        {
            IRunEvaluator <InstanceSeedFile, RuntimeResult> runEvaluator;

            if (runnerConfig.FactorParK == 0)
            {
                runEvaluator = new SortByUnpenalizedRuntime <InstanceSeedFile>(tunerConfig.CpuTimeout);
            }
            else
            {
                runEvaluator = new SortByPenalizedRuntime <InstanceSeedFile>(runnerConfig.FactorParK, tunerConfig.CpuTimeout);
            }

            var tuner = new AlgorithmTuner <SapsRunner, InstanceSeedFile, RuntimeResult, TLearnerModel, TPredictorModel, TSamplingStrategy>(
                targetAlgorithmFactory: new SapsRunnerFactory(runnerConfig.PathToExecutable, tunerConfig.CpuTimeout),
                runEvaluator: runEvaluator,
                trainingInstances: InstanceSeedFile.CreateInstanceSeedFilesFromDirectory(
                    trainingInstanceFolder,
                    SapsUtils.ListOfValidFileExtensions,
                    runnerConfig.NumberOfSeeds,
                    runnerConfig.RngSeed),
                parameterTree: SapsUtils.CreateParameterTree(),
                configuration: tunerConfig);

            if (!string.IsNullOrWhiteSpace(testInstanceFolder))
            {
                tuner.SetTestInstances(
                    InstanceSeedFile.CreateInstanceSeedFilesFromDirectory(
                        testInstanceFolder,
                        SapsUtils.ListOfValidFileExtensions,
                        runnerConfig.NumberOfSeeds,
                        runnerConfig.RngSeed));
            }

            return(tuner);
        }
        /// <summary>
        /// Runs the master.
        /// </summary>
        /// <param name="remainingArguments">Remaining arguments for the tuner.</param>
        /// <param name="runnerConfig">Configuration of the algorithm.</param>
        /// <returns>The best parameters.</returns>
        public static Dictionary <string, IAllele> Run(IEnumerable <string> remainingArguments, SapsRunnerConfiguration runnerConfig)
        {
            var bestParameters = Master <SapsRunner, InstanceSeedFile, RuntimeResult, TLearnerModel, TPredictorModel, TSamplingStrategy> .Run(
                args : remainingArguments.ToArray(),
                algorithmTunerBuilder : (tunerConfig, trainingInstanceFolder, testInstanceFolder) =>
                GenericSapsEntryPoint <TLearnerModel, TPredictorModel, TSamplingStrategy> .BuildSapsAlgorithmTuner(
                    tunerConfig,
                    trainingInstanceFolder,
                    testInstanceFolder,
                    runnerConfig));

            return(bestParameters);
        }
        /// <summary>
        /// Logs the best parameters.
        /// </summary>
        /// <param name="bestParameters">The parameters.</param>
        /// <param name="sapsConfig">The config.</param>
        private static void LogBestParameters(Dictionary <string, IAllele> bestParameters, SapsRunnerConfiguration sapsConfig)
        {
            var bestParametersConsoleFormat = string.Join(" ", bestParameters.Select(parameter => $"-{parameter.Key} {parameter.Value}"));
            var ubcsatCommand =
                $"{sapsConfig.PathToExecutable} -alg saps -i [INSTANCE] -timeout [TIMEOUT] -seed [SEED] -cutoff max {bestParametersConsoleFormat}";

            LoggingHelper.WriteLine(VerbosityLevel.Info, "Command to start ubcsat with best parameters:");
            LoggingHelper.WriteLine(VerbosityLevel.Info, ubcsatCommand);
        }