Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/06/14 20:41:57 (10 years ago)
Author:
sawinkle
Message:

#2109:

  • Implemented PIGEMapper. Due to that, it was necessary to modify the Map method interface to additionally take the bounds and length of the genotype.
  • Corrected and simplified the different mappers. Simplified the SampleArity method of /Mappers/GenotypeToPhenotypeMapper.cs
File:
1 edited

Legend:

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

    r10280 r10290  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Data;
    2627using HeuristicLab.Encodings.IntegerVectorEncoding;
    2728using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    5455    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
    5556    /// <returns>phenotype (a symbolic expression tree)</returns>
    56     public override SymbolicExpressionTree Map(IRandom random,
     57    public override SymbolicExpressionTree Map(IRandom random, IntMatrix bounds, int length,
    5758                                               ISymbolicExpressionGrammar grammar,
    5859                                               IntegerVector genotype) {
     
    8990
    9091      int genotypeIndex = 0;
    91       int currSubtreeCount = 1;
    92 
    9392      stack.Push(new Tuple<ISymbolicExpressionTreeNode, int>(startNode, 1));
    9493
    95       while ((currSubtreeCount < maxSubtreeCount) && (stack.Count > 0)) {
     94      while (stack.Count > 0) {
    9695
    9796        // get next node from stack and re-push it, if this node still has unhandled subtrees ...
     
    101100        }
    102101
    103         var newNode = GetNewChildNode(current.Item1, genotype, grammar, genotypeIndex, random);
    104         int arity = SampleArity(random, newNode, maxSubtreeCount - currSubtreeCount, grammar);
    105 
    106         if (arity < 0) {
     102        if (genotypeIndex >= maxSubtreeCount) {
     103          // if all genomes were used, only add terminal nodes to the remaining subtrees
    107104          current.Item1.AddSubtree(GetRandomTerminalNode(current.Item1, grammar, random));
    108105        } else {
     106          var newNode = GetNewChildNode(current.Item1, genotype, grammar, genotypeIndex, random);
     107          int arity = SampleArity(random, newNode, grammar);
     108
    109109          current.Item1.AddSubtree(newNode);
    110110          genotypeIndex++;
    111           currSubtreeCount += arity;
    112111          if (arity > 0) {
    113112            // new node has subtrees so push it onto the stack
     
    116115        }
    117116      }
    118 
    119       // maximum allowed subtree count was already reached, but there are still
    120       // incomplete subtrees (non-terminal symbols) in the tree
    121       // -> fill them with terminal symbols
    122       while (stack.Count > 0) {
    123         Tuple<ISymbolicExpressionTreeNode, int> current = stack.Pop();
    124         if (current.Item2 > 1) {
    125           stack.Push(new Tuple<ISymbolicExpressionTreeNode, int>(current.Item1, current.Item2 - 1));
    126         }
    127         current.Item1.AddSubtree(GetRandomTerminalNode(current.Item1, grammar, random));
    128       }
    129117    }
    130118  }
Note: See TracChangeset for help on using the changeset viewer.