1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 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 |
|
---|
22 | using System;
|
---|
23 | using System.Text;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using System.Linq;
|
---|
26 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
28 | using HeuristicLab.Random;
|
---|
29 | using System.Diagnostics;
|
---|
30 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators;
|
---|
31 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
|
---|
34 | [TestClass]
|
---|
35 | public class SubroutineDeleterTest {
|
---|
36 | private const int POPULATION_SIZE = 1000;
|
---|
37 | private const int MAX_TREE_SIZE = 100;
|
---|
38 | private const int MAX_TREE_HEIGHT = 10;
|
---|
39 | private TestContext testContextInstance;
|
---|
40 |
|
---|
41 | /// <summary>
|
---|
42 | ///Gets or sets the test context which provides
|
---|
43 | ///information about and functionality for the current test run.
|
---|
44 | ///</summary>
|
---|
45 | public TestContext TestContext {
|
---|
46 | get {
|
---|
47 | return testContextInstance;
|
---|
48 | }
|
---|
49 | set {
|
---|
50 | testContextInstance = value;
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | [TestMethod()]
|
---|
55 | public void SubroutineDeleterDistributionsTest() {
|
---|
56 | var trees = new List<SymbolicExpressionTree>();
|
---|
57 | var grammar = Grammars.CreateArithmeticAndAdfGrammar();
|
---|
58 | var random = new MersenneTwister(31415);
|
---|
59 | int failedEvents = 0;
|
---|
60 | for (int i = 0; i < POPULATION_SIZE; i++) {
|
---|
61 | var tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3);
|
---|
62 | if (!SubroutineDeleter.DeleteSubroutine(random, tree, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3))
|
---|
63 | failedEvents++;
|
---|
64 | Util.IsValid(tree);
|
---|
65 | trees.Add(tree);
|
---|
66 | }
|
---|
67 | Assert.Inconclusive("SubroutineDeleter: " + Environment.NewLine +
|
---|
68 | "Failed events: " + failedEvents / (double)POPULATION_SIZE * 100 + " %" + Environment.NewLine +
|
---|
69 | Util.GetSizeDistributionString(trees, 105, 5) + Environment.NewLine +
|
---|
70 | Util.GetFunctionDistributionString(trees) + Environment.NewLine +
|
---|
71 | Util.GetNumberOfSubTreesDistributionString(trees) + Environment.NewLine +
|
---|
72 | Util.GetTerminalDistributionString(trees) + Environment.NewLine
|
---|
73 | );
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|