Changeset 5792 for branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators
- Timestamp:
- 03/22/11 15:07:20 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs
r5733 r5792 124 124 // the branch at the cut point is to be replaced by a new argument node 125 125 var cutPoints = (from node in defunBranch.IterateNodesPrefix() 126 where node.Subtrees.Count() > 0 126 where node.Subtrees.Count() > 0 && 127 !node.IterateNodesPrefix().OfType<ArgumentTreeNode>().Any() && 128 !node.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>().Any() 127 129 from subtree in node.Subtrees 128 130 select new CutPoint(node, subtree)).ToList(); … … 169 171 defunBranch.Grammar.SetSubtreeCount(newArgumentNode.Symbol, 0, 0); 170 172 // allow the argument as child of any other symbol 171 foreach (var symb in defunBranch.Grammar.Symbols) 172 for (int i = 0; i < defunBranch.Grammar.GetMaximumSubtreeCount(symb); i++) { 173 defunBranch.Grammar.AddAllowedChildSymbol(symb, newArgumentNode.Symbol, i); 174 } 173 GrammarModifier.SetAllowedParentSymbols(defunBranch.Grammar, selectedCutPoint.Child.Symbol, newArgumentNode.Symbol); 174 175 175 foreach (var subtree in tree.Root.Subtrees) { 176 176 // when the changed function is known in the branch then update the number of arguments … … 178 178 if (matchingSymbol != null) { 179 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);183 }180 foreach (var symb in subtree.Grammar.Symbols) { 181 if (symb is StartSymbol || symb is ProgramRootSymbol) continue; 182 if (subtree.Grammar.IsAllowedChildSymbol(selectedCutPoint.Parent.Symbol, symb, selectedCutPoint.ChildIndex)) 183 subtree.Grammar.AddAllowedChildSymbol(matchingSymbol, symb, newArgumentNode.Symbol.ArgumentIndex); 184 184 } 185 185 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDuplicater.cs
r5733 r5792 108 108 selectedDefunBranch.Grammar.AddSymbol(newArgSymbol); 109 109 selectedDefunBranch.Grammar.SetSubtreeCount(newArgSymbol, 0, 0); 110 // allow the argument as child of any other symbol 111 foreach (var symb in selectedDefunBranch.Grammar.Symbols) 112 for (int i = 0; i < selectedDefunBranch.Grammar.GetMaximumSubtreeCount(symb); i++) { 113 selectedDefunBranch.Grammar.AddAllowedChildSymbol(symb, newArgSymbol, i); 114 } 110 // allow the duplicated argument as child of all other arguments where the orginal argument was allowed 111 GrammarModifier.SetAllowedParentSymbols(selectedDefunBranch.Grammar, selectedArgumentSymbol, newArgSymbol); 115 112 selectedDefunBranch.NumberOfArguments++; 116 113 … … 122 119 if (matchingInvokeSymbol != null) { 123 120 subtree.Grammar.SetSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments, selectedDefunBranch.NumberOfArguments); 124 foreach (var child in subtree.Grammar.GetAllowedChildSymbols(subtree.Symbol, 0)) {125 for (int i = 0; i < subtree.Grammar.GetMaximumSubtreeCount(matchingInvokeSymbol); i++) {126 subtree.Grammar.AddAllowedChildSymbol(matchingInvokeSymbol, child, i);127 }121 foreach (var symb in subtree.Grammar.Symbols) { 122 if (symb is StartSymbol || symb is ProgramRootSymbol) continue; 123 if (subtree.Grammar.IsAllowedChildSymbol(matchingInvokeSymbol, symb, selectedArgumentSymbol.ArgumentIndex)) 124 subtree.Grammar.AddAllowedChildSymbol(matchingInvokeSymbol, symb, newArgumentIndex); 128 125 } 129 126 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/GrammarModifier.cs
r5686 r5792 26 26 public static class GrammarModifier { 27 27 internal static void AddInvokeSymbol(ISymbolicExpressionTreeGrammar grammar, string functionName, int nArgs, CutPoint startCutPoint, IEnumerable<CutPoint> argumentCutPoints) { 28 if (!grammar.ContainsSymbol(startCutPoint.Child.Symbol)) return; 29 28 30 var invokeSym = new InvokeFunction(functionName); 29 31 grammar.AddSymbol(invokeSym); … … 31 33 32 34 //allow invoke symbol everywhere, where the child of the startCutPoint was allowed 33 foreach (ISymbol parent in grammar.Symbols) { 34 if (grammar.IsAllowedChildSymbol(parent, startCutPoint.Child.Symbol)) 35 grammar.AddAllowedChildSymbol(parent, invokeSym); 36 else { 37 for (int i = 0; i < grammar.GetMaximumSubtreeCount(parent); i++) { 38 if (grammar.IsAllowedChildSymbol(parent, startCutPoint.Child.Symbol, i)) 39 grammar.AddAllowedChildSymbol(parent, invokeSym, i); 40 } 41 } 42 } 35 SetAllowedParentSymbols(grammar, startCutPoint.Child.Symbol, invokeSym); 43 36 44 37 if (nArgs > 0) { 45 38 //set allowed child symbols of invoke symbol 46 39 foreach (ISymbol child in grammar.Symbols) { 47 if (argumentCutPoints.All(x => grammar.IsAllowedChildSymbol(x.Parent.Symbol, child))) 48 grammar.AddAllowedChildSymbol(invokeSym, child); 49 else { 50 int i = 0; 51 foreach (CutPoint argumentCutPoint in argumentCutPoints) { 52 if (grammar.IsAllowedChildSymbol(argumentCutPoint.Parent.Symbol, child, argumentCutPoint.ChildIndex)) 53 grammar.AddAllowedChildSymbol(invokeSym, child, i); 54 i++; 55 } 40 int i = 0; 41 foreach (CutPoint argumentCutPoint in argumentCutPoints) { 42 if (grammar.IsAllowedChildSymbol(argumentCutPoint.Parent.Symbol, child, argumentCutPoint.ChildIndex)) 43 grammar.AddAllowedChildSymbol(invokeSym, child, i); 44 i++; 56 45 } 57 46 } 58 47 } 59 48 } 49 50 60 51 61 52 internal static void AddArgumentSymbol(ISymbolicExpressionTreeGrammar originalGrammar, ISymbolicExpressionTreeGrammar grammar, IEnumerable<int> argumentIndexes, IEnumerable<CutPoint> argumentCutPoints) { … … 65 56 grammar.SetSubtreeCount(argSymbol, 0, 0); 66 57 67 foreach ( ISymbol parent in originalGrammar.Symbols) {68 if ( parent is StartSymbol || parent is ProgramRootSymbol) continue;69 if (originalGrammar.IsAllowedChildSymbol( parent, pair.CutPoint.Child.Symbol))70 grammar.AddAllowedChildSymbol( parent, argSymbol);58 foreach (var symb in grammar.Symbols) { 59 if (symb is ProgramRootSymbol || symb is StartSymbol) continue; 60 if (originalGrammar.IsAllowedChildSymbol(symb, pair.CutPoint.Child.Symbol)) 61 grammar.AddAllowedChildSymbol(symb, argSymbol); 71 62 else { 72 for (int i = 0; i < originalGrammar.GetMaximumSubtreeCount(parent); i++) {73 if (originalGrammar.IsAllowedChildSymbol( parent, pair.CutPoint.Child.Symbol, i))74 grammar.AddAllowedChildSymbol( parent, argSymbol, i);63 for (int i = 0; i < grammar.GetMaximumSubtreeCount(symb); i++) { 64 if (originalGrammar.IsAllowedChildSymbol(symb, pair.CutPoint.Child.Symbol, i)) 65 grammar.AddAllowedChildSymbol(symb, argSymbol, i); 75 66 } 67 } 68 } 69 } 70 } 71 72 internal static void SetAllowedParentSymbols(ISymbolicExpressionTreeGrammar grammar, ISymbol symbol, ISymbol newSymbol) { 73 foreach (var symb in grammar.Symbols) { 74 if (symb is ProgramRootSymbol) continue; 75 if (newSymbol is Argument && symb is StartSymbol) continue; 76 if (grammar.IsAllowedChildSymbol(symb, symbol)) 77 grammar.AddAllowedChildSymbol(symb, newSymbol); 78 else { 79 for (int i = 0; i < grammar.GetMaximumSubtreeCount(symb); i++) { 80 if (grammar.IsAllowedChildSymbol(symb, symbol, i)) 81 grammar.AddAllowedChildSymbol(symb, newSymbol, i); 76 82 } 77 83 } -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDuplicater.cs
r5733 r5792 89 89 for (int i = 0; i < subtree.Grammar.GetMaximumSubtreeCount(symbol); i++) 90 90 if (subtree.Grammar.IsAllowedChildSymbol(symbol, matchingInvokeSymbol, i)) 91 subtree.Grammar.AddAllowedChildSymbol(symbol, matchingInvokeSymbol, i);91 subtree.Grammar.AddAllowedChildSymbol(symbol, invokeSymbol, i); 92 92 } 93 93 }
Note: See TracChangeset
for help on using the changeset viewer.