Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/22/11 19:04:54 (14 years ago)
Author:
gkronber
Message:

#1418 unified size/height vs. length/depth terminology and adapted unit tests for symbolic expression tree encoding version 3.4

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/AllArchitectureAlteringOperatorsTest.cs

    r5445 r5549  
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators;
    28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers;
    3027using HeuristicLab.Random;
    3128using Microsoft.VisualStudio.TestTools.UnitTesting;
    3229
    33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
     30namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._4.Tests {
    3431  [TestClass]
    3532  public class AllArchitectureAlteringOperatorsTest {
    3633    private const int POPULATION_SIZE = 1000;
    3734    private const int N_ITERATIONS = 20;
    38     private const int MAX_TREE_SIZE = 100;
    39     private const int MAX_TREE_HEIGHT = 10;
     35    private const int MAX_TREE_LENGTH = 100;
     36    private const int MAX_TREE_DEPTH = 10;
    4037    private TestContext testContextInstance;
    4138
     
    5552    [TestMethod()]
    5653    public void AllArchitectureAlteringOperatorsDistributionTest() {
    57       var trees = new List<SymbolicExpressionTree>();
    58       var newTrees = new List<SymbolicExpressionTree>();
     54      var trees = new List<ISymbolicExpressionTree>();
     55      var newTrees = new List<ISymbolicExpressionTree>();
    5956      var grammar = Grammars.CreateArithmeticAndAdfGrammar();
    6057      var random = new MersenneTwister(31415);
    61       IntValue maxTreeSize = new IntValue(MAX_TREE_SIZE);
    62       IntValue maxTreeHeigth = new IntValue(MAX_TREE_HEIGHT);
     58      IntValue maxTreeSize = new IntValue(MAX_TREE_LENGTH);
     59      IntValue maxTreeHeigth = new IntValue(MAX_TREE_DEPTH);
    6360      IntValue maxDefuns = new IntValue(3);
    6461      IntValue maxArgs = new IntValue(3);
    6562      for (int i = 0; i < POPULATION_SIZE; i++) {
    66         var tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3);
     63        var tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_LENGTH, MAX_TREE_DEPTH, 3, 3);
    6764        Util.IsValid(tree);
    6865        trees.Add(tree);
     
    7067      Stopwatch stopwatch = new Stopwatch();
    7168      stopwatch.Start();
    72       var combinedAAOperator = new MultiSymbolicExpressionTreeArchitectureManipulator();
    7369      int failedEvents = 0;
    7470      for (int g = 0; g < N_ITERATIONS; g++) {
     
    7672          if (random.NextDouble() < 0.5) {
    7773            // manipulate
    78             var selectedTree = (SymbolicExpressionTree)trees.SelectRandom(random).Clone();
    79             var op = combinedAAOperator.Operators.SelectRandom(random);
     74            var selectedTree = (ISymbolicExpressionTree)trees.SelectRandom(random).Clone();
    8075            bool success = false;
    81             op.ModifyArchitecture(random, selectedTree, grammar, maxTreeSize, maxTreeHeigth, maxDefuns, maxArgs, out success);
    82             if (!success) failedEvents++; // architecture manipulation might fail
     76            switch (random.Next(6)) {
     77              case 0: success = ArgumentCreater.CreateNewArgument(random, selectedTree, MAX_TREE_LENGTH, MAX_TREE_DEPTH, 3, 3); break;
     78              case 1: success = ArgumentDeleter.DeleteArgument(random, selectedTree, 3, 3); break;
     79              case 2: success = ArgumentDuplicater.DuplicateArgument(random, selectedTree, 3, 3); break;
     80              case 3: success = SubroutineCreater.CreateSubroutine(random, selectedTree, MAX_TREE_LENGTH, MAX_TREE_DEPTH, 3, 3); break;
     81              case 4: success = SubroutineDuplicater.DuplicateSubroutine(random, selectedTree, 3, 3); break;
     82              case 5: success = SubroutineDeleter.DeleteSubroutine(random, selectedTree, 3, 3); break;
     83            }
     84            if (!success) failedEvents++;
    8385            Util.IsValid(selectedTree);
    8486            newTrees.Add(selectedTree);
     
    9092              par0 = (SymbolicExpressionTree)trees.SelectRandom(random).Clone();
    9193              par1 = (SymbolicExpressionTree)trees.SelectRandom(random).Clone();
    92             } while (par0.Size > MAX_TREE_SIZE || par1.Size > MAX_TREE_SIZE);
    93             bool success;
    94             newTrees.Add(SubtreeCrossover.Cross(random, par0, par1, 0.9, MAX_TREE_SIZE, MAX_TREE_HEIGHT, out success));
    95             Assert.IsTrue(success); // crossover must succeed
     94            } while (par0.Length > MAX_TREE_LENGTH || par1.Length > MAX_TREE_LENGTH);
     95            newTrees.Add(SubtreeCrossover.Cross(random, par0, par1, 0.9, MAX_TREE_LENGTH, MAX_TREE_DEPTH));
    9696          }
    9797        }
Note: See TracChangeset for help on using the changeset viewer.