Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/SubroutineDeleterTest.cs @ 10147

Last change on this file since 10147 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
27using HeuristicLab.Random;
28using Microsoft.VisualStudio.TestTools.UnitTesting;
29
30namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
31  [TestClass]
32  public class SubroutineDeleterTest {
33    private const int POPULATION_SIZE = 1000;
34    private const int MAX_TREE_SIZE = 100;
35    private const int MAX_TREE_HEIGHT = 10;
36    private TestContext testContextInstance;
37
38    /// <summary>
39    ///Gets or sets the test context which provides
40    ///information about and functionality for the current test run.
41    ///</summary>
42    public TestContext TestContext {
43      get {
44        return testContextInstance;
45      }
46      set {
47        testContextInstance = value;
48      }
49    }
50
51    [TestMethod()]
52    public void SubroutineDeleterDistributionsTest() {
53      var trees = new List<SymbolicExpressionTree>();
54      var grammar = Grammars.CreateArithmeticAndAdfGrammar();
55      var random = new MersenneTwister(31415);
56      for (int i = 0; i < POPULATION_SIZE; i++) {
57        SymbolicExpressionTree tree = null;
58        do {
59          tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3);
60        } while (!HasAtLeastOneAdf(tree));
61        var success = SubroutineDeleter.DeleteSubroutine(random, tree, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3);
62        Assert.IsTrue(success);
63        Util.IsValid(tree);
64        trees.Add(tree);
65      }
66      Console.WriteLine("SubroutineDeleter: " + Environment.NewLine +
67        Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine +
68        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
69        Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
70        Util.GetTerminalDistributionString(trees) + Environment.NewLine
71        );
72    }
73
74    private bool HasAtLeastOneAdf(SymbolicExpressionTree tree) {
75      return tree.Root.SubTrees.Count > 1;
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.