Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.2/sources/HeuristicLab.GP.Tests/TournamentPruningTest.cs @ 14728

Last change on this file since 14728 was 3874, checked in by gkronber, 15 years ago

Added first implementation of a simple randomized greedy pruning operator. #125 (Pruning operator)

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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 HeuristicLab.GP.StructureIdentification;
23using Microsoft.VisualStudio.TestTools.UnitTesting;
24using HeuristicLab.GP.Interfaces;
25using System.IO;
26using HeuristicLab.DataAnalysis;
27using System;
28using HeuristicLab.Random;
29using System.Collections.Generic;
30using HeuristicLab.GP.Operators;
31using System.Diagnostics;
32using HeuristicLab.Core;
33namespace HeuristicLab.GP.Test {
34
35
36  [TestClass()]
37  public class TournamentPruningTest {
38    private TestContext testContextInstance;
39
40    /// <summary>
41    ///Gets or sets the test context which provides
42    ///information about and functionality for the current test run.
43    ///</summary>
44    public TestContext TestContext {
45      get {
46        return testContextInstance;
47      }
48      set {
49        testContextInstance = value;
50      }
51    }
52
53    [TestMethod()]
54    public void TournamentPruningPruneTest() {
55      IRandom random = new MersenneTwister();
56
57      Dataset ds = new Dataset(new double[,] {
58        { 1.0, 1.0, 1.0 },
59        { 2.0, 2.0, 2.0 },
60        { 3.0, 1.0, 2.0 }
61      });
62
63      ds.SetVariableName(0, "y");
64      ds.SetVariableName(1, "a");
65      ds.SetVariableName(2, "b");
66
67      var importer = new SymbolicExpressionImporter();
68      HL3TreeEvaluator evaluator = new HL3TreeEvaluator();
69
70
71      IFunctionTree prunedTree = null;
72      prunedTree = TournamentPruning.Prune(random, importer.Import("(+ 1.5 3.5)"), 3, ds, "y", 0, 2, evaluator, 1.0, 1.0);
73      prunedTree = TournamentPruning.Prune(random, importer.Import("(+ (variable 2.0 a 0) (+ 1.5 3.5))"), 3, ds, "y", 0, 2, evaluator, 1.0, 1.0);
74      prunedTree = TournamentPruning.Prune(random, importer.Import("(+ (variable 2.0 a 0) (variable 0.00001 a 0))"), 3, ds, "y", 0, 2, evaluator, 1.0, 1.0);
75      prunedTree = TournamentPruning.Prune(random, importer.Import("(+ (variable 1.0 a 0) (variable 1.0 b 0))"), 3, ds, "y", 0, 2, evaluator, 1.0, 1.0);
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.