/// <summary> /// Builds a OPTANO Algorithm Tuner instance that tunes by process runtime. /// </summary> /// <param name="config"> /// The configuration. /// </param> /// <param name="trainingInstanceFolder"> /// The path to the folder containing training instances. /// </param> /// <param name="testInstanceFolder"> /// The path to the folder containing test instances. /// </param> /// <param name="basicCommand"> /// The basic command to the target algorithm as it should be executed by the /// command line. The path to the instance file and the parameters will be set by replacing /// <see cref="CommandExecutorBase{TResult}.InstanceReplacement"/> and /// <see cref="CommandExecutorBase{TResult}.ParameterReplacement"/>. /// </param> /// <param name="pathToParameterTree"> /// The path to a parameter tree defined via XML. /// </param> /// <param name="factorParK"> /// The factor for the penalization of the average runtime. /// </param> /// <returns> /// The built OPTANO Algorithm Tuner instance. /// </returns> private static AlgorithmTuner <TimeMeasuringExecutor, InstanceFile, RuntimeResult> BuildRuntimeTuner( AlgorithmTunerConfiguration config, string trainingInstanceFolder, string testInstanceFolder, string basicCommand, string pathToParameterTree, int factorParK) { IRunEvaluator <InstanceFile, RuntimeResult> runEvaluator; if (factorParK == 0) { runEvaluator = new SortByUnpenalizedRuntime <InstanceFile>(config.CpuTimeout); } else { runEvaluator = new SortByPenalizedRuntime <InstanceFile>(factorParK, config.CpuTimeout); } var tuner = new AlgorithmTuner <TimeMeasuringExecutor, InstanceFile, RuntimeResult>( targetAlgorithmFactory: new TimeMeasuringExecutorFactory(basicCommand, config.CpuTimeout), runEvaluator: runEvaluator, trainingInstances: ExtractInstances(trainingInstanceFolder), parameterTree: ParameterTreeConverter.ConvertToParameterTree(pathToParameterTree), configuration: config); if (testInstanceFolder != null) { tuner.SetTestInstances(ExtractInstances(testInstanceFolder)); } return(tuner); }
/// <summary> /// Creates a parameter tree from the "lingelingParamTree.xml" in the working directory. /// </summary> /// <returns>The <see cref="ParameterTree"/>.</returns> public static ParameterTree CreateParameterTree() { var parameterTree = ParameterTreeConverter.ConvertToParameterTree( Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"lingelingParamTree.xml")); LingelingUtils.AddAllActiveParameterWrappers(parameterTree); return parameterTree; }
public void DomainsReturnXmlDefaultValues() { Randomizer.Reset(); Randomizer.Configure(42); var tree = ParameterTreeConverter.ConvertToParameterTree(ParameterTreeConverterTest.PathPrefix + "treeWithDefaults.xml"); var nodes = tree.Root.Children.ToList(); Assert.Equal(5, nodes.Count); var contLog = (ParameterNodeBase <double>)nodes[0]; Assert.NotNull(contLog); Assert.Equal("contLog", contLog.Identifier); Assert.Equal(42d, contLog.Domain.GetDefaultValue().GetValue()); var contLinear = (ParameterNodeBase <double>)nodes[1]; Assert.NotNull(contLinear); Assert.Equal("contLinear", contLinear.Identifier); Assert.Equal(123.45, contLinear.Domain.GetDefaultValue().GetValue()); var discreteLog = (ParameterNodeBase <int>)nodes[2]; Assert.NotNull(discreteLog); Assert.Equal("discreteLog", discreteLog.Identifier); Assert.Equal(10, discreteLog.Domain.GetDefaultValue().GetValue()); var discreteLinear = (ParameterNodeBase <int>)nodes[3]; Assert.NotNull(discreteLinear); Assert.Equal("discreteLinear", discreteLinear.Identifier); Assert.Equal(100, discreteLinear.Domain.GetDefaultValue().GetValue()); var orNode = (OrNode <double>)nodes[4]; Assert.NotNull(orNode); Assert.Equal("or", orNode.Identifier); Assert.Equal(2, orNode.Children.Count()); Assert.Equal(0.3, orNode.Domain.GetDefaultValue().GetValue()); // make sure that domains without default value return a random value within the domain when calling GetDefaultValue. var orValueChild = orNode.Children.Skip(1).Single() as ValueNode <int>; Assert.NotNull(orValueChild); Assert.Equal("orChild2", orValueChild.Identifier); var defaultAllele = orValueChild.Domain.GetDefaultValue(); Assert.NotNull(defaultAllele); var defaultValue = defaultAllele.GetValue(); Assert.NotNull(defaultValue); Assert.True(orValueChild.Domain.ContainsGeneValue(defaultAllele)); }
/// <summary> /// Creates a <see cref="ParameterTree" /> of tuneable Gurobi parameters for MIP solving. /// The parameters and their connections are described in parameterTree.xml. /// <para> /// Defines parameter replacements for artificial parameters. /// </para> /// </summary> /// <returns>The <see cref="ParameterTree" />.</returns> public static ParameterTree CreateParameterTree() { var parameterTree = ParameterTreeConverter.ConvertToParameterTree( Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"parameterTree.xml")); // handle special case: RINS parameterTree.AddParameterReplacementDefinition(GurobiUtils.RinsActiveIdentifier, 0, GRB.IntParam.RINS.ToString(), 0, true); parameterTree.AddParameterReplacementDefinition(GurobiUtils.RinsActiveIdentifier, -1, GRB.IntParam.RINS.ToString(), -1, true); // filter all ignored parameters foreach (var artificialNodeIdentifier in GurobiUtils.ArtificialNodeIdentifiers) { parameterTree.AddIgnoredParameter(artificialNodeIdentifier); } return(parameterTree); }
/// <summary> /// Checks console output on calling <see cref="ParameterTreeConverter.ConvertToParameterTree(string)"/>. /// </summary> /// <param name="fileName">File name of file lying in <see cref="PathPrefix"/>. Will be tried to be converted. /// </param> /// <param name="check">Checks to do on the output.</param> private void CheckConsoleOutput(string fileName, Action <StringReader> check) { TestUtils.CheckOutput( action: () => { // Call converter. ParameterTreeConverter.ConvertToParameterTree(ParameterTreeConverterTest.PathPrefix + fileName); }, check: consoleOutput => { // Check the console output. using (var reader = new StringReader(consoleOutput.ToString())) { check.Invoke(reader); } }); }
/// <summary> /// Builds a OPTANO Algorithm Tuner instance that tunes by last value printed to console. /// </summary> /// <param name="config">The configuration.</param> /// <param name="trainingInstanceFolder">The path to the folder containing training instances.</param> /// <param name="testInstanceFolder">The path to the folder containing test instances.</param> /// <param name="basicCommand">The basic command to the target algorithm as it should be executed by the /// command line. The path to the instance file and the parameters will be set by replacing /// <see cref="CommandExecutorBase{TResult}.InstanceReplacement"/> and /// <see cref="CommandExecutorBase{TResult}.ParameterReplacement"/>.</param> /// <param name="pathToParameterTree">The path to a parameter tree defined via XML.</param> /// <param name="ascending">Whether smaller values are better.</param> /// <returns>The built OPTANO Algorithm Tuner instance.</returns> private static AlgorithmTuner <ValueReadingExecutor, InstanceFile, ContinuousResult> BuildValueTuner( AlgorithmTunerConfiguration config, string trainingInstanceFolder, string testInstanceFolder, string basicCommand, string pathToParameterTree, bool ascending) { var tuner = new AlgorithmTuner <ValueReadingExecutor, InstanceFile, ContinuousResult>( targetAlgorithmFactory: new ValueReadingExecutorFactory(basicCommand, config.CpuTimeout), runEvaluator: new SortByValue(ascending), trainingInstances: ExtractInstances(trainingInstanceFolder), parameterTree: ParameterTreeConverter.ConvertToParameterTree(pathToParameterTree), configuration: config); if (testInstanceFolder != null) { tuner.SetTestInstances(ExtractInstances(testInstanceFolder)); } return(tuner); }
public void ConvertToParameterTreeReturnsNullForMissingFile() { Assert.Null( ParameterTreeConverter.ConvertToParameterTree("foo.xml")); }
public void ConvertToParameterTreeWorksForExampleTree() { // Convert XML to tree. var tree = ParameterTreeConverter.ConvertToParameterTree(ParameterTreeConverterTest.PathPrefix + "exampleTree.xml"); // Check root node. Assert.NotNull(tree.Root); Assert.Equal(typeof(AndNode), tree.Root.GetType()); // Check root node has the desired children. Assert.Equal(2, tree.Root.Children.Count()); // Check type and identifier for OR node (first root child). var orNode = tree.Root.Children.First() as OrNode <double>; Assert.True(orNode != null, "First root child is not a double OR node as expected."); Assert.Equal("or", orNode.Identifier); // defaultValue of OR node should be the 2nd value of the categorical list (= 0.3). Assert.Equal(0.3, orNode.Domain.GetDefaultValue().GetValue()); // Check values / children for OR node (first root child). IParameterTreeNode secondAndNode; Assert.True(orNode.TryGetChild(0.1, out secondAndNode), "OR node did not have a child at 0.1."); IParameterTreeNode integerValueNode; Assert.True(orNode.TryGetChild(0.5, out integerValueNode), "OR node did not have a child at 0.5"); Assert.True( orNode.Domain.ContainsGeneValue(new Allele <double>(0.3)), "0.3 should be a possible value for OR node."); // Check type, identifier and values for continuous value node (second root child). var firstLevelValueNode = tree.Root.Children.Skip(1).First() as ValueNode <double>; Assert.True(firstLevelValueNode != null, "Second root child is not a double value node as expected."); Assert.Equal("value2", firstLevelValueNode.Identifier); Assert.True( firstLevelValueNode.Domain is ContinuousDomain, "Continuous value node's domain is not continuous."); Assert.True( firstLevelValueNode.Domain.ContainsGeneValue(new Allele <double>(-0.1)), "Continuous value node's domain does not contain -0.1."); Assert.True( firstLevelValueNode.Domain.ContainsGeneValue(new Allele <double>(0)), "Continuous value node's domain does not contain 0."); // Check type for second AND node (child of OR node). Assert.True(secondAndNode is AndNode, "Child at 0.1 should have been an AND node."); // Check type, identifier and values for integer value node (child of OR node). var discreteValueNode = integerValueNode as ValueNode <int>; Assert.True(discreteValueNode != null, "Child at 0.5 should have been an integer value node."); Assert.Equal("value1", discreteValueNode.Identifier); Assert.True(discreteValueNode.Domain is IntegerDomain, "Discrete value node's domain is not integer."); Assert.True( discreteValueNode.Domain.ContainsGeneValue(new Allele <int>(-2)), "Discrete value node's domain does not contain -2."); Assert.True( discreteValueNode.Domain.ContainsGeneValue(new Allele <int>(3)), "Discrete value node's domain does not contain 3."); // Check type, identifier and values for child of continuous value node. var logNode = firstLevelValueNode.Children.Single() as ValueNode <double>; Assert.True(logNode != null, "Child of continuous value node should have been a log value node."); Assert.Equal("value3", logNode.Identifier); Assert.True(logNode.Domain is LogDomain, "Log value node's domain is not a log domain."); Assert.True( logNode.Domain.ContainsGeneValue(new Allele <double>(10)), "Log value node's domain does not contain 10."); Assert.True( logNode.Domain.ContainsGeneValue(new Allele <double>(100)), "Log value node's domain does not contain 100."); }
public void ConvertToParameterTreeReturnsNullForChoiceOfWrongType() { Assert.Null( ParameterTreeConverter.ConvertToParameterTree(ParameterTreeConverterTest.PathPrefix + "wrongChoice.xml")); }
public void ConvertToParameterTreeReturnsNullForOrNodeWithoutCategoricalDomain() { Assert.Null( ParameterTreeConverter.ConvertToParameterTree(ParameterTreeConverterTest.PathPrefix + "orNodeWithoutCategoricalDomain.xml")); }
public void ConvertToParameterTreeReturnsNullForCategoricalDomainWithMixedTypes() { Assert.Null( ParameterTreeConverter.ConvertToParameterTree(ParameterTreeConverterTest.PathPrefix + "mixedCategoricalDomain.xml")); }
public void ConvertToParameterTreeReturnsNullForXmlNotMatchingXsd() { Assert.Null( ParameterTreeConverter.ConvertToParameterTree(ParameterTreeConverterTest.PathPrefix + "illegal.xml")); }
public void ConvertToParameterTreeReturnsNullForBrokenXml() { Assert.Null( ParameterTreeConverter.ConvertToParameterTree(ParameterTreeConverterTest.PathPrefix + "broken.xml")); }
public void ConvertToParameterTreeReturnsNullForNonXml() { Assert.Null( ParameterTreeConverter.ConvertToParameterTree(ParameterTreeConverterTest.PathPrefix + "wrongExtension.txt")); }