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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/ArgumentDuplicater.cs

    r4068 r4106  
    2525using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using System.Collections.Generic;
    2728
    2829namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators {
     
    8081      var invocationNodes = from node in symbolicExpressionTree.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>()
    8182                            where node.Symbol.FunctionName == selectedDefunBranch.FunctionName
     83                            where node.SubTrees.Count == selectedDefunBranch.NumberOfArguments
    8284                            select node;
    83       foreach (var invokeNode in invocationNodes) {
    84         var argumentBranch = invokeNode.SubTrees[selectedArgumentSymbol.ArgumentIndex];
    85         var clonedArgumentBranch = (SymbolicExpressionTreeNode)argumentBranch.Clone();
    86         invokeNode.InsertSubTree(newArgumentIndex, clonedArgumentBranch);
     85      // do this repeatedly until no matching invocations are found     
     86      while (invocationNodes.Count() > 0) {
     87        List<SymbolicExpressionTreeNode> newlyAddedBranches = new List<SymbolicExpressionTreeNode>();
     88        foreach (var invokeNode in invocationNodes) {
     89          var argumentBranch = invokeNode.SubTrees[selectedArgumentSymbol.ArgumentIndex];
     90          var clonedArgumentBranch = (SymbolicExpressionTreeNode)argumentBranch.Clone();
     91          invokeNode.InsertSubTree(newArgumentIndex, clonedArgumentBranch);
     92          newlyAddedBranches.Add(clonedArgumentBranch);
     93        }
     94        invocationNodes = from newlyAddedBranch in newlyAddedBranches
     95                          from node in newlyAddedBranch.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>()
     96                          where node.Symbol.FunctionName == selectedDefunBranch.FunctionName
     97                          where node.SubTrees.Count == selectedDefunBranch.NumberOfArguments
     98                          select node;
    8799      }
    88100      // register the new argument symbol and increase the number of arguments of the ADF
Note: See TracChangeset for help on using the changeset viewer.