Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/13/10 20:44:31 (14 years ago)
Author:
gkronber
Message:

Fixed bugs related to dynamic symbol constraints with ADFs. #290 (Implement ADFs)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDuplicater.cs

    r3294 r3338  
    6565        // no function defining branches to duplicate or already reached the max number of ADFs
    6666        return false;
    67       var selectedBranch = (DefunTreeNode)SelectRandomBranch(random, functionDefiningBranches);
     67      var selectedBranch = functionDefiningBranches.SelectRandom(random);
    6868      var clonedBranch = (DefunTreeNode)selectedBranch.Clone();
    6969      clonedBranch.Name = allowedFunctionNames.Except(UsedFunctionNames(symbolicExpressionTree)).First();
     
    7373        if (invokeFunctionNode != null && invokeFunctionNode.InvokedFunctionName == selectedBranch.Name) {
    7474          // add the new function name to the list of known functions in the branches that used the originating function
    75           var branch = FindDefiningBranch(symbolicExpressionTree, invokeFunctionNode);
     75          var branch = symbolicExpressionTree.GetTopLevelBranchOf(invokeFunctionNode);
    7676          branch.AddDynamicSymbol(clonedBranch.Name, clonedBranch.NumberOfArguments);
    7777          // flip coin wether to replace with newly defined function
     
    8383      Debug.Assert(grammar.IsValidExpression(symbolicExpressionTree));
    8484      return true;
    85     }
    86 
    87     private static SymbolicExpressionTreeNode FindDefiningBranch(SymbolicExpressionTree tree, SymbolicExpressionTreeNode node) {
    88       foreach (var subtree in tree.Root.SubTrees) {
    89         if (ContainsNode(subtree, node)) return subtree;
    90       }
    91       return null;
    9285    }
    9386
     
    10699    }
    107100
    108     private static SymbolicExpressionTreeNode SelectRandomBranch(IRandom random, IEnumerable<DefunTreeNode> branches) {
    109       var list = branches.ToList();
    110       return list[random.Next(list.Count)];
    111     }
     101
    112102  }
    113103}
Note: See TracChangeset for help on using the changeset viewer.