Changeset 15812 for branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs
- Timestamp:
- 02/23/18 18:10:30 (7 years ago)
- Location:
- branches/2886_SymRegGrammarEnumeration
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration
- Property svn:ignore
-
old new 1 1 TestResults 2 *.gitignore
-
-
Property
svn:global-ignores
set to
.git
- Property svn:ignore
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs
r15806 r15812 143 143 } 144 144 145 private int CalcHashCode<THashType>(SymbolString sentence, Func<Symbol, IEnumerable<THashType>, THashType> aggregateFunction) {145 private int CalcHashCode<THashType>(SymbolString sentence, Func<Symbol, THashType[], THashType> aggregateFunction) { 146 146 Debug.Assert(sentence.Any(), "Trying to evaluate empty sentence!"); 147 147 … … 152 152 } 153 153 154 private THashType[] GetSubtreeHashes<THashType>(Stack<Symbol> parseStack, Func<Symbol, IEnumerable<THashType>, THashType> aggregateHashes) {154 private THashType[] GetSubtreeHashes<THashType>(Stack<Symbol> parseStack, Func<Symbol, THashType[], THashType> aggregateHashes) { 155 155 Symbol currentSymbol = parseStack.Pop(); 156 156 … … 207 207 208 208 var currFactor = childHashes[i]; 209 var invFactor = aggregateHashes(Inv, currFactor.ToEnumerable());209 var invFactor = aggregateHashes(Inv, new[] { currFactor }); 210 210 211 211 int indexOfInv = childHashes.IndexOf(invFactor); … … 228 228 229 229 // var or nonterminal symbol 230 return new[] { aggregateHashes(currentSymbol, Enumerable.Empty<THashType>()) };231 } 232 233 private string AggregateStringHashes(Symbol operatorSym, IEnumerable<string>hashes) {230 return new[] { aggregateHashes(currentSymbol, new THashType[0]) }; 231 } 232 233 private string AggregateStringHashes(Symbol operatorSym, string[] hashes) { 234 234 var hashesArray = hashes.ToArray(); 235 235 … … 237 237 return hashesArray[0]; 238 238 } 239 if (operatorSym is NonterminalSymbol || Var.VariableTerminalSymbols.Contains(operatorSym)) {239 if (operatorSym is NonterminalSymbol || ((TerminalSymbol)operatorSym).IsVariable) { 240 240 return operatorSym.StringRepresentation; 241 241 } … … 244 244 } 245 245 246 private int AggregateIntHashes(Symbol operatorSym, IEnumerable<int> hashes) { 247 var hashesArray = hashes.ToArray(); 248 246 private int AggregateIntHashes(Symbol operatorSym, int[] hashes) { 249 247 int start; 250 248 if ((ReferenceEquals(operatorSym, Addition) || ReferenceEquals(operatorSym, Multiplication)) && 251 hashes Array.Count()<= 1) {249 hashes.Length <= 1) { 252 250 start = 0; 253 251 254 } else if (operatorSym is NonterminalSymbol || Var.VariableTerminalSymbols.Contains(operatorSym)) {252 } else if (operatorSym is NonterminalSymbol || ((TerminalSymbol)operatorSym).IsVariable) { 255 253 return operatorSym.StringRepresentation.GetHashCode(); 256 254 … … 259 257 } 260 258 261 return hashesArray.Aggregate(start, (result, ti) => ((result << 5) + result) ^ ti.GetHashCode()); 259 for (int i = 0; i < hashes.Length; i++) { 260 start = ((start << 5) + start) ^ hashes[i]; 261 } 262 return start; 262 263 } 263 264 #endregion … … 314 315 parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack)); 315 316 316 } else if ( Var.VariableTerminalSymbols.Contains(currentSymbol)) {317 } else if (currentSymbol.IsVariable) { 317 318 VariableTreeNode varNode = (VariableTreeNode)varSy.CreateTreeNode(); 318 319 varNode.Weight = 1.0; … … 337 338 Symbol head = parseStack.Pop(); 338 339 339 SymbolString result = new SymbolString( );340 SymbolString result = new SymbolString(parseStack.Count); 340 341 341 342 if (ReferenceEquals(head, Addition) || ReferenceEquals(head, Multiplication)) {
Note: See TracChangeset
for help on using the changeset viewer.