1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 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 |
|
---|
22 | using System;
|
---|
23 | using System.Linq;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using System.Xml;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 | using HeuristicLab.Data;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
|
---|
32 | [StorableClass]
|
---|
33 | [Item("SymbolicExpressionTree", "Represents a symbolic expression tree.")]
|
---|
34 | public class SymbolicExpressionTree : Item {
|
---|
35 | [Storable]
|
---|
36 | private SymbolicExpressionTreeNode root;
|
---|
37 | public SymbolicExpressionTreeNode Root {
|
---|
38 | get { return root; }
|
---|
39 | set {
|
---|
40 | if (value == null) throw new ArgumentNullException();
|
---|
41 | else if (value != root) {
|
---|
42 | root = value;
|
---|
43 | OnToStringChanged();
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public SymbolicExpressionTreeNode ResultProducingExpression {
|
---|
49 | get { return root.SubTrees[0].SubTrees[0]; }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public int Size {
|
---|
53 | get {
|
---|
54 | return root.GetSize();
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public int Height {
|
---|
59 | get {
|
---|
60 | return root.GetHeight();
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | public SymbolicExpressionTree()
|
---|
65 | : base() {
|
---|
66 | }
|
---|
67 |
|
---|
68 | public SymbolicExpressionTree(SymbolicExpressionTreeNode root)
|
---|
69 | : base() {
|
---|
70 | }
|
---|
71 |
|
---|
72 | public IEnumerable<SymbolicExpressionTreeNode> IterateNodesPrefix() {
|
---|
73 | return root.IterateNodesPrefix();
|
---|
74 | }
|
---|
75 | public IEnumerable<SymbolicExpressionTreeNode> IterateNodesPostfix() {
|
---|
76 | return root.IterateNodesPostfix();
|
---|
77 | }
|
---|
78 |
|
---|
79 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
80 | SymbolicExpressionTree clone = new SymbolicExpressionTree();
|
---|
81 | cloner.RegisterClonedObject(this, clone);
|
---|
82 | clone.ReadOnlyView = ReadOnlyView;
|
---|
83 | clone.root = (SymbolicExpressionTreeNode)this.root.Clone();
|
---|
84 | return clone;
|
---|
85 | }
|
---|
86 | }
|
---|
87 | }
|
---|