Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/10/15 12:02:20 (9 years ago)
Author:
mkommend
Message:

#2320: Merged r12422, r12423, r12424, r12480, r12481 and r12482 into stable.

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDeleter.cs

    r12009 r12706  
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Random;
    2728
    2829namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    5455      int maxFunctionDefinitions, int maxFunctionArguments) {
    5556
    56       var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>();
    57       if (functionDefiningBranches.Count() == 0)
     57      var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList();
     58      if (!functionDefiningBranches.Any())
    5859        // no function defining branch => abort
    5960        return false;
    60       var selectedDefunBranch = functionDefiningBranches.SelectRandom(random);
     61
     62      var selectedDefunBranch = functionDefiningBranches.SampleRandom(random);
    6163      if (selectedDefunBranch.NumberOfArguments <= 1)
    6264        // argument deletion by consolidation is not possible => abort
     
    7779
    7880      // delete the dynamic argument symbol that matches the argument to be removed
    79       var matchingSymbol = selectedDefunBranch.Grammar.Symbols.OfType<Argument>().Where(s => s.ArgumentIndex == removedArgument).Single();
     81      var matchingSymbol = selectedDefunBranch.Grammar.Symbols.OfType<Argument>().Single(s => s.ArgumentIndex == removedArgument);
    8082      selectedDefunBranch.Grammar.RemoveSymbol(matchingSymbol);
    8183      selectedDefunBranch.NumberOfArguments--;
    8284      // reduce arity in known functions of all root branches
    8385      foreach (var subtree in symbolicExpressionTree.Root.Subtrees) {
    84         var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().Where(s => s.FunctionName == selectedDefunBranch.FunctionName).SingleOrDefault();
     86        var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().SingleOrDefault(s => s.FunctionName == selectedDefunBranch.FunctionName);
    8587        if (matchingInvokeSymbol != null) {
    8688          subtree.Grammar.SetSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments, selectedDefunBranch.NumberOfArguments);
     
    99101                     select node;
    100102      foreach (var argNode in argNodes) {
    101         var replacementSymbol = possibleArgumentSymbols.SelectRandom(random);
     103        var replacementSymbol = possibleArgumentSymbols.SampleRandom(random);
    102104        argNode.Symbol = replacementSymbol;
    103105      }
Note: See TracChangeset for help on using the changeset viewer.