Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/04/14 12:23:59 (9 years ago)
Author:
sawinkle
Message:

#2109:
Refactoring:

  • Removed recursive version of mapping in /Mappers/DepthFirstMapper.cs, because only the iterative one is used.
  • Removed unused using statements and unused commented code.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/DepthFirstMapper.cs

    r10229 r10276  
    6565      tree.Root = rootNode;
    6666
    67       //int genotypeIndex = 0;
    68       //int currSubtreeCount = 1;
    69       //MapDepthFirstRecursively(startNode, genotype,
    70       //                         grammar, genotype.Length,
    71       //                         ref genotypeIndex, ref currSubtreeCount,
    72       //                         new MersenneTwister());
    73 
    7467      MapDepthFirstIteratively(startNode, genotype, grammar,
    7568                               genotype.Length, new MersenneTwister());
    7669      return tree;
    77     }
    78 
    79 
    80     /// <summary>
    81     /// Genotype-to-Phenotype mapper (recursive depth-first approach).
    82     /// Appends maximum allowed children (non-terminal symbols) to
    83     /// <paramref name="currentNode"/>, as long as <paramref name="currSubtreeCount"/>
    84     /// doesn't exceed <paramref name="maxSubtreeCount"/>.
    85     /// If at most <paramref name="maxSubtreeCount"/> subtrees were created,
    86     /// each non-full node is filled with randomly chosen nodes
    87     /// (non-terminal and terminal), and each non-terminal node is again filled with a terminal node.
    88     /// </summary>
    89     /// <param name="currentNode">current parent node</param>
    90     /// <param name="genotype">integer vector, which should be mapped to a tree</param>
    91     /// <param name="grammar">grammar to determine the allowed child symbols for currentNode </param>
    92     /// <param name="maxSubtreeCount">maximum allowed subtrees (= number of used genomes)</param>
    93     /// <param name="genotypeIndex">current index in integer vector</param>
    94     /// <param name="currSubtreeCount">number of already determined subtrees (filled or still incomplete)</param>
    95     private void MapDepthFirstRecursively(ISymbolicExpressionTreeNode currentNode,
    96                                           IntegerVector genotype,
    97                                           ISymbolicExpressionGrammar grammar,
    98                                           int maxSubtreeCount,
    99                                           ref int genotypeIndex,
    100                                           ref int currSubtreeCount,
    101                                           IRandom random) {
    102 
    103       // TODO: check, if method calls of GetNewChildNode() and GetRandomTerminalNode() don't return null
    104       if (currSubtreeCount < maxSubtreeCount) {
    105 
    106         var newNode = GetNewChildNode(currentNode, genotype, grammar, genotypeIndex, random);
    107 
    108         if ((currSubtreeCount + newNode.Symbol.MinimumArity) > maxSubtreeCount) {
    109           // TODO: maybe check, if there is any node, which fits in the tree yet
    110           currentNode.AddSubtree(GetRandomTerminalNode(currentNode, grammar, random));
    111         } else {
    112           currentNode.AddSubtree(newNode);
    113           genotypeIndex++;
    114           currSubtreeCount += newNode.Symbol.MinimumArity;
    115 
    116           while (newNode.Symbol.MinimumArity > newNode.SubtreeCount) {
    117             MapDepthFirstRecursively(newNode, genotype,
    118                                      grammar, maxSubtreeCount,
    119                                      ref genotypeIndex, ref currSubtreeCount, random);
    120           }
    121         }
    122 
    123       } else {
    124         while (currentNode.Symbol.MinimumArity > currentNode.SubtreeCount) {
    125           var newNode = GetNewChildNode(currentNode, genotype, grammar, genotypeIndex, random);
    126           currentNode.AddSubtree(newNode);
    127           genotypeIndex++;
    128           while (newNode.Symbol.MinimumArity > newNode.SubtreeCount) {
    129             newNode.AddSubtree(GetRandomTerminalNode(newNode, grammar, random));
    130           }
    131         }
    132       }
    13370    }
    13471
Note: See TracChangeset for help on using the changeset viewer.