Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs @ 3244

Last change on this file since 3244 was 3244, checked in by gkronber, 14 years ago

Integrated graphical symbolic expression tree view from model analyzer. #937 (Data types and operators for symbolic expression tree encoding)

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Core;
26using System.Xml;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Data;
29
30namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
31  [StorableClass]
32  public class SymbolicExpressionTreeNode : DeepCloneable {
33    private List<SymbolicExpressionTreeNode> subTrees;
34    private Symbol symbol;
35
36    public SymbolicExpressionTreeNode() {
37    }
38
39    public SymbolicExpressionTreeNode(Symbol symbol) {
40      subTrees = new List<SymbolicExpressionTreeNode>();
41      this.symbol = symbol;
42    }
43
44    //protected SymbolicExpressionTreeNode(SymbolicExpressionTreeNode original) {
45    //  this.symbol = original.Symbol;
46    //  this.subTrees = new List<SymbolicExpressionTreeNode>(original.SubTrees.Count);
47    //  foreach (SymbolicExpressionTreeNode originalSubTree in original.SubTrees) {
48    //    this.SubTrees.Add((SymbolicExpressionTreeNode)originalSubTree.Clone());
49    //  }
50    //}
51
52    public virtual bool HasLocalParameters {
53      get { return false; }
54    }
55
56    public virtual IList<SymbolicExpressionTreeNode> SubTrees {
57      get { return subTrees; }
58    }
59
60    public Symbol Symbol {
61      get { return symbol; }
62      protected set { symbol = value; }
63    }
64
65    public int GetSize() {
66      int size = 1;
67      foreach (SymbolicExpressionTreeNode tree in SubTrees) size += tree.GetSize();
68      return size;
69    }
70
71    public int GetHeight() {
72      int maxHeight = 0;
73      foreach (SymbolicExpressionTreeNode tree in SubTrees) maxHeight = Math.Max(maxHeight, tree.GetHeight());
74      return maxHeight + 1;
75    }
76
77    //public virtual IOperation CreateShakingOperation(IScope scope) {
78    //  return null;
79    //}
80
81    //public virtual IOperation CreateInitOperation(IScope scope) {
82    //  return null;
83    //}
84
85    protected internal virtual void AddSubTree(SymbolicExpressionTreeNode tree) {
86      SubTrees.Add(tree);
87    }
88
89    protected internal virtual void InsertSubTree(int index, SymbolicExpressionTreeNode tree) {
90      SubTrees.Insert(index, tree);
91    }
92
93    protected internal virtual void RemoveSubTree(int index) {
94      SubTrees.RemoveAt(index);
95    }
96
97    public override IDeepCloneable Clone(Cloner cloner) {
98      SymbolicExpressionTreeNode clone = new SymbolicExpressionTreeNode(symbol);
99      cloner.RegisterClonedObject(this, clone);
100      foreach (var subtree in SubTrees) {
101        clone.AddSubTree((SymbolicExpressionTreeNode)subtree.Clone(cloner));
102      }
103      return clone;
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.