public void SeedsToUseReturnsCorrectNumberOfSeeds() { var numberOfSeeds = 6; var seedsToUse = GurobiUtils.SeedsToUse(numberOfSeeds, 42); seedsToUse.Count().ShouldBe(numberOfSeeds); }
public void GetFileNameWithoutGurobiExtensionReturnsCorrectFileName(string fileName, string extension) { var fileInfo = new FileInfo(fileName + extension); var fileNameWithoutExtension = GurobiUtils.GetFileNameWithoutGurobiExtension(fileInfo); fileNameWithoutExtension.ShouldBe(fileName); }
public void CorrectGrayBoxFeaturesAreSelected() { var gurobiGrayBoxMethods = new GurobiGrayBoxMethods(); var runtimeFeatures = new GurobiRuntimeFeatures(DateTime.Now); var instanceFeatures = new GurobiInstanceFeatures(); var adapterFeatures = GurobiUtils.ComposeAdapterFeatures(runtimeFeatures, runtimeFeatures, instanceFeatures); var adapterFeaturesHeader = GurobiUtils.ComposeAdapterFeaturesHeader(runtimeFeatures, runtimeFeatures, instanceFeatures); var result = new GurobiResult(double.NaN, TimeSpan.MaxValue, TargetAlgorithmStatus.CancelledByTimeout, false); var adapterDataRecord = new AdapterDataRecord <GurobiResult>( "Gurobi901", TargetAlgorithmStatus.Running, TimeSpan.Zero, TimeSpan.Zero, DateTime.Now, adapterFeaturesHeader, adapterFeatures, result); var tunerDataRecord = new TunerDataRecord <GurobiResult>( "Node", 0, 0, "Instance", 0.5, new[] { "Genome" }, (GenomeDoubleRepresentation) new[] { 0D }, result); var dataRecord = new DataRecord <GurobiResult>(tunerDataRecord, adapterDataRecord); var featureNames = gurobiGrayBoxMethods.GetGrayBoxFeatureNamesFromDataRecord(dataRecord); var correctFeatureNames = new[] { "ExpendedWallClockTime", "RuntimeFeature_CuttingPlanesCount_Current", "RuntimeFeature_ExploredNodeCount_Current", "RuntimeFeature_FeasibleSolutionsCount_Current", "RuntimeFeature_MipGap_Current", "RuntimeFeature_SimplexIterationsCount_Current", "RuntimeFeature_UnexploredNodeCount_Current", "RuntimeFeature_CuttingPlanesCount_Last", "RuntimeFeature_ExploredNodeCount_Last", "RuntimeFeature_FeasibleSolutionsCount_Last", "RuntimeFeature_MipGap_Last", "RuntimeFeature_SimplexIterationsCount_Last", "RuntimeFeature_UnexploredNodeCount_Last", "InstanceFeature_NumberOfIntegerVariables", "InstanceFeature_NumberOfLinearConstraints", "InstanceFeature_NumberOfNonZeroCoefficients", "InstanceFeature_NumberOfVariables", }; featureNames.SequenceEqual(correctFeatureNames).ShouldBeTrue(); }
public void CreateInstancesIgnoresFilesNotInMpsFormat() { // Call method. var instances = GurobiUtils.CreateInstances(this._instanceFolder, 1, 42); // Check that no non-mps file has been translated into an instance. var instancePaths = instances.Select(instance => instance.Path); instancePaths.Any(path => GurobiUtilsTests.NonMpsFileNames.Any(file => path.Contains(file))) .ShouldBeFalse("Not all non-mps files have been ignored."); }
public void CreateParameterTreeThrowsNoException() { try { var parameterTree = GurobiUtils.CreateParameterTree(); } catch (Exception exception) { Assert.True(false, $"Exception: {exception.Message}"); } }
public void CreateInstancesCorrectlyExtractsPathsToMpsFiles() { // Call method. var instances = GurobiUtils.CreateInstances(this._instanceFolder, 1, 42); // Check that file names of instances match the complete paths of all .mps files. var expectedPaths = GurobiUtilsTests.MpsFileNames.Select(name => this._instanceFolder + Path.DirectorySeparatorChar + name); var instancePaths = instances.Select(instance => instance.Path); expectedPaths.ShouldBe( instancePaths, true, $"{TestUtils.PrintList(instancePaths)} should have been equal to {TestUtils.PrintList(expectedPaths)}."); }
public void AllDummyParametersAreFiltered() { Randomizer.Reset(); Randomizer.Configure(0); var parameterTree = GurobiUtils.CreateParameterTree(); var config = new AlgorithmTunerConfiguration.AlgorithmTunerConfigurationBuilder().Build(1); var genomeBuilder = new GenomeBuilder(parameterTree, config); var genome = genomeBuilder.CreateRandomGenome(0); var filteredGenes = genome.GetFilteredGenes(parameterTree); foreach (var filteredGenesKey in filteredGenes.Keys) { filteredGenesKey.ShouldNotContain("Indicator"); } }
/// <summary> /// Initializes a new instance of the <see cref="GurobiRuntimeFeatures" /> class. /// </summary> /// <param name="timeStamp">The time stamp.</param> public GurobiRuntimeFeatures(DateTime timeStamp) { this._immutableTimeSinceLastCallback = null; this.TimeStampOfLastEditing = timeStamp; this.BestObjective = double.NaN; this.BestObjectiveBound = double.NaN; this.FeasibleSolutionsCount = 0; this.ExploredNodeCount = 0; this.UnexploredNodeCount = 0; this.BarrierIterationsCount = 0; this.SimplexIterationsCount = 0; this.CuttingPlanesCount = 0; this.MipGap = GurobiUtils.GetMipGap(double.NaN, double.NaN); this.PreSolveRemovedRows = 0; this.PreSolveRemovedColumns = 0; this.PreSolveConstraintChanges = 0; this.PreSolveBoundChanges = 0; this.PreSolveCoefficientChanges = 0; }
public void CreateInstancesPrintsMessageIfItCannotOpenFolder() { TestUtils.CheckOutput( action: () => { // Call CreateInstances with a non existant directory path. try { GurobiUtils.CreateInstances("foobarFolder", 1, 42); } catch (DirectoryNotFoundException) { // This is expected. } }, check: consoleOutput => { // Check that information about it is written to console. StringReader reader = new StringReader(consoleOutput.ToString()); reader.ReadLine().ShouldContain("foobarFolder", "The problematic path did not get printed."); reader.ReadLine().ShouldBe("Cannot open folder.", "Cause of exception has not been printed."); }); }
public void CreateInstancesThrowsExceptionIfItCannotOpenFolder() { Exception exception = Assert.Throws <DirectoryNotFoundException>( () => { GurobiUtils.CreateInstances("foobarFolder", 1, 42); }); }
public void GetFileNameWithoutGurobiExtensionThrowsIfExtensionIsNotValid(string fileName) { var fileInfo = new FileInfo(fileName); Assert.Throws <ArgumentException>(() => GurobiUtils.GetFileNameWithoutGurobiExtension(fileInfo)); }
public void GetMipGapReturnsCorrectResult(double bestObjective, double bestObjectiveBound, double expectedResult) { var actualResult = GurobiUtils.GetMipGap(bestObjective, bestObjectiveBound); actualResult.ShouldBe(expectedResult); }