#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using HeuristicLab.GP.StructureIdentification;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HeuristicLab.GP.Interfaces;
using System.IO;
using HeuristicLab.DataAnalysis;
using System;
using HeuristicLab.Random;
using System.Collections.Generic;
using HeuristicLab.GP.Operators;
using System.Diagnostics;
using HeuristicLab.Core;
namespace HeuristicLab.GP.Test {
[TestClass()]
public class TournamentPruningTest {
private TestContext testContextInstance;
///
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///
public TestContext TestContext {
get {
return testContextInstance;
}
set {
testContextInstance = value;
}
}
[TestMethod()]
public void TournamentPruningPruneTest() {
IRandom random = new MersenneTwister();
Dataset ds = new Dataset(new double[,] {
{ 1.0, 1.0, 1.0 },
{ 2.0, 2.0, 2.0 },
{ 3.0, 1.0, 2.0 }
});
ds.SetVariableName(0, "y");
ds.SetVariableName(1, "a");
ds.SetVariableName(2, "b");
var importer = new SymbolicExpressionImporter();
HL3TreeEvaluator evaluator = new HL3TreeEvaluator();
IFunctionTree prunedTree = null;
prunedTree = TournamentPruning.Prune(random, importer.Import("(+ 1.5 3.5)"), 3, ds, "y", 0, 2, evaluator, 1.0, 1.0);
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);
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);
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);
}
}
}