Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/22/11 15:07:20 (14 years ago)
Author:
mkommend
Message:

#1418: Corrected ADFs and adapted unit tests.

Location:
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests
Files:
3 edited

Legend:

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

    r5759 r5792  
    3232  public class AllArchitectureAlteringOperatorsTest {
    3333    private const int POPULATION_SIZE = 1000;
    34     private const int N_ITERATIONS = 100;
     34    private const int N_ITERATIONS = 200;
    3535    private const int MAX_TREE_LENGTH = 100;
    3636    private const int MAX_TREE_DEPTH = 10;
     
    9999              par1 = (SymbolicExpressionTree)trees.SelectRandom(random).Clone();
    100100            } while (par0.Length > MAX_TREE_LENGTH || par1.Length > MAX_TREE_LENGTH);
    101             newTrees.Add(SubtreeCrossover.Cross(random, par0, par1, 0.9, MAX_TREE_LENGTH, MAX_TREE_DEPTH));
     101            var newTree = SubtreeCrossover.Cross(random, par0, par1, 0.9, MAX_TREE_LENGTH, MAX_TREE_DEPTH);
     102            Util.IsValid(newTree);
     103            newTrees.Add(newTree);
    102104          }
    103105        }
    104         trees = newTrees;
     106        trees = new List<ISymbolicExpressionTree>(newTrees);
     107        newTrees.Clear();
    105108      }
    106109      var msPerOperation = stopwatch.ElapsedMilliseconds / (double)POPULATION_SIZE / (double)N_ITERATIONS;
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/SubtreeCrossoverTest.cs

    r5733 r5792  
    5252      var grammar = Grammars.CreateArithmeticAndAdfGrammar();
    5353      var random = new MersenneTwister(31415);
    54       List<ISymbolicExpressionTree> crossoverTrees;
    5554      double msPerCrossoverEvent;
    5655
     
    6362      stopwatch.Start();
    6463      for (int gCount = 0; gCount < generations; gCount++) {
    65         var newPopulation = new List<ISymbolicExpressionTree>();
    6664        for (int i = 0; i < POPULATION_SIZE; i++) {
    67           var par0 = (SymbolicExpressionTree)trees.SelectRandom(random).Clone();
    68           var par1 = (SymbolicExpressionTree)trees.SelectRandom(random).Clone();
    69           newPopulation.Add(SubtreeCrossover.Cross(random, par0, par1, 0.9, 100, 10));
     65          var par0 = (ISymbolicExpressionTree)trees.SelectRandom(random).Clone();
     66          var par1 = (ISymbolicExpressionTree)trees.SelectRandom(random).Clone();
     67          SubtreeCrossover.Cross(random, par0, par1, 0.9, 100, 10);
    7068        }
    71         crossoverTrees = newPopulation;
    7269      }
    7370      stopwatch.Stop();
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Tests/Util.cs

    r5733 r5792  
    141141
    142142      }
     143
    143144      foreach (var subtree in tree.Root.Subtrees) {
    144145        Assert.AreNotSame(subtree.Grammar, tree.Root.Grammar);
     
    159160        }
    160161      }
     162
     163      foreach (var symbol in grammar.ModifyableSymbols) {
     164        //check if ever symbol has at least on
     165        for (int i = 0; i < grammar.GetMaximumSubtreeCount(symbol); i++)
     166          Assert.IsTrue(grammar.GetAllowedChildSymbols(symbol, i).Any());
     167
     168        //if (symbol is ProgramRootSymbol) continue;
     169        ////check if symbol is allowed as at least one child symbol
     170        //bool result = false;
     171        //foreach (var parentSymbol in grammar.Symbols) {
     172        //  if (result) break;
     173        //  for (int i = 0; i < grammar.GetMaximumSubtreeCount(parentSymbol); i++)
     174        //    result = result || grammar.IsAllowedChildSymbol(parentSymbol, symbol, i);
     175        //}
     176        //Assert.IsTrue(result);
     177
     178      }
    161179    }
    162180
Note: See TracChangeset for help on using the changeset viewer.