Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/24/21 13:40:39 (3 years ago)
Author:
chaider
Message:

#3041

  • Renaming Constant Symbol to Num, behaves like before
  • Adding new Symbol RealConstant (Constant), this symbol behaves now like a real constant, won't be changed by parameter optimization or manipulators
  • Refactored classes part1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs

    r17180 r18093  
    3636    private static readonly Sine sin = new Sine();
    3737    private static readonly Cosine cos = new Cosine();
    38     private static readonly Constant constant = new Constant();
     38    private static readonly Num Num = new Num();
    3939
    4040    private static ISymbolicExpressionTreeNode ActualRoot(this ISymbolicExpressionTree tree) => tree.Root.GetSubtree(0).GetSubtree(0);
     
    6666      var symbol = node.Symbol;
    6767      var name = symbol.Name;
    68       if (node is ConstantTreeNode constantNode) {
     68      if (node is NumTreeNode constantNode) {
    6969        name = strict ? constantNode.Value.ToString() : symbol.Name;
    7070      } else if (node is VariableTreeNode variableNode) {
     
    222222            variableTreeNode.VariableName = variable.VariableName;
    223223            variableTreeNode.Weight = variable.Weight;
    224           } else if (node.Data is ConstantTreeNode @const) {
    225             var constantTreeNode = (ConstantTreeNode)treeNodes[i];
     224          } else if (node.Data is NumTreeNode @const) {
     225            var constantTreeNode = (NumTreeNode)treeNodes[i];
    226226            constantTreeNode.Value = @const.Value;
    227227          }
     
    285285
    286286        var symbol = child.Data.Symbol;
    287         if (child.Data is ConstantTreeNode firstConst) {
     287        if (child.Data is NumTreeNode firstConst) {
    288288          // fold sibling constant nodes into the first constant
    289289          for (int k = j + 1; k < children.Length; ++k) {
    290290            var sibling = nodes[children[k]];
    291             if (sibling.Data is ConstantTreeNode otherConst) {
     291            if (sibling.Data is NumTreeNode otherConst) {
    292292              sibling.Enabled = false;
    293293              node.Arity--;
     
    301301          for (int k = j + 1; k < children.Length; ++k) {
    302302            var sibling = nodes[children[k]];
    303             if (sibling.Data is ConstantTreeNode constantNode) {
     303            if (sibling.Data is NumTreeNode constantNode) {
    304304              sibling.Enabled = false;
    305305              node.Arity--;
     
    329329
    330330        if (node.Arity == 0) { // if everything is simplified this node becomes constant
    331           var constantTreeNode = constant.CreateTreeNode<ConstantTreeNode>();
     331          var constantTreeNode = Num.CreateTreeNode<NumTreeNode>();
    332332          constantTreeNode.Value = 1;
    333333          nodes[i] = constantTreeNode.ToHashNode();
     
    344344      var tmp = nodes;
    345345
    346       if (children.All(x => tmp[x].Data.Symbol is Constant)) {
    347         var v = ((ConstantTreeNode)nodes[children.First()].Data).Value;
     346      if (children.All(x => tmp[x].Data.Symbol is Num)) {
     347        var v = ((NumTreeNode)nodes[children.First()].Data).Value;
    348348        if (node.Arity == 1) {
    349349          v = 1 / v;
    350350        } else if (node.Arity > 1) {
    351351          foreach (var j in children.Skip(1)) {
    352             v /= ((ConstantTreeNode)nodes[j].Data).Value;
     352            v /= ((NumTreeNode)nodes[j].Data).Value;
    353353          }
    354354        }
    355         var constantTreeNode = constant.CreateTreeNode<ConstantTreeNode>();
     355        var constantTreeNode = Num.CreateTreeNode<NumTreeNode>();
    356356        constantTreeNode.Value = v;
    357357        nodes[i] = constantTreeNode.ToHashNode();
     
    368368        }
    369369        if (node.Arity == 0) {
    370           var constantTreeNode = constant.CreateTreeNode<ConstantTreeNode>();
     370          var constantTreeNode = Num.CreateTreeNode<NumTreeNode>();
    371371          constantTreeNode.Value = 1; // x / x = 1
    372372          nodes[i] = constantTreeNode.ToHashNode();
     
    383383      var childSymbol = child.Data.Symbol;
    384384
    385       if (childSymbol is Constant) {
     385      if (childSymbol is Num) {
    386386        nodes[i].Enabled = false;
    387387      } else if ((parentSymbol is Exponential && childSymbol is Logarithm) || (parentSymbol is Logarithm && childSymbol is Exponential)) {
     
    393393      var children = nodes.IterateChildren(i);
    394394      var tmp = nodes;
    395       if (children.All(x => tmp[x].Data.Symbol is Constant)) {
     395      if (children.All(x => tmp[x].Data.Symbol is Num)) {
    396396        foreach (var j in children) {
    397397          nodes[j].Enabled = false;
    398398        }
    399         nodes[i] = constant.CreateTreeNode().ToHashNode();
     399        nodes[i] = Num.CreateTreeNode().ToHashNode();
    400400      }
    401401    }
Note: See TracChangeset for help on using the changeset viewer.