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/BreathFirstMapper.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) {
     
    8788
    8889      int genotypeIndex = 0;
    89       int currSubtreeCount = 1;
    90 
    9190      queue.Enqueue(new Tuple<ISymbolicExpressionTreeNode, int>(startNode, 1));
    9291
    93       while ((currSubtreeCount < maxSubtreeCount) && (queue.Count > 0)) {
     92      while (queue.Count > 0) {
    9493
    9594        Tuple<ISymbolicExpressionTreeNode, int> current = queue.Dequeue();
     
    9897        for (int i = 0; i < current.Item2; ++i) {
    9998
    100           var newNode = GetNewChildNode(current.Item1, genotype, grammar, genotypeIndex, random);
    101           int arity = SampleArity(random, newNode, maxSubtreeCount - currSubtreeCount, grammar);
    102 
    103           if (arity < 0) {
     99          if (genotypeIndex >= maxSubtreeCount) {
     100            // if all genomes were used, only add terminal nodes to the remaining subtrees
    104101            current.Item1.AddSubtree(GetRandomTerminalNode(current.Item1, grammar, random));
    105102          } else {
     103            var newNode = GetNewChildNode(current.Item1, genotype, grammar, genotypeIndex, random);
     104            int arity = SampleArity(random, newNode, grammar);
     105
    106106            current.Item1.AddSubtree(newNode);
    107107            genotypeIndex++;
    108             currSubtreeCount += arity;
    109108            if (arity > 0) {
    110109              // new node has subtrees so enqueue the node
     
    114113        }
    115114      }
    116 
    117       // maximum allowed subtree count was already reached, but there are still
    118       // incomplete subtrees (non-terminal symbols) in the tree
    119       // -> fill them with terminal symbols
    120       while (queue.Count > 0) {
    121         Tuple<ISymbolicExpressionTreeNode, int> current = queue.Dequeue();
    122         for (int i = 0; i < current.Item2; ++i) {
    123           current.Item1.AddSubtree(GetRandomTerminalNode(current.Item1, grammar, random));
    124         }
    125       }
    126115    }
    127116  }
Note: See TracChangeset for help on using the changeset viewer.