Changeset 10290 for branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/BreathFirstMapper.cs
- Timestamp:
- 01/06/14 20:41:57 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/BreathFirstMapper.cs
r10280 r10290 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Encodings.IntegerVectorEncoding; 27 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 54 55 /// <param name="genotype">integer vector, which should be mapped to a tree</param> 55 56 /// <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, 57 58 ISymbolicExpressionGrammar grammar, 58 59 IntegerVector genotype) { … … 87 88 88 89 int genotypeIndex = 0; 89 int currSubtreeCount = 1;90 91 90 queue.Enqueue(new Tuple<ISymbolicExpressionTreeNode, int>(startNode, 1)); 92 91 93 while ( (currSubtreeCount < maxSubtreeCount) && (queue.Count > 0)) {92 while (queue.Count > 0) { 94 93 95 94 Tuple<ISymbolicExpressionTreeNode, int> current = queue.Dequeue(); … … 98 97 for (int i = 0; i < current.Item2; ++i) { 99 98 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 104 101 current.Item1.AddSubtree(GetRandomTerminalNode(current.Item1, grammar, random)); 105 102 } else { 103 var newNode = GetNewChildNode(current.Item1, genotype, grammar, genotypeIndex, random); 104 int arity = SampleArity(random, newNode, grammar); 105 106 106 current.Item1.AddSubtree(newNode); 107 107 genotypeIndex++; 108 currSubtreeCount += arity;109 108 if (arity > 0) { 110 109 // new node has subtrees so enqueue the node … … 114 113 } 115 114 } 116 117 // maximum allowed subtree count was already reached, but there are still118 // incomplete subtrees (non-terminal symbols) in the tree119 // -> fill them with terminal symbols120 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 }126 115 } 127 116 }
Note: See TracChangeset
for help on using the changeset viewer.