Changeset 18115 for branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing
- Timestamp:
- 12/13/21 17:49:34 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs
r18114 r18115 28 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 29 29 public static class SymbolicExpressionTreeHash { 30 private static readonly Addition add = new Addition();31 private static readonly Subtraction sub = new Subtraction();32 private static readonly Multiplication mul = new Multiplication();33 private static readonly Division div = new Division();34 private static readonly Logarithm log = new Logarithm();35 private static readonly Exponential exp = new Exponential();36 private static readonly Sine sin = new Sine();37 private static readonly Cosine cos = new Cosine();38 30 private static readonly Number number = new Number(); 39 31 … … 66 58 var symbol = node.Symbol; 67 59 var name = symbol.Name; 68 if (node is NumberTreeNode numNode) {69 name = strict ? numNode.Value.ToString() : symbol.Name;60 if (node is INumericTreeNode numNode) { 61 name = strict ? numNode.Value.ToString() : "Number"; 70 62 } else if (node is VariableTreeNode variableNode) { 71 63 name = strict ? variableNode.Weight.ToString() + variableNode.VariableName : variableNode.VariableName; … … 222 214 variableTreeNode.VariableName = variable.VariableName; 223 215 variableTreeNode.Weight = variable.Weight; 224 } else if (node.Data is NumberTreeNode existingNumNode) {225 var newNumNode = ( NumberTreeNode)treeNodes[i];216 } else if (node.Data is INumericTreeNode existingNumNode) { 217 var newNumNode = (INumericTreeNode)treeNodes[i]; 226 218 newNumNode.Value = existingNumNode.Value; 227 219 } … … 285 277 286 278 var symbol = child.Data.Symbol; 287 if (child.Data is NumberTreeNode firstNum) {279 if (child.Data is INumericTreeNode firstNum) { 288 280 // fold sibling number nodes into the first number 289 281 for (int k = j + 1; k < children.Length; ++k) { 290 282 var sibling = nodes[children[k]]; 291 if (sibling.Data is NumberTreeNode otherNum) {283 if (sibling.Data is INumericTreeNode otherNum) { 292 284 sibling.Enabled = false; 293 285 node.Arity--; … … 301 293 for (int k = j + 1; k < children.Length; ++k) { 302 294 var sibling = nodes[children[k]]; 303 if (sibling.Data is NumberTreeNode numNode) {295 if (sibling.Data is INumericTreeNode numNode) { 304 296 sibling.Enabled = false; 305 297 node.Arity--; … … 344 336 var tmp = nodes; 345 337 346 if (children.All(x => tmp[x].Data.Symbol is Number)) {347 var v = (( NumberTreeNode)nodes[children.First()].Data).Value;338 if (children.All(x => tmp[x].Data.Symbol is INumericSymbol)) { 339 var v = ((INumericTreeNode)nodes[children.First()].Data).Value; 348 340 if (node.Arity == 1) { 349 341 v = 1 / v; 350 342 } else if (node.Arity > 1) { 351 343 foreach (var j in children.Skip(1)) { 352 v /= (( NumberTreeNode)nodes[j].Data).Value;344 v /= ((INumericTreeNode)nodes[j].Data).Value; 353 345 } 354 346 } … … 383 375 var childSymbol = child.Data.Symbol; 384 376 385 if (childSymbol is Number) {377 if (childSymbol is INumericSymbol) { 386 378 nodes[i].Enabled = false; 387 379 } else if ((parentSymbol is Exponential && childSymbol is Logarithm) || (parentSymbol is Logarithm && childSymbol is Exponential)) { … … 393 385 var children = nodes.IterateChildren(i); 394 386 var tmp = nodes; 395 if (children.All(x => tmp[x].Data.Symbol is Number)) {387 if (children.All(x => tmp[x].Data.Symbol is INumericSymbol)) { 396 388 foreach (var j in children) { 397 389 nodes[j].Enabled = false;
Note: See TracChangeset
for help on using the changeset viewer.