Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/13/10 20:44:31 (14 years ago)
Author:
gkronber
Message:

Fixed bugs related to dynamic symbol constraints with ADFs. #290 (Implement ADFs)

File:
1 edited

Legend:

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

    r3317 r3338  
    5050    }
    5151
    52     [Storable]
    53     private Dictionary<int, IEnumerable<string>> allowedFunctionsInBranch;
    54 
    5552    public int Size {
    5653      get {
     
    6764    public SymbolicExpressionTree()
    6865      : base() {
    69       allowedFunctionsInBranch = new Dictionary<int, IEnumerable<string>>();
    7066    }
    7167
    7268    public SymbolicExpressionTree(SymbolicExpressionTreeNode root)
    7369      : base() {
    74       allowedFunctionsInBranch = new Dictionary<int, IEnumerable<string>>();
    7570    }
    7671
    7772    public IEnumerable<SymbolicExpressionTreeNode> IterateNodesPrefix() {
    78       return IterateNodesPrefix(root);
    79     }
    80     private IEnumerable<SymbolicExpressionTreeNode> IterateNodesPrefix(SymbolicExpressionTreeNode node) {
    81       yield return node;
    82       foreach (var subtree in node.SubTrees) {
    83         foreach (var n in IterateNodesPrefix(subtree))
    84           yield return n;
    85       }
     73      return root.IterateNodesPrefix();
    8674    }
    8775    public IEnumerable<SymbolicExpressionTreeNode> IterateNodesPostfix() {
    88       return IterateNodesPostfix(root);
     76      return root.IterateNodesPostfix();
    8977    }
    90     private IEnumerable<SymbolicExpressionTreeNode> IterateNodesPostfix(SymbolicExpressionTreeNode node) {
    91       foreach (var subtree in node.SubTrees) {
    92         foreach (var n in IterateNodesPrefix(subtree))
    93           yield return n;
     78
     79    public SymbolicExpressionTreeNode GetTopLevelBranchOf(SymbolicExpressionTreeNode node) {
     80      foreach (var branch in root.SubTrees) {
     81        if (branch.IterateNodesPrefix().Contains(node)) return branch;
    9482      }
    95       yield return node;
     83      throw new ArgumentException("Node was not found in tree.");
    9684    }
    9785
     
    10189      clone.ReadOnlyView = ReadOnlyView;
    10290      clone.root = (SymbolicExpressionTreeNode)this.root.Clone();
    103       clone.allowedFunctionsInBranch = new Dictionary<int, IEnumerable<string>>(allowedFunctionsInBranch);
    10491      return clone;
     92    }
     93
     94    public bool IsValidExpression() {
     95      if (root.Symbol != root.Grammar.StartSymbol) return false;
     96      foreach (var subtree in root.SubTrees)
     97        if (subtree.Grammar == root.Grammar) return false;
     98      return root.IsValidTree();
    10599    }
    106100  }
Note: See TracChangeset for help on using the changeset viewer.