Changeset 18113 for branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing
- Timestamp:
- 12/11/21 12:26:27 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs
r18093 r18113 36 36 private static readonly Sine sin = new Sine(); 37 37 private static readonly Cosine cos = new Cosine(); 38 private static readonly Num Num = new Num();38 private static readonly Number number = new Number(); 39 39 40 40 private static ISymbolicExpressionTreeNode ActualRoot(this ISymbolicExpressionTree tree) => tree.Root.GetSubtree(0).GetSubtree(0); … … 66 66 var symbol = node.Symbol; 67 67 var name = symbol.Name; 68 if (node is Num TreeNode constantNode) {68 if (node is NumberTreeNode constantNode) { 69 69 name = strict ? constantNode.Value.ToString() : symbol.Name; 70 70 } else if (node is VariableTreeNode variableNode) { … … 222 222 variableTreeNode.VariableName = variable.VariableName; 223 223 variableTreeNode.Weight = variable.Weight; 224 } else if (node.Data is Num TreeNode @const) {225 var constantTreeNode = (Num TreeNode)treeNodes[i];224 } else if (node.Data is NumberTreeNode @const) { 225 var constantTreeNode = (NumberTreeNode)treeNodes[i]; 226 226 constantTreeNode.Value = @const.Value; 227 227 } … … 285 285 286 286 var symbol = child.Data.Symbol; 287 if (child.Data is Num TreeNode firstConst) {287 if (child.Data is NumberTreeNode firstConst) { 288 288 // fold sibling constant nodes into the first constant 289 289 for (int k = j + 1; k < children.Length; ++k) { 290 290 var sibling = nodes[children[k]]; 291 if (sibling.Data is Num TreeNode otherConst) {291 if (sibling.Data is NumberTreeNode otherConst) { 292 292 sibling.Enabled = false; 293 293 node.Arity--; … … 301 301 for (int k = j + 1; k < children.Length; ++k) { 302 302 var sibling = nodes[children[k]]; 303 if (sibling.Data is Num TreeNode constantNode) {303 if (sibling.Data is NumberTreeNode constantNode) { 304 304 sibling.Enabled = false; 305 305 node.Arity--; … … 329 329 330 330 if (node.Arity == 0) { // if everything is simplified this node becomes constant 331 var constantTreeNode = Num.CreateTreeNode<NumTreeNode>();331 var constantTreeNode = number.CreateTreeNode<NumberTreeNode>(); 332 332 constantTreeNode.Value = 1; 333 333 nodes[i] = constantTreeNode.ToHashNode(); … … 344 344 var tmp = nodes; 345 345 346 if (children.All(x => tmp[x].Data.Symbol is Num )) {347 var v = ((Num TreeNode)nodes[children.First()].Data).Value;346 if (children.All(x => tmp[x].Data.Symbol is Number)) { 347 var v = ((NumberTreeNode)nodes[children.First()].Data).Value; 348 348 if (node.Arity == 1) { 349 349 v = 1 / v; 350 350 } else if (node.Arity > 1) { 351 351 foreach (var j in children.Skip(1)) { 352 v /= ((Num TreeNode)nodes[j].Data).Value;352 v /= ((NumberTreeNode)nodes[j].Data).Value; 353 353 } 354 354 } 355 var constantTreeNode = Num.CreateTreeNode<NumTreeNode>();355 var constantTreeNode = number.CreateTreeNode<NumberTreeNode>(); 356 356 constantTreeNode.Value = v; 357 357 nodes[i] = constantTreeNode.ToHashNode(); … … 368 368 } 369 369 if (node.Arity == 0) { 370 var constantTreeNode = Num.CreateTreeNode<NumTreeNode>();370 var constantTreeNode = number.CreateTreeNode<NumberTreeNode>(); 371 371 constantTreeNode.Value = 1; // x / x = 1 372 372 nodes[i] = constantTreeNode.ToHashNode(); … … 383 383 var childSymbol = child.Data.Symbol; 384 384 385 if (childSymbol is Num ) {385 if (childSymbol is Number) { 386 386 nodes[i].Enabled = false; 387 387 } else if ((parentSymbol is Exponential && childSymbol is Logarithm) || (parentSymbol is Logarithm && childSymbol is Exponential)) { … … 393 393 var children = nodes.IterateChildren(i); 394 394 var tmp = nodes; 395 if (children.All(x => tmp[x].Data.Symbol is Num )) {395 if (children.All(x => tmp[x].Data.Symbol is Number)) { 396 396 foreach (var j in children) { 397 397 nodes[j].Enabled = false; 398 398 } 399 nodes[i] = Num.CreateTreeNode().ToHashNode();399 nodes[i] = number.CreateTreeNode().ToHashNode(); 400 400 } 401 401 }
Note: See TracChangeset
for help on using the changeset viewer.