Changeset 5686 for branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs
- Timestamp:
- 03/15/11 13:34:38 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs
r5549 r5686 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Parameters; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Parameters;30 30 31 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 126 126 where node.SubTrees.Count() > 0 127 127 from subtree in node.SubTrees 128 select new { Parent = node, ReplacedChildIndex = node.IndexOfSubTree(subtree), ReplacedChild = subtree }).ToList();128 select new CutPoint(node, subtree)).ToList(); 129 129 130 130 if (cutPoints.Count() == 0) … … 133 133 var selectedCutPoint = cutPoints[random.Next(cutPoints.Count)]; 134 134 // replace the branch at the cut point with an argument node 135 var replacedBranch = selectedCutPoint. ReplacedChild;136 selectedCutPoint.Parent.RemoveSubTree(selectedCutPoint. ReplacedChildIndex);137 selectedCutPoint.Parent.InsertSubTree(selectedCutPoint. ReplacedChildIndex, newArgumentNode);135 var replacedBranch = selectedCutPoint.Child; 136 selectedCutPoint.Parent.RemoveSubTree(selectedCutPoint.ChildIndex); 137 selectedCutPoint.Parent.InsertSubTree(selectedCutPoint.ChildIndex, newArgumentNode); 138 138 139 139 // find all old invocations of the selected ADF and attach a cloned version of the replaced branch (with all argument-nodes expanded) … … 167 167 defunBranch.NumberOfArguments++; 168 168 defunBranch.Grammar.AddSymbol(newArgumentNode.Symbol); 169 defunBranch.Grammar.SetMinSubtreeCount(newArgumentNode.Symbol, 0); 170 defunBranch.Grammar.SetMaxSubtreeCount(newArgumentNode.Symbol, 0); 169 defunBranch.Grammar.SetSubtreeCount(newArgumentNode.Symbol, 0, 0); 171 170 // allow the argument as child of any other symbol 172 171 foreach (var symb in defunBranch.Grammar.Symbols) 173 for (int i = 0; i < defunBranch.Grammar.GetMax SubtreeCount(symb); i++) {174 defunBranch.Grammar. SetAllowedChild(symb, newArgumentNode.Symbol, i);172 for (int i = 0; i < defunBranch.Grammar.GetMaximumSubtreeCount(symb); i++) { 173 defunBranch.Grammar.AddAllowedChildSymbol(symb, newArgumentNode.Symbol, i); 175 174 } 176 175 foreach (var subtree in tree.Root.SubTrees) { … … 178 177 var matchingSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().Where(s => s.FunctionName == defunBranch.FunctionName).SingleOrDefault(); 179 178 if (matchingSymbol != null) { 180 subtree.Grammar.SetMinSubtreeCount(matchingSymbol, defunBranch.NumberOfArguments); 181 subtree.Grammar.SetMaxSubtreeCount(matchingSymbol, defunBranch.NumberOfArguments); 182 foreach (var child in subtree.Grammar.GetAllowedSymbols(subtree.Symbol, 0)) { 183 for (int i = 0; i < subtree.Grammar.GetMaxSubtreeCount(matchingSymbol); i++) { 184 subtree.Grammar.SetAllowedChild(matchingSymbol, child, i); 179 subtree.Grammar.SetSubtreeCount(matchingSymbol, defunBranch.NumberOfArguments, defunBranch.NumberOfArguments); 180 foreach (var child in subtree.Grammar.GetAllowedChildSymbols(subtree.Symbol, 0)) { 181 for (int i = 0; i < subtree.Grammar.GetMaximumSubtreeCount(matchingSymbol); i++) { 182 subtree.Grammar.AddAllowedChildSymbol(matchingSymbol, child, i); 185 183 } 186 184 }
Note: See TracChangeset
for help on using the changeset viewer.