Пример #1
0
        /// <summary>
        /// Executes the worker.
        /// </summary>
        /// <param name="args">
        /// Arguments like the master's hostname.
        /// See <see cref="WorkerArgumentParser" /> for more information.
        /// </param>
        public static void Run(string[] args)
        {
            ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture);
            LoggingHelper.Configure($"consoleOutput_Worker_{ProcessUtils.GetCurrentProcessId()}.log");
            Randomizer.Configure();

            // Parse arguments.
            var argsParser = new WorkerArgumentParser();

            if (!ArgumentParserUtils.ParseArguments(argsParser, args))
            {
                return;
            }

            LoggingHelper.ChangeConsoleLoggingLevel(argsParser.VerbosityLevel);

            // Create an actor system for remote nodes to deploy onto.
            var akkaConfig = CustomizeAkkaConfiguration(
                argsParser.OwnHostName,
                argsParser.SeedHostName,
                argsParser.Port,
                argsParser.VerbosityLevel >= VerbosityLevel.Trace);
            var actorSystem = ActorSystem.Create(AkkaNames.ActorSystemName, akkaConfig);

            // Create an actor checking whether the cluster seed is still up.
            actorSystem.ActorOf(Props.Create(() => new SeedObserver()));

            // Do not stop execution before the actor system has been terminated.
            var cluster = Cluster.Get(actorSystem);

            actorSystem.WhenTerminated.Wait();
            cluster.Leave(cluster.SelfAddress);
        }
Пример #2
0
 protected void Application_Start()
 {
     GlobalConfiguration.Configure(WebApiConfig.Register);
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     LoggingHelper.Configure(typeof(MvcApplication));
     ConfigureUnhandledExceptionsHandler();
 }
Пример #3
0
        /// <summary>
        /// Entry point to the program.
        /// </summary>
        /// <param name="args">If 'master' is included as argument, a
        /// <see cref="Master{TTargetAlgorithm,TInstance,TResult}"/> is starting using the remaining arguments.
        /// Otherwise, a <see cref="Worker"/> is started with the provided arguments.</param>
        public static void Main(string[] args)
        {
            ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture);
            LoggingHelper.Configure($"parserLog_{ProcessUtils.GetCurrentProcessId()}.log");

            // Parse arguments.
            var argsParser = new SapsRunnerConfigurationParser();

            if (!ArgumentParserUtils.ParseArguments(argsParser, args))
            {
                return;
            }

            var config = argsParser.ConfigurationBuilder.Build();

            // Start master or worker depending on arguments.
            if (argsParser.IsMaster)
            {
                Dictionary <string, IAllele> bestParameters;
                switch (config.GenericParameterization)
                {
                case GenericParameterization.RandomForestAverageRank:
                    bestParameters = GenericSapsEntryPoint <
                        GenomePredictionRandomForest <AverageRankStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        AverageRankStrategy> .Run(argsParser.AdditionalArguments, config);

                    break;

                case GenericParameterization.RandomForestReuseOldTrees:
                    bestParameters = GenericSapsEntryPoint <
                        GenomePredictionRandomForest <ReuseOldTreesStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        ReuseOldTreesStrategy> .Run(argsParser.AdditionalArguments, config);

                    break;

                case GenericParameterization.StandardRandomForest:
                case GenericParameterization.Default:
                default:
                    bestParameters = GenericSapsEntryPoint <
                        StandardRandomForestLearner <ReuseOldTreesStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        ReuseOldTreesStrategy> .Run(argsParser.AdditionalArguments, config);

                    break;
                }

                Program.LogBestParameters(bestParameters, config);
            }
            else
            {
                Worker.Run(args);
            }
        }
Пример #4
0
        /// <summary>
        /// Runs the master.
        /// </summary>
        /// <param name="args">
        /// Arguments to configure the run, e.g. population size or port to use.
        /// </param>
        /// <param name="algorithmTunerBuilder">
        /// A function creating a <see cref="AlgorithmTuner{TTargetAlgorithm, TInstance, TResult, TLearnerModel, TPredictorModel, TSamplingStrategy}"/> instance.
        /// </param>
        /// <returns>
        /// The <see cref="Dictionary{String, IAllele}"/>, containing the best configuration.
        /// </returns>
        public static Dictionary <string, IAllele> Run(
            string[] args,
            Func <AlgorithmTunerConfiguration, string, string,
                  AlgorithmTuner <TTargetAlgorithm, TInstance, TResult, TLearnerModel, TPredictorModel, TSamplingStrategy> > algorithmTunerBuilder)
        {
            ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture);
            LoggingHelper.Configure($"consoleOutput_Master_{ProcessUtils.GetCurrentProcessId()}.log");
            Randomizer.Configure();

            var argsParser = new MasterArgumentParser();

            if (!ArgumentParserUtils.ParseArguments(argsParser, args))
            {
                return(null);
            }

            var configuration = CreateAlgorithmTunerConfiguration(argsParser);

            LoggingHelper.ChangeConsoleLoggingLevel(configuration.Verbosity);
            LoggingHelper.WriteLine(VerbosityLevel.Info, $"Configuration:{Environment.NewLine}{configuration}");

            // Create status file directories.
            Directory.CreateDirectory(configuration.StatusFileDirectory);
            if (configuration.ZipOldStatusFiles)
            {
                Directory.CreateDirectory(configuration.ZippedStatusFileDirectory);
            }

            using var runner = algorithmTunerBuilder.Invoke(
                      configuration,
                      argsParser.PathToTrainingInstanceFolder,
                      argsParser.PathToTestInstanceFolder);

            if (argsParser.StartFromExistingStatus)
            {
                runner.UseStatusDump(Path.Combine(configuration.StatusFileDirectory, AlgorithmTunerConfiguration.FileName));
            }

            if (configuration.EnableDataRecording)
            {
                runner.PrepareDataRecordDirectory(argsParser.StartFromExistingStatus);
            }

            // Run algorithm tuner.
            var bestParameters = runner.Run();

            LoggingHelper.WriteLine(
                VerbosityLevel.Info,
                $"Best Configuration:{Environment.NewLine}{string.Join(Environment.NewLine, bestParameters.Select(keyValuePair => $"{keyValuePair.Key}: {keyValuePair.Value}"))}");

            runner.CompleteAndExportGenerationHistory();

            return(bestParameters);
        }
Пример #5
0
        /// <summary>
        /// Entry point to the program.
        /// </summary>
        /// <param name="args">If 'master' is included as argument, a
        /// <see cref="Master{TTargetAlgorithm,TInstance,TResult}"/> is starting using the remaining arguments.
        /// Otherwise, a <see cref="Worker"/> is started with the provided arguments.</param>
        public static void Main(string[] args)
        {
            ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture);
            LoggingHelper.Configure($"parserLog_{ProcessUtils.GetCurrentProcessId()}.log");

            // Parse arguments.
            var argsParser = new BbobRunnerConfigurationParser();

            if (!ArgumentParserUtils.ParseArguments(argsParser, args))
            {
                return;
            }

            var bbobConfig = argsParser.ConfigurationBuilder.Build();

            if (argsParser.IsMaster)
            {
                switch (bbobConfig.GenericParameterization)
                {
                case GenericParameterization.RandomForestAverageRank:
                    GenericBbobEntryPoint <
                        GenomePredictionRandomForest <AverageRankStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        AverageRankStrategy> .Run(argsParser.AdditionalArguments, bbobConfig);

                    break;

                case GenericParameterization.RandomForestReuseOldTrees:
                    GenericBbobEntryPoint <
                        GenomePredictionRandomForest <ReuseOldTreesStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        ReuseOldTreesStrategy> .Run(argsParser.AdditionalArguments, bbobConfig);

                    break;

                case GenericParameterization.StandardRandomForest:
                case GenericParameterization.Default:
                default:
                    GenericBbobEntryPoint <
                        StandardRandomForestLearner <ReuseOldTreesStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        ReuseOldTreesStrategy> .Run(argsParser.AdditionalArguments, bbobConfig);

                    break;
                }
            }

            else
            {
                Worker.Run(args);
                return;
            }
        }
Пример #6
0
        /// <summary>
        /// Entry point to the program.
        /// </summary>
        /// <param name="args">If 'master' is included as argument, a
        /// <see cref="Master{TTargetAlgorithm,TInstance,TResult}"/> is starting using the remaining arguments.
        /// Otherwise, a <see cref="Worker"/> is started with the provided arguments.</param>
        public static void Main(string[] args)
        {
            LoggingHelper.Configure("bbobParserLog.txt");

            var configParser = new BbobRunnerConfigurationParser();

            if (!ArgumentParserUtils.ParseArguments(configParser, args))
            {
                return;
            }

            var bbobConfig = configParser.ConfigurationBuilder.Build();

            if (bbobConfig.IsMaster)
            {
                switch (bbobConfig.GenericParameterization)
                {
                case GenericParameterization.RandomForestAverageRank:
                    GenericBbobEntryPoint <
                        GenomePredictionRandomForest <AverageRankStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        AverageRankStrategy> .Run(configParser.AdditionalArguments, bbobConfig);

                    break;

                case GenericParameterization.RandomForestReuseOldTrees:
                    GenericBbobEntryPoint <
                        GenomePredictionRandomForest <ReuseOldTreesStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        ReuseOldTreesStrategy> .Run(configParser.AdditionalArguments, bbobConfig);

                    break;

                case GenericParameterization.StandardRandomForest:
                case GenericParameterization.Default:
                default:
                    GenericBbobEntryPoint <
                        StandardRandomForestLearner <ReuseOldTreesStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>,
                        ReuseOldTreesStrategy> .Run(configParser.AdditionalArguments, bbobConfig);

                    break;
                }
            }

            else
            {
                Worker.Run(args);
                return;
            }
        }
Пример #7
0
        /// <summary>
        /// Entry point to the program.
        /// </summary>
        /// <param name="args">If 'master' is included as argument, a
        /// <see cref="Master{TTargetAlgorithm,TInstance,TResult}"/> is starting using the remaining arguments.
        /// Otherwise, a <see cref="Worker"/> is started with the provided arguments.</param>
        public static void Main(string[] args)
        {
            LoggingHelper.Configure($"lingelingParserLog.txt");

            // Parse arguments.
            var argsParser = new LingelingRunnerConfigurationParser();

            if (!ArgumentParserUtils.ParseArguments(argsParser, args))
            {
                return;
            }

            var config = argsParser.ConfigurationBuilder.Build();

            // Start master or worker depending on arguments.
            if (config.IsMaster)
            {
                var bestParameters = config.GenericParameterization switch
                {
                    GenericParameterization.RandomForestAverageRank => GenericLingelingEntryPoint <
                        GenomePredictionRandomForest <AverageRankStrategy>, GenomePredictionForestModel <GenomePredictionTree>,
                        AverageRankStrategy>
                    .Run(argsParser.RemainingArguments, config),
                    GenericParameterization.RandomForestReuseOldTrees => GenericLingelingEntryPoint <
                        GenomePredictionRandomForest <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>,
                        ReuseOldTreesStrategy> .Run(argsParser.RemainingArguments, config),
                    GenericParameterization.StandardRandomForest => GenericLingelingEntryPoint <
                        StandardRandomForestLearner <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>,
                        ReuseOldTreesStrategy> .Run(argsParser.RemainingArguments, config),
                    GenericParameterization.Default => GenericLingelingEntryPoint <
                        StandardRandomForestLearner <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>,
                        ReuseOldTreesStrategy> .Run(argsParser.RemainingArguments, config),
                    _ => GenericLingelingEntryPoint <StandardRandomForestLearner <ReuseOldTreesStrategy>,
                                                     GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(argsParser.RemainingArguments, config)
                };

                Program.LogBestParameters(bestParameters, config);
            }
            else
            {
                Worker.Run(args);
            }
        }
Пример #8
0
        private static void Main(string[] args)
        {
            LoggingHelper.Configure();

            var cts = new CancellationTokenSource();

            const string endpointName = "EnduranceTest";

            Console.WriteLine("CTRL + C to stop test. Press Enter to continue.");
            Console.ReadLine();

            Console.CancelKeyPress += (s, e) =>
            {
                e.Cancel = true;
                cts.Cancel();
            };

            for (;;)
            {
                try
                {
                    RunEndpointAsync(endpointName, cts.Token).Wait(cts.Token);

                    break;
                }
                catch (OperationCanceledException)
                {
                    Console.WriteLine("Test Cancelled. Press ENTER to continue.");
                    Console.ReadLine();

                    break;
                }
                catch (Exception ex)
                {
                    LoggingHelper.Log.Error(ex, "Caught RunEndpointAsync Exception");
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Entry point to the program.
        /// </summary>
        /// <param name="args">Program arguments. Call the program with --help for more information.</param>
        public static void Main(string[] args)
        {
            ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture);
            LoggingHelper.Configure($"parserLog_{ProcessUtils.GetCurrentProcessId()}.log");

            // Parse arguments.
            var argsParser = new ArgumentParser();

            if (!ArgumentParserUtils.ParseArguments(argsParser, args))
            {
                return;
            }

            // Start master or worker depending on arguments.
            if (argsParser.IsMaster)
            {
                Program.RunMaster(argsParser);
            }
            else
            {
                Worker.Run(argsParser.AdditionalArguments.ToArray());
            }
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GrayBoxSimulation{TTargetAlgorithm, TInstance, TResult}" /> class.
        /// </summary>
        /// <param name="configuration">The <see cref="AlgorithmTunerConfiguration"/>.</param>
        /// <param name="targetAlgorithmFactory">The <see cref="ITargetAlgorithmFactory{TTargetAlgorithm, TInstance, TResult}"/>.</param>
        /// <param name="customGrayBoxMethods">The <see cref="ICustomGrayBoxMethods{TResult}"/>.</param>
        /// <param name="runEvaluator">The <see cref="IRunEvaluator{TInstance, TResult}"/>.</param>
        /// <param name="parameterTree">The <see cref="ParameterTree"/>.</param>
        public GrayBoxSimulation(
            AlgorithmTunerConfiguration configuration,
            ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory,
            ICustomGrayBoxMethods <TResult> customGrayBoxMethods,
            IRunEvaluator <TInstance, TResult> runEvaluator,
            ParameterTree parameterTree)
        {
            ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture);

            this._configuration          = configuration ?? throw new ArgumentNullException(nameof(configuration));
            this._customGrayBoxMethods   = customGrayBoxMethods ?? throw new ArgumentNullException(nameof(customGrayBoxMethods));
            this._runEvaluator           = runEvaluator ?? throw new ArgumentNullException(nameof(runEvaluator));
            this._targetAlgorithmFactory = targetAlgorithmFactory ?? throw new ArgumentNullException(nameof(targetAlgorithmFactory));
            this._parameterTree          = parameterTree ?? throw new ArgumentNullException(nameof(parameterTree));

            this._logFileDirectory = new DirectoryInfo(Path.Combine(this._configuration.DataRecordDirectoryPath, "GrayBoxSimulationLogFiles"));
            Directory.CreateDirectory(this._logFileDirectory.FullName);

            LoggingHelper.Configure(
                Path.Combine(this._logFileDirectory.FullName, $"consoleOutput_GrayBoxSimulation_{ProcessUtils.GetCurrentProcessId()}.log"));
            LoggingHelper.ChangeConsoleLoggingLevel(configuration.Verbosity);
            LoggingHelper.WriteLine(VerbosityLevel.Info, "Reading in and preprocessing data for gray box simulation.");

            if (!GrayBoxUtils.TryToReadDataRecordsFromDirectory(
                    targetAlgorithmFactory,
                    configuration.DataRecordDirectoryPath,
                    0,
                    configuration.Generations - 1,
                    out this._allDataRecords))
            {
                throw new ArgumentException($"Cannot read data records from {configuration.DataRecordDirectoryPath}!");
            }

            this.ReadGenerationCompositionFiles();
            this.CreatePredictionDictionaryAndDataDictionary();
        }
Пример #11
0
        /// <summary>
        /// Entry point to the program.
        /// </summary>
        /// <param name="args">If 'master' is included as argument, a
        /// <see cref="Master{TTargetAlgorithm,TInstance,TResult}"/> is starting using the provided arguments.
        /// Otherwise, a <see cref="Worker"/> is started with the provided arguments.</param>
        public static void Main(string[] args)
        {
            ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture);
            LoggingHelper.Configure($"parserLog_{ProcessUtils.GetCurrentProcessId()}.log");

            // Parse gurobi configuration.
            var gurobiParser = new GurobiRunnerConfigurationParser();

            if (!ArgumentParserUtils.ParseArguments(gurobiParser, args))
            {
                return;
            }

            if (gurobiParser.IsPostTuningRunner)
            {
                LoggingHelper.Configure($"consoleOutput_PostTuningRun_{ProcessUtils.GetCurrentProcessId()}.log");

                // Parse and build tuner configuration.
                var masterArgumentParser = new MasterArgumentParser();
                if (!ArgumentParserUtils.ParseArguments(masterArgumentParser, gurobiParser.AdditionalArguments.ToArray()))
                {
                    return;
                }

                var tunerConfig = masterArgumentParser.ConfigurationBuilder.Build();
                LoggingHelper.ChangeConsoleLoggingLevel(tunerConfig.Verbosity);

                // Build gurobi configuration.
                var gurobiConfig        = Program.BuildGurobiConfigAndCheckThreadCount(gurobiParser.ConfigurationBuilder, tunerConfig);
                var gurobiRunnerFactory = new GurobiRunnerFactory(gurobiConfig, tunerConfig);
                var parameterTree       = GurobiUtils.CreateParameterTree();

                // Start post tuning runner.
                var parallelPostTuningRunner =
                    new ParallelPostTuningRunner <GurobiRunner, InstanceSeedFile, GurobiResult>(
                        tunerConfig,
                        gurobiParser.PostTuningConfiguration,
                        gurobiRunnerFactory,
                        parameterTree);
                parallelPostTuningRunner.ExecutePostTuningRunsInParallel();

                return;
            }

            if (gurobiParser.IsMaster)
            {
                Master <GurobiRunner, InstanceSeedFile, GurobiResult, StandardRandomForestLearner <ReuseOldTreesStrategy>,
                        GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(
                    args : gurobiParser.AdditionalArguments.ToArray(),
                    algorithmTunerBuilder : (algorithmTunerConfig, pathToInstanceFolder, pathToTestInstanceFolder) =>
                    Program.BuildGurobiRunner(
                        algorithmTunerConfig,
                        pathToInstanceFolder,
                        pathToTestInstanceFolder,
                        gurobiParser.ConfigurationBuilder));
            }
            else
            {
                Worker.Run(gurobiParser.AdditionalArguments.ToArray());
            }
        }
Пример #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoggingHelperTest"/> class.
 /// </summary>
 public LoggingHelperTest()
 {
     LoggingHelper.Configure(LoggingHelperTest.LogFile);
 }