[11732] | 1 | using System;
|
---|
| 2 | using System.Linq;
|
---|
[12014] | 3 | using HeuristicLab.Algorithms.Bandits.BanditPolicies;
|
---|
| 4 | using HeuristicLab.Algorithms.Bandits.GrammarPolicies;
|
---|
[11895] | 5 | using HeuristicLab.Algorithms.GeneticProgramming;
|
---|
[11732] | 6 | using HeuristicLab.Algorithms.GrammaticalOptimization;
|
---|
| 7 | using HeuristicLab.Problems.GrammaticalOptimization.SymbReg;
|
---|
| 8 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 9 |
|
---|
| 10 | namespace HeuristicLab.Problems.GrammaticalOptimization.Test {
|
---|
| 11 | // tests for the brige to the HL symb-reg instances
|
---|
| 12 | [TestClass]
|
---|
| 13 | public class TestSymbRegInstances {
|
---|
| 14 | [TestMethod]
|
---|
| 15 | public void TestGetDataDescriptors() {
|
---|
[12014] | 16 | var problem = new SymbolicRegressionProblem(new Random(), "Tower");
|
---|
| 17 | Assert.IsNotNull(problem);
|
---|
| 18 | }
|
---|
[11732] | 19 |
|
---|
[12014] | 20 | [TestMethod]
|
---|
| 21 | public void TestConstantOptimization() {
|
---|
| 22 | double r2;
|
---|
[11832] | 23 | var problem = new SymbolicRegressionProblem(new Random(), "Tower");
|
---|
[11895] | 24 | Assert.AreEqual(problem.Evaluate("a*b"), problem.OptimizeConstantsAndEvaluate("a*b"));
|
---|
| 25 | Assert.AreEqual(problem.OptimizeConstantsAndEvaluate("a*b"), problem.Evaluate("a*b"));
|
---|
| 26 | Assert.AreEqual(problem.OptimizeConstantsAndEvaluate("0*a*b"), problem.Evaluate("a*b"), 1E-6);
|
---|
| 27 | Assert.AreEqual(problem.OptimizeConstantsAndEvaluate("0*a*b+1"), problem.Evaluate("a*b"), 1E-6);
|
---|
| 28 | Assert.IsTrue(problem.OptimizeConstantsAndEvaluate("0*a+b") >= problem.Evaluate("a+b"));
|
---|
| 29 | Assert.AreEqual(problem.OptimizeConstantsAndEvaluate("0*a+0*b"), problem.Evaluate("a+b"), 1E-6);
|
---|
| 30 | Assert.IsTrue(problem.OptimizeConstantsAndEvaluate("0*a+1*b") >= problem.Evaluate("a+b"));
|
---|
[11732] | 31 | }
|
---|
[12014] | 32 |
|
---|
| 33 | [TestMethod]
|
---|
[12025] | 34 | [Timeout(1000 * 60 * 60 * 8)] // 8 hours
|
---|
[12014] | 35 | public void TestSequentialSolverForTower() {
|
---|
| 36 | var problem = new SymbolicRegressionProblem(new Random(), "Tower");
|
---|
| 37 | var random = new Random(31415);
|
---|
[12025] | 38 | var solver = new SequentialSearch(problem, 50, random, 0, new GenericFunctionApproximationGrammarPolicy(problem, true));
|
---|
[12014] | 39 | solver.FoundNewBestSolution += (s, d) => {
|
---|
| 40 | Console.WriteLine("{0:F3} {1}", d, s);
|
---|
| 41 | };
|
---|
[12025] | 42 | solver.Run(100000);
|
---|
[12014] | 43 | }
|
---|
| 44 |
|
---|
[11732] | 45 | }
|
---|
| 46 | }
|
---|