1 | using System;
|
---|
2 | using System.Linq;
|
---|
3 | using HeuristicLab.Algorithms.Bandits.BanditPolicies;
|
---|
4 | using HeuristicLab.Algorithms.Bandits.GrammarPolicies;
|
---|
5 | using HeuristicLab.Algorithms.GeneticProgramming;
|
---|
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() {
|
---|
16 | var problem = new SymbolicRegressionProblem(new Random(), "Tower");
|
---|
17 | Assert.IsNotNull(problem);
|
---|
18 | }
|
---|
19 |
|
---|
20 | [TestMethod]
|
---|
21 | public void TestConstantOptimization() {
|
---|
22 | double r2;
|
---|
23 | var problem = new SymbolicRegressionProblem(new Random(), "Tower");
|
---|
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"));
|
---|
31 | }
|
---|
32 |
|
---|
33 | [TestMethod]
|
---|
34 | [Timeout(1000 * 60 * 60 * 8)] // 8 hours
|
---|
35 | public void TestSequentialSolverForTower() {
|
---|
36 | var problem = new SymbolicRegressionProblem(new Random(), "Tower");
|
---|
37 | var random = new Random(31415);
|
---|
38 | var solver = new SequentialSearch(problem, 50, random, 0, new GenericFunctionApproximationGrammarPolicy(problem, true));
|
---|
39 | solver.FoundNewBestSolution += (s, d) => {
|
---|
40 | Console.WriteLine("{0:F3} {1}", d, s);
|
---|
41 | };
|
---|
42 | solver.Run(100000);
|
---|
43 | }
|
---|
44 |
|
---|
45 | }
|
---|
46 | }
|
---|