Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/26/10 16:18:45 (14 years ago)
Author:
gkronber
Message:

Fixed bugs in SubtreeCrossover, ArgumentCreater and ArgumentDuplicater and updated unit tests for symbolic expression tree operators. #1103

Location:
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/Grammars.cs

    r4068 r4106  
    2626namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
    2727  public static class Grammars {
    28     private class Addition : Symbol { }
    29     private class Subtraction : Symbol { }
    30     private class Multiplication : Symbol { }
    31     private class Division : Symbol { }
    32     private class Terminal : Symbol { }
     28    private class Addition : Symbol { public Addition() : base("Addition", "") { } }
     29    private class Subtraction : Symbol { public Subtraction() : base("Subtraction", "") { } }
     30    private class Multiplication : Symbol { public Multiplication() : base("Multiplication", "") { } }
     31    private class Division : Symbol { public Division() : base("Division", "") { } }
     32    private class Terminal : Symbol { public Terminal() : base("Terminal", "") { } }
    3333
    3434    private class SimpleArithmeticGrammar : DefaultSymbolicExpressionGrammar {
     
    8989      return g;
    9090    }
    91 
    92     public static void HasValidAdfGrammars(SymbolicExpressionTree tree) {
    93       //Assert.AreEqual(tree.Root.Grammar.Symbols.Count(), 8);
    94       //Assert.AreEqual(tree.Root.GetAllowedSymbols(0).Count(), 1); // only the start symbol is allowed
    95       //// we allow 3 ADF branches
    96       //Assert.AreEqual(tree.Root.GetAllowedSymbols(1).Count(), 1); // only the defun branch is allowed
    97       //Assert.AreEqual(tree.Root.GetAllowedSymbols(2).Count(), 1); // only the defun symbol is allowed
    98       //Assert.AreEqual(tree.Root.GetAllowedSymbols(3).Count(), 1); // only the defun symbol is allowed
    99       //foreach (var subtree in tree.Root.SubTrees) {
    100       //  // check consistency of each sub-tree grammar independently
    101       //  var allowedSymbols = subtree.GetAllowedSymbols(0);
    102       //  int numberOfAllowedSymbols = allowedSymbols.Count();
    103       //  foreach (var parent in allowedSymbols) {
    104       //    for (int argIndex = 0; argIndex < subtree.Grammar.GetMaxSubtreeCount(parent); argIndex++) {
    105       //      var allowedChildren = from child in subtree.Grammar.Symbols
    106       //                            where subtree.Grammar.IsAllowedChild(parent, child, argIndex)
    107       //                            select child;
    108       //      Assert.AreEqual(numberOfAllowedSymbols, allowedChildren.Count());
    109       //    }
    110       //  }
    111       //}
    112     }
    113 
    11491  }
    11592}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ProbabilisticTreeCreaterTest.cs

    r4068 r4106  
    7676      for (int i = 0; i < POPULATION_SIZE; i++) {
    7777        var tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3);
    78         Grammars.HasValidAdfGrammars(tree);
    7978        Util.IsValid(tree);
    8079        randomTrees.Add(tree);
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/Util.cs

    r4068 r4106  
    2626using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2727using Microsoft.VisualStudio.TestTools.UnitTesting;
     28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2829
    2930namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
     
    114115
    115116    public static void IsValid(SymbolicExpressionTree tree) {
    116       Grammars.HasValidAdfGrammars(tree);
     117      foreach (var defunTreeNode in tree.Root.SubTrees.OfType<DefunTreeNode>()) {
     118        int arity = defunTreeNode.NumberOfArguments;
     119        var invoke = new InvokeFunction(defunTreeNode.FunctionName);
     120        foreach (var otherRootNode in tree.Root.SubTrees) {
     121          if (otherRootNode.Grammar.ContainsSymbol(invoke)) {
     122            Assert.IsTrue(otherRootNode.Grammar.GetMinSubtreeCount(invoke) == arity);
     123            Assert.IsTrue(otherRootNode.Grammar.GetMaxSubtreeCount(invoke) == arity);
     124          }
     125        }
     126      }
    117127      //Assert.AreEqual(tree.Root.Symbol, tree.Root.Grammar.StartSymbol);
    118128      //foreach (var subtree in tree.Root.SubTrees)
     
    122132
    123133    public static void IsValid(SymbolicExpressionTreeNode treeNode) {
    124       //var matchingSymbol = (from symb in treeNode.Grammar.Symbols
    125       //                      where symb.Name == treeNode.Symbol.Name
    126       //                      select symb).SingleOrDefault();
    127       //Assert.IsTrue(treeNode.SubTrees.Count >= treeNode.Grammar.GetMinSubtreeCount(matchingSymbol));
    128       //Assert.IsTrue(treeNode.SubTrees.Count <= treeNode.Grammar.GetMaxSubtreeCount(matchingSymbol));
     134      var matchingSymbol = (from symb in treeNode.Grammar.Symbols
     135                            where symb.Name == treeNode.Symbol.Name
     136                            select symb).SingleOrDefault();
     137      Assert.IsTrue(treeNode.SubTrees.Count >= treeNode.Grammar.GetMinSubtreeCount(matchingSymbol));
     138      Assert.IsTrue(treeNode.SubTrees.Count <= treeNode.Grammar.GetMaxSubtreeCount(matchingSymbol));
    129139      for (int i = 0; i < treeNode.SubTrees.Count; i++) {
    130140        Assert.IsTrue(treeNode.GetAllowedSymbols(i).Select(x => x.Name).Contains(treeNode.SubTrees[i].Symbol.Name));
Note: See TracChangeset for help on using the changeset viewer.