public void CreateInstancesPrintsMessageIfItCannotOpenFolder() { TestUtils.CheckOutput( action: () => { // Call CreateInstanceSeedFilesFromDirectory with a non existant directory path. try { InstanceSeedFile.CreateInstanceSeedFilesFromDirectory( "foobarFolder", InstanceSeedFileTest.ValidInstanceExtensions, 1, 42); } catch (DirectoryNotFoundException) { // This is expected. } }, check: consoleOutput => { // Check that information about it is written to console. var reader = new StringReader(consoleOutput.ToString()); reader.ReadLine().ShouldContain("foobarFolder"); reader.ReadLine().ShouldBe("Cannot open instance directory foobarFolder!"); }); }
public void CreateInstancesThrowsExceptionIfItCannotOpenFolder() { Exception exception = Assert.Throws <DirectoryNotFoundException>( () => { InstanceSeedFile.CreateInstanceSeedFilesFromDirectory( "foobarFolder", InstanceSeedFileTest.ValidInstanceExtensions, 1, 42); }); }
public void CreateInstancesIgnoresNonValidFiles() { // Call method. var instances = InstanceSeedFile.CreateInstanceSeedFilesFromDirectory( this._pathToTestInstanceFolder, InstanceSeedFileTest.ValidInstanceExtensions, 1, 42); // Check that no non valid file has been translated into an instance. var instancePaths = instances.Select(instance => instance.Path); instancePaths.Any(path => InstanceSeedFileTest.NonValidFileNames.Any(path.Contains)) .ShouldBeFalse("Not all non valid files have been ignored."); }
public void CreateInstancesCorrectlyExtractsPathsToValidFiles() { // Call method. var instances = InstanceSeedFile.CreateInstanceSeedFilesFromDirectory( this._pathToTestInstanceFolder, InstanceSeedFileTest.ValidInstanceExtensions, 1, 42); // Check that file names of instances match the complete paths of all valid files. var expectedPaths = InstanceSeedFileTest.ValidFileNames .Select(name => this._pathToTestInstanceFolder + Path.DirectorySeparatorChar + name).ToList(); var instancePaths = instances.Select(instance => instance.Path).ToList(); expectedPaths.ShouldBe( instancePaths, true, $"{TestUtils.PrintList(instancePaths)} should have been equal to {TestUtils.PrintList(expectedPaths)}."); }
BuildLingelingAlgorithmTuner( AlgorithmTunerConfiguration tunerConfig, string trainingInstanceFolder, string testInstanceFolder, LingelingRunnerConfiguration 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 <LingelingRunner, InstanceSeedFile, RuntimeResult, TLearnerModel, TPredictorModel, TSamplingStrategy>( targetAlgorithmFactory: new LingelingRunnerFactory(runnerConfig.PathToExecutable, tunerConfig, runnerConfig.MemoryLimitMegabyte), runEvaluator: runEvaluator, trainingInstances: InstanceSeedFile.CreateInstanceSeedFilesFromDirectory( trainingInstanceFolder, LingelingUtils.ListOfValidFileExtensions, runnerConfig.NumberOfSeeds, runnerConfig.RngSeed), parameterTree: LingelingUtils.CreateParameterTree(), configuration: tunerConfig); if (!string.IsNullOrWhiteSpace(testInstanceFolder)) { tuner.SetTestInstances( InstanceSeedFile.CreateInstanceSeedFilesFromDirectory( testInstanceFolder, LingelingUtils.ListOfValidFileExtensions, runnerConfig.NumberOfSeeds, runnerConfig.RngSeed)); } return(tuner); }
/// <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); }