Changeset 5686 for branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars
- Timestamp:
- 03/15/11 13:34:38 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/ArithmeticExpressionGrammar.cs
r5580 r5686 29 29 [StorableClass] 30 30 [Item("ArithmeticExpressionGrammar", "Represents a grammar for functional expressions using only arithmetic operations.")] 31 public class ArithmeticExpressionGrammar : DefaultSymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {31 public class ArithmeticExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar { 32 32 33 33 [StorableConstructor] … … 59 59 60 60 foreach (var funSymb in functionSymbols) { 61 SetMinSubtreeCount(funSymb, 1); 62 SetMaxSubtreeCount(funSymb, 3); 61 SetSubtreeCount(funSymb, 1, 3); 63 62 } 64 SetMinSubtreeCount(constant, 0); 65 SetMaxSubtreeCount(constant, 0); 66 SetMinSubtreeCount(variableSymbol, 0); 67 SetMaxSubtreeCount(variableSymbol, 0); 63 SetSubtreeCount(constant, 0, 0); 64 SetSubtreeCount(variableSymbol, 0, 0); 68 65 69 66 // allow each symbol as child of the start symbol 70 67 foreach (var symb in allSymbols) { 71 SetAllowedChild(StartSymbol, symb, 0);68 AddAllowedChildSymbol(StartSymbol, symb); 72 69 } 73 70 74 71 // allow each symbol as child of every other symbol (except for terminals that have maxSubtreeCount == 0) 75 foreach (var parent in allSymbols) { 76 for (int i = 0; i < GetMaxSubtreeCount(parent); i++) 77 foreach (var child in allSymbols) { 78 SetAllowedChild(parent, child, i); 79 } 72 foreach (var parent in functionSymbols) { 73 foreach (var child in allSymbols) 74 AddAllowedChildSymbol(parent, child); 80 75 } 81 76 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs
r5580 r5686 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 29 30 [StorableClass] 30 31 [Item("FullFunctionalExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")] 31 public class FullFunctionalExpressionGrammar : DefaultSymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {32 public class FullFunctionalExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar { 32 33 [StorableConstructor] 33 34 protected FullFunctionalExpressionGrammar(bool deserializing) : base(deserializing) { } … … 92 93 93 94 foreach (var funSymb in functionSymbols) { 94 SetMinSubtreeCount(funSymb, 1); 95 SetMaxSubtreeCount(funSymb, 3); 95 SetSubtreeCount(funSymb, 1, 3); 96 96 } 97 97 foreach (var funSymb in unaryFunctionSymbols) { 98 SetMinSubtreeCount(funSymb, 1); 99 SetMaxSubtreeCount(funSymb, 1); 98 SetSubtreeCount(funSymb, 1, 1); 100 99 } 101 100 foreach (var funSymb in binaryFunctionSymbols) { 102 SetMinSubtreeCount(funSymb, 2); 103 SetMaxSubtreeCount(funSymb, 2); 101 SetSubtreeCount(funSymb, 2, 2); 102 } 103 foreach (var terminalSymbol in terminalSymbols) { 104 SetSubtreeCount(terminalSymbol, 0, 0); 104 105 } 105 106 106 foreach (var terminalSymbol in terminalSymbols) { 107 SetMinSubtreeCount(terminalSymbol, 0); 108 SetMaxSubtreeCount(terminalSymbol, 0); 109 } 110 111 SetMinSubtreeCount(@if, 3); 112 SetMaxSubtreeCount(@if, 3); 107 SetSubtreeCount(@if, 3, 3); 113 108 114 109 115 110 // allow each symbol as child of the start symbol 116 111 foreach (var symb in allSymbols) { 117 SetAllowedChild(StartSymbol, symb, 0);112 AddAllowedChildSymbol(StartSymbol, symb); 118 113 } 119 114 120 115 // allow each symbol as child of every other symbol (except for terminals that have maxSubtreeCount == 0) 121 foreach (var parent in allSymbols) { 122 for (int i = 0; i < GetMaxSubtreeCount(parent); i++) 123 foreach (var child in allSymbols) { 124 SetAllowedChild(parent, child, i); 125 } 116 foreach (var parent in allSymbols.Except(terminalSymbols)) { 117 foreach (var child in allSymbols) 118 AddAllowedChildSymbol(parent, child); 126 119 } 127 120 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs
r5580 r5686 29 29 [StorableClass] 30 30 [Item("TypeCoherentExpressionGrammar", "Represents a grammar for functional expressions in which special syntactic constraints are enforced so that boolean and real-valued expressions are not mixed.")] 31 public class TypeCoherentExpressionGrammar : DefaultSymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {31 public class TypeCoherentExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar { 32 32 33 33 [StorableConstructor] … … 123 123 124 124 foreach (var unaryFun in unaryFunctionSymbols.Concat(unaryBooleanFunctionSymbols)) { 125 SetMinSubtreeCount(unaryFun, 1); 126 SetMaxSubtreeCount(unaryFun, 1); 125 SetSubtreeCount(unaryFun, 1, 1); 127 126 } 128 127 foreach (var binaryFun in binaryFunctionSymbols.Concat(binaryBooleanFunctionSymbols).Concat(relationalFunctionSymbols)) { 129 SetMinSubtreeCount(binaryFun, 2); 130 SetMaxSubtreeCount(binaryFun, 2); 128 SetSubtreeCount(binaryFun, 2, 2); 131 129 } 132 130 133 131 foreach (var terminalSymbol in terminalSymbols) { 134 SetMinSubtreeCount(terminalSymbol, 0); 135 SetMaxSubtreeCount(terminalSymbol, 0); 132 SetSubtreeCount(terminalSymbol, 0, 0); 136 133 } 137 134 138 SetMinSubtreeCount(@if, 3); 139 SetMaxSubtreeCount(@if, 3); 135 SetSubtreeCount(@if, 3, 3); 140 136 141 137 142 138 // allow only real-valued expressions as child of the start symbol 143 139 foreach (var symb in realValuedSymbols) { 144 SetAllowedChild(StartSymbol, symb, 0);140 AddAllowedChildSymbol(StartSymbol, symb); 145 141 } 146 142 147 143 foreach (var symb in unaryFunctionSymbols) { 148 144 foreach (var childSymb in realValuedSymbols) { 149 SetAllowedChild(symb, childSymb, 0);145 AddAllowedChildSymbol(symb, childSymb); 150 146 } 151 147 } … … 153 149 foreach (var symb in binaryFunctionSymbols) { 154 150 foreach (var childSymb in realValuedSymbols) { 155 SetAllowedChild(symb, childSymb, 0); 156 SetAllowedChild(symb, childSymb, 1); 151 AddAllowedChildSymbol(symb, childSymb); 157 152 } 158 153 } 159 154 160 155 foreach (var childSymb in booleanSymbols) { 161 SetAllowedChild(@if, childSymb, 0);156 AddAllowedChildSymbol(@if, childSymb, 0); 162 157 } 163 158 foreach (var childSymb in realValuedSymbols) { 164 SetAllowedChild(@if, childSymb, 1);165 SetAllowedChild(@if, childSymb, 2);159 AddAllowedChildSymbol(@if, childSymb, 1); 160 AddAllowedChildSymbol(@if, childSymb, 2); 166 161 } 167 162 168 163 foreach (var symb in relationalFunctionSymbols) { 169 164 foreach (var childSymb in realValuedSymbols) { 170 SetAllowedChild(symb, childSymb, 0); 171 SetAllowedChild(symb, childSymb, 1); 165 AddAllowedChildSymbol(symb, childSymb); 172 166 } 173 167 } 174 168 foreach (var symb in binaryBooleanFunctionSymbols) { 175 169 foreach (var childSymb in booleanSymbols) { 176 SetAllowedChild(symb, childSymb, 0); 177 SetAllowedChild(symb, childSymb, 1); 170 AddAllowedChildSymbol(symb, childSymb); 178 171 } 179 172 } 180 173 foreach (var symb in unaryBooleanFunctionSymbols) { 181 174 foreach (var childSymb in booleanSymbols) { 182 SetAllowedChild(symb, childSymb, 0);175 AddAllowedChildSymbol(symb, childSymb); 183 176 } 184 177 }
Note: See TracChangeset
for help on using the changeset viewer.