Exemplo n.º 1
0
        /// <summary>
        /// Builds an instance of the <see cref="AlgorithmTuner{TTargetAlorithm,TInstance,TResult}" /> class for tuning Gurobi.
        /// </summary>
        /// <param name="configuration">The <see cref="AlgorithmTunerConfiguration" /> to use.</param>
        /// <param name="pathToTrainingInstanceFolder">The path to the folder containing training instances.</param>
        /// <param name="pathToTestInstanceFolder">The path to test instance folder.</param>
        /// <param name="gurobiConfigBuilder">The gurobi configuration builder.</param>
        /// <returns>
        /// The built instance.
        /// </returns>
        public static AlgorithmTuner <GurobiRunner, InstanceSeedFile, GurobiResult> BuildGurobiRunner(
            AlgorithmTunerConfiguration configuration,
            string pathToTrainingInstanceFolder,
            string pathToTestInstanceFolder,
            GurobiRunnerConfiguration.GurobiRunnerConfigBuilder gurobiConfigBuilder)
        {
            var gurobiConfig = gurobiConfigBuilder.Build(configuration.CpuTimeout);

            var tuner = new AlgorithmTuner <GurobiRunner, InstanceSeedFile, GurobiResult>(
                targetAlgorithmFactory: new GurobiRunnerFactory(gurobiConfig),
                runEvaluator: new GurobiRunEvaluator(),
                trainingInstances: GurobiUtils.CreateInstances(pathToTrainingInstanceFolder, gurobiConfig.NumberOfSeeds, gurobiConfig.RngSeed),
                parameterTree: GurobiUtils.CreateParameterTree(),
                configuration: configuration);

            try
            {
                if (!string.IsNullOrWhiteSpace(pathToTestInstanceFolder))
                {
                    var testInstances = GurobiUtils.CreateInstances(pathToTestInstanceFolder, gurobiConfig.NumberOfSeeds, gurobiConfig.RngSeed);
                    tuner.SetTestInstances(testInstances);
                }
            }
            catch
            {
            }

            return(tuner);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Builds an instance of the <see cref="AlgorithmTuner{TTargetAlorithm,TInstance,TResult}" /> class for tuning Gurobi.
        /// </summary>
        /// <param name="tunerConfig">The <see cref="AlgorithmTunerConfiguration" /> to use.</param>
        /// <param name="pathToTrainingInstanceFolder">The path to the folder containing training instances.</param>
        /// <param name="pathToTestInstanceFolder">The path to test instance folder.</param>
        /// <param name="gurobiConfigBuilder">The gurobi configuration builder.</param>
        /// <returns>
        /// The built instance.
        /// </returns>
        public static AlgorithmTuner <GurobiRunner, InstanceSeedFile, GurobiResult> BuildGurobiRunner(
            AlgorithmTunerConfiguration tunerConfig,
            string pathToTrainingInstanceFolder,
            string pathToTestInstanceFolder,
            GurobiRunnerConfiguration.GurobiRunnerConfigBuilder gurobiConfigBuilder)
        {
            var gurobiConfig = Program.BuildGurobiConfigAndCheckThreadCount(gurobiConfigBuilder, tunerConfig);

            var tuner = new AlgorithmTuner <GurobiRunner, InstanceSeedFile, GurobiResult>(
                targetAlgorithmFactory: new GurobiRunnerFactory(gurobiConfig, tunerConfig),
                runEvaluator: new GurobiRunEvaluator(tunerConfig.CpuTimeout),
                trainingInstances: InstanceSeedFile.CreateInstanceSeedFilesFromDirectory(
                    pathToTrainingInstanceFolder,
                    GurobiUtils.ListOfValidFileExtensions,
                    gurobiConfig.NumberOfSeeds,
                    gurobiConfig.RngSeed),
                parameterTree: GurobiUtils.CreateParameterTree(),
                configuration: tunerConfig,
                customGrayBoxMethods: new GurobiGrayBoxMethods());

            try
            {
                if (!string.IsNullOrWhiteSpace(pathToTestInstanceFolder))
                {
                    var testInstances = InstanceSeedFile.CreateInstanceSeedFilesFromDirectory(
                        pathToTestInstanceFolder,
                        GurobiUtils.ListOfValidFileExtensions,
                        gurobiConfig.NumberOfSeeds,
                        gurobiConfig.RngSeed);
                    tuner.SetTestInstances(testInstances);
                }
            }
            catch
            {
            }

            return(tuner);
        }
Exemplo n.º 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 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());
            }
        }