Changeset 3541 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/GlobalSymbolicExpressionGrammar.cs
- Timestamp:
- 04/27/10 11:44:36 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/GlobalSymbolicExpressionGrammar.cs
r3484 r3541 40 40 set { 41 41 minFunctionDefinitions = value; 42 Reset();42 Initialize(); 43 43 } 44 44 } … … 49 49 set { 50 50 maxFunctionDefinitions = value; 51 Reset();51 Initialize(); 52 52 } 53 53 } … … 58 58 set { 59 59 minFunctionArguments = value; 60 Reset();60 Initialize(); 61 61 } 62 62 } … … 67 67 set { 68 68 maxFunctionArguments = value; 69 Reset();69 Initialize(); 70 70 } 71 71 } … … 83 83 } 84 84 85 [StorableHook(HookType.AfterDeserialization)] 86 private void AfterDeserializationHook() { 87 Reset(); 88 } 85 private void Initialize() { 86 base.Clear(); 89 87 90 private new void Reset() {91 base.Reset();92 Initialize();93 }94 95 private void Initialize() {96 88 // remove the start symbol of the default grammar 97 89 RemoveSymbol(StartSymbol); … … 107 99 SetMaxSubtreeCount(defunSymbol, 1); 108 100 109 // copy symbols from mainBranchGrammar 110 foreach (var symb in mainBranchGrammar.Symbols) { 111 AddSymbol(symb); 112 SetMinSubtreeCount(symb, mainBranchGrammar.GetMinSubtreeCount(symb)); 113 SetMaxSubtreeCount(symb, mainBranchGrammar.GetMaxSubtreeCount(symb)); 114 } 101 if (mainBranchGrammar != null) { 102 // copy symbols from mainBranchGrammar 103 foreach (var symb in mainBranchGrammar.Symbols) { 104 AddSymbol(symb); 105 SetMinSubtreeCount(symb, mainBranchGrammar.GetMinSubtreeCount(symb)); 106 SetMaxSubtreeCount(symb, mainBranchGrammar.GetMaxSubtreeCount(symb)); 107 } 115 108 116 // the start symbol of the mainBranchGrammar is allowed as the result producing branch117 SetAllowedChild(StartSymbol, mainBranchGrammar.StartSymbol, 0);109 // the start symbol of the mainBranchGrammar is allowed as the result producing branch 110 SetAllowedChild(StartSymbol, mainBranchGrammar.StartSymbol, 0); 118 111 119 // ADF branches maxFunctionDefinitions120 for (int argumentIndex = 1; argumentIndex < maxFunctionDefinitions + 1; argumentIndex++) {121 SetAllowedChild(StartSymbol, defunSymbol, argumentIndex);122 }112 // ADF branches maxFunctionDefinitions 113 for (int argumentIndex = 1; argumentIndex < maxFunctionDefinitions + 1; argumentIndex++) { 114 SetAllowedChild(StartSymbol, defunSymbol, argumentIndex); 115 } 123 116 124 // copy syntax constraints from mainBranchGrammar 125 foreach (var parent in mainBranchGrammar.Symbols) { 126 for (int i = 0; i < mainBranchGrammar.GetMaxSubtreeCount(parent); i++) { 127 foreach (var child in mainBranchGrammar.Symbols) { 128 if (mainBranchGrammar.IsAllowedChild(parent, child, i)) { 129 SetAllowedChild(parent, child, i); 117 // copy syntax constraints from mainBranchGrammar 118 foreach (var parent in mainBranchGrammar.Symbols) { 119 for (int i = 0; i < mainBranchGrammar.GetMaxSubtreeCount(parent); i++) { 120 foreach (var child in mainBranchGrammar.Symbols) { 121 if (mainBranchGrammar.IsAllowedChild(parent, child, i)) { 122 SetAllowedChild(parent, child, i); 123 } 130 124 } 131 125 } 132 126 } 133 }134 127 135 // every symbol of the mainBranchGrammar that is allowed as child of the start symbol is also allowed as direct child of defun 136 foreach (var symb in mainBranchGrammar.Symbols) { 137 if (mainBranchGrammar.IsAllowedChild(mainBranchGrammar.StartSymbol, symb, 0)) 138 SetAllowedChild(defunSymbol, symb, 0); 128 // every symbol of the mainBranchGrammar that is allowed as child of the start symbol is also allowed as direct child of defun 129 foreach (var symb in mainBranchGrammar.Symbols) { 130 if (mainBranchGrammar.IsAllowedChild(mainBranchGrammar.StartSymbol, symb, 0)) 131 SetAllowedChild(defunSymbol, symb, 0); 132 } 139 133 } 140 134 }
Note: See TracChangeset
for help on using the changeset viewer.