Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/07/13 21:04:53 (11 years ago)
Author:
sawinkle
Message:

#2109: added additional documentation and refactored code of GEEvaluator.cs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/GEEvaluator.cs

    r10022 r10029  
    4040    ISingleObjectiveEvaluator, ISymbolicExpressionTreeGrammarBasedOperator {
    4141
    42     // TODO: replace these horrible global variables ...
    43     private static int genotypeIndex    = 0;
    44     private static int currSubtreeCount = 1;
    45    
    4642    #region Parameter Properties
    4743    public ILookupParameter<DoubleValue> QualityParameter {
     
    9692   
    9793    /// <summary>
    98     /// Genotype-to-Phenotype mapper (depth-first approach).
     94    /// Maps an integer vector to a symbolic expression tree, using a
     95    /// genotype-to-phenotype mapper.
    9996    /// </summary>
    10097    /// <returns>solution tree</returns>
     
    109106      tree.Root = rootNode;
    110107     
    111       genotypeIndex    = 0;
    112       currSubtreeCount = 1;
     108      int genotypeIndex    = 0;
     109      int currSubtreeCount = 1;
    113110     
    114111      MapGenoToPhenoDepthFirstRec(startNode, integerVectorGenome,
    115                                   grammar, integerVectorGenome.Length);
     112                                  grammar, integerVectorGenome.Length,
     113                                  ref genotypeIndex, ref currSubtreeCount);
    116114     
    117115      SymbolicExpressionTreeParameter.ActualValue = tree;
     
    120118   
    121119   
     120    /// <summary>
     121    /// Genotype-to-Phenotype mapper (recursive depth-first approach).
     122    /// Appends maximum allowed children (non-terminal symbols) to
     123    /// <paramref name="currentNode"/>, as long as <paramref name="currSubtreeCount"/>
     124    /// doesn't exceed <paramref name="maxSubtreeCount"/>.
     125    /// If at most <paramref name="maxSubtreeCount"/> subtrees were created,
     126    /// each non-full node is filled with randomly chosen nodes
     127    /// (non-terminal and terminal), and each non-terminal node is again filled with a terminal node.
     128    /// </summary>
     129    /// <param name="currentNode">current parent node</param>
     130    /// <param name="integerVectorGenome">integer vector used for mapping</param>
     131    /// <param name="grammar">grammar definition to determine the allowed child symbols for currentNode </param>
     132    /// <param name="maxSubtreeCount">maximum allowed subtrees (= number of used genomes)</param>
     133    /// <param name="genotypeIndex">current index in integer vector</param>
     134    /// <param name="currSubtreeCount">number of already determined subtrees (filled or still incomplete)</param>
    122135    private void MapGenoToPhenoDepthFirstRec(ISymbolicExpressionTreeNode currentNode,
    123136                                             IntegerVector integerVectorGenome,
    124137                                             ISymbolicExpressionGrammar grammar,
    125                                              int maxSubtreeCount) {
     138                                             int maxSubtreeCount,
     139                                             ref int genotypeIndex,
     140                                             ref int currSubtreeCount) {
    126141      if (currSubtreeCount < maxSubtreeCount) {
    127142     
     
    138153          while (newNode.Symbol.MaximumArity > newNode.SubtreeCount) {
    139154            MapGenoToPhenoDepthFirstRec(newNode, integerVectorGenome,
    140                                         grammar, maxSubtreeCount);
     155                                        grammar, maxSubtreeCount,
     156                                        ref genotypeIndex, ref currSubtreeCount);
    141157          }
    142158        }
     
    156172   
    157173    /// <summary>
    158     /// Randomly returns a terminal node for the given parentNode.
     174    /// Randomly returns a terminal node for the given <paramref name="parentNode"/>.
    159175    /// (A terminal has got a minimum and maximum arity of 0.)
    160176    /// </summary>
     
    174190   
    175191    /// <summary>
    176     /// Utility method, which returns the number of elements of the parameter symbolList.
     192    /// Utility method, which returns the number of elements of <paramref name="symbolList"/>.
    177193    /// </summary>
    178194    /// <param name="symbolList">enumerable symbol list to count the elements for</param>
     
    190206   
    191207    /// <summary>
    192     /// Returns a randomly chosen child node for the given parentNode.
     208    /// Returns a randomly chosen child node for the given <paramref name="parentNode"/>.
    193209    /// </summary>
    194210    /// <param name="parentNode">parent node to find a child node randomly for</param>
     
    204220      var symbolList    = grammar.GetAllowedChildSymbols(parentNode.Symbol);
    205221      int prodRuleCount = GetNumberOfAllowedChildSymbols(symbolList);
    206       int prodRuleIndex = integerVectorGenome[genotypeIndex] % prodRuleCount;
     222      int prodRuleIndex = integerVectorGenome[genotypeIndex % integerVectorGenome.Length] % prodRuleCount;
    207223      int currentIndex  = 0;
    208224     
Note: See TracChangeset for help on using the changeset viewer.