- Timestamp:
- 12/03/10 14:11:02 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SubtreeCrossover.cs
r4722 r5014 66 66 SymbolicExpressionTreeNode crossoverPoint0; 67 67 int replacedSubtreeIndex; 68 SelectCrossoverPoint(random, parent0, internalCrossoverPointProbability, maxTreeSize - 1, maxTreeHeight - 1, out crossoverPoint0, out replacedSubtreeIndex);68 SelectCrossoverPoint(random, parent0, internalCrossoverPointProbability, maxTreeSize, maxTreeHeight, out crossoverPoint0, out replacedSubtreeIndex); 69 69 70 70 // calculate the max size and height that the inserted branch can have -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/ReplaceBranchManipulation.cs
r4722 r5014 53 53 from subtree in parent.SubTrees 54 54 select new { Parent = parent, Node = subtree, Index = parent.SubTrees.IndexOf(subtree) }).SelectRandom(random); 55 56 int maxSize = maxTreeSize - symbolicExpressionTree.Size + manipulationPoint.Node.GetSize(); 57 int maxHeight = maxTreeHeight - symbolicExpressionTree.Height + manipulationPoint.Node.GetHeight(); 55 58 // find possible symbols for the node (also considering the existing branches below it) 56 var allowedSymbols = from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index )59 var allowedSymbols = from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index, maxHeight) 57 60 select symbol; 61 if (allowedSymbols.Count() <= 1) return; 58 62 59 if (allowedSymbols.Count() <= 1) { 60 return; 61 } 62 var oldBranch = manipulationPoint.Node; 63 int oldBranchSize = manipulationPoint.Node.GetSize(); 64 65 var seedSymbol = SelectRandomSymbol(random, allowedSymbols); 66 67 // replace the old node with the new node 63 var seedSymbol = SelectRandomSymbol(random, allowedSymbols); // replace the old node with the new node 68 64 var seedNode = seedSymbol.CreateTreeNode(); 69 65 if (seedNode.HasLocalParameters) … … 72 68 manipulationPoint.Parent.RemoveSubTree(manipulationPoint.Index); 73 69 manipulationPoint.Parent.InsertSubTree(manipulationPoint.Index, seedNode); 74 int maxSize = Math.Max(oldBranchSize, seedNode.Grammar.GetMinExpressionLength(seedNode.Symbol)) * 2; 75 var bla = ProbabilisticTreeCreator.PTC2(random, seedNode, maxSize, maxSize, 0, 0); 70 seedNode = ProbabilisticTreeCreator.PTC2(random, seedNode, maxSize, maxHeight, 0, 0); 76 71 success = true; 77 72 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs
r4722 r5014 178 178 return Grammar.Symbols.Where(s => Grammar.IsAllowedChild(Symbol, s, argumentIndex)); 179 179 } 180 public IEnumerable<Symbol> GetAllowedSymbols(int argumentIndex, int maxExpressionDepth) { 181 return Grammar.Symbols.Where(s => Grammar.IsAllowedChild(Symbol, s, argumentIndex) && Grammar.GetMinExpressionDepth(s) <= maxExpressionDepth); 182 } 183 180 184 public int GetMinSubtreeCount() { 181 185 return Grammar.GetMinSubtreeCount(Symbol);
Note: See TracChangeset
for help on using the changeset viewer.