Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/10 12:12:29 (14 years ago)
Author:
gkronber
Message:

Changed way the grammar is stored in tree nodes to make it more efficient and fixed bugs in symbolic expression tree operators. #290 (Implement ADFs)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs

    r3360 r3369  
    3737    [Storable]
    3838    private Symbol symbol;
     39    //[Storable]
     40    private SymbolicExpressionTreeNode parent;
    3941
    4042    public SymbolicExpressionTreeNode() {
     
    5153      symbol = original.symbol;
    5254      subTrees = new List<SymbolicExpressionTreeNode>();
    53       grammar = original.grammar;
    5455      foreach (var subtree in original.SubTrees) {
    55         SubTrees.Add((SymbolicExpressionTreeNode)subtree.Clone());
     56        AddSubTree((SymbolicExpressionTreeNode)subtree.Clone());
    5657      }
    5758    }
     
    7071    }
    7172
    72     private ISymbolicExpressionGrammar grammar;
    73     public virtual ISymbolicExpressionGrammar Grammar {
    74       get { return grammar; }
    75       set {
    76         grammar = value;
    77         foreach (var subtree in subTrees)
    78           subtree.Grammar = value;
    79       }
     73    internal SymbolicExpressionTreeNode Parent {
     74      get { return parent; }
     75      set { parent = value; }
     76    }
     77
     78    internal virtual ISymbolicExpressionGrammar Grammar {
     79      get { return parent.Grammar; }
     80      set { throw new NotSupportedException("Grammar can be set only for SymbolicExpressionTreeTopLevelNodes."); }
    8081    }
    8182
     
    9697
    9798    public virtual void AddSubTree(SymbolicExpressionTreeNode tree) {
    98       SubTrees.Add(tree);
    99       //if (tree != null)
    100       tree.Grammar = Grammar;
     99      subTrees.Add(tree);
     100      tree.Parent = this;
    101101    }
    102102
    103103    public virtual void InsertSubTree(int index, SymbolicExpressionTreeNode tree) {
    104       SubTrees.Insert(index, tree);
    105       //if (tree != null)
    106       tree.Grammar = Grammar;
     104      subTrees.Insert(index, tree);
     105      tree.Parent = this;
    107106    }
    108107
    109108    public virtual void RemoveSubTree(int index) {
    110       //if (SubTrees[index] != null)
    111       SubTrees[index].Grammar = null;
    112       SubTrees.RemoveAt(index);
     109      subTrees[index].Parent = null;
     110      subTrees.RemoveAt(index);
    113111    }
    114112
Note: See TracChangeset for help on using the changeset viewer.