[2210] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2210] | 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.Collections.Generic;
|
---|
[4068] | 24 | using System.Drawing;
|
---|
[8126] | 25 | using System.Linq;
|
---|
[3376] | 26 | using HeuristicLab.Common;
|
---|
[2210] | 27 | using HeuristicLab.Core;
|
---|
[3223] | 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[2210] | 29 |
|
---|
[3223] | 30 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
|
---|
| 31 | [StorableClass]
|
---|
| 32 | [Item("SymbolicExpressionTree", "Represents a symbolic expression tree.")]
|
---|
[5499] | 33 | public class SymbolicExpressionTree : Item, ISymbolicExpressionTree {
|
---|
[7201] | 34 | public static new Image StaticItemImage {
|
---|
[5287] | 35 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
|
---|
[3710] | 36 | }
|
---|
[3252] | 37 | [Storable]
|
---|
[5499] | 38 | private ISymbolicExpressionTreeNode root;
|
---|
| 39 | public ISymbolicExpressionTreeNode Root {
|
---|
[3223] | 40 | get { return root; }
|
---|
| 41 | set {
|
---|
| 42 | if (value == null) throw new ArgumentNullException();
|
---|
| 43 | else if (value != root) {
|
---|
| 44 | root = value;
|
---|
| 45 | OnToStringChanged();
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
[2211] | 48 | }
|
---|
| 49 |
|
---|
[5549] | 50 | public int Length {
|
---|
[3223] | 51 | get {
|
---|
[3926] | 52 | if (root == null)
|
---|
| 53 | return 0;
|
---|
[5549] | 54 | return root.GetLength();
|
---|
[3223] | 55 | }
|
---|
[2210] | 56 | }
|
---|
| 57 |
|
---|
[5549] | 58 | public int Depth {
|
---|
[3223] | 59 | get {
|
---|
[3926] | 60 | if (root == null)
|
---|
| 61 | return 0;
|
---|
[5549] | 62 | return root.GetDepth();
|
---|
[2210] | 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[4722] | 66 | [StorableConstructor]
|
---|
| 67 | protected SymbolicExpressionTree(bool deserializing) : base(deserializing) { }
|
---|
| 68 | protected SymbolicExpressionTree(SymbolicExpressionTree original, Cloner cloner)
|
---|
| 69 | : base(original, cloner) {
|
---|
| 70 | root = cloner.Clone(original.Root);
|
---|
[3294] | 71 | }
|
---|
[4722] | 72 | public SymbolicExpressionTree() : base() { }
|
---|
[5532] | 73 | public SymbolicExpressionTree(ISymbolicExpressionTreeNode root)
|
---|
[3294] | 74 | : base() {
|
---|
[3442] | 75 | this.Root = root;
|
---|
[3294] | 76 | }
|
---|
[2210] | 77 |
|
---|
[7795] | 78 | public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesBreadth() {
|
---|
| 79 | if (root == null)
|
---|
[8126] | 80 | return Enumerable.Empty<SymbolicExpressionTreeNode>();
|
---|
[7795] | 81 | return root.IterateNodesBreadth();
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[5499] | 84 | public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPrefix() {
|
---|
[3926] | 85 | if (root == null)
|
---|
[8126] | 86 | return Enumerable.Empty<SymbolicExpressionTreeNode>();
|
---|
[3338] | 87 | return root.IterateNodesPrefix();
|
---|
[3244] | 88 | }
|
---|
[5499] | 89 | public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix() {
|
---|
[3926] | 90 | if (root == null)
|
---|
[8126] | 91 | return Enumerable.Empty<SymbolicExpressionTreeNode>();
|
---|
[3338] | 92 | return root.IterateNodesPostfix();
|
---|
[3244] | 93 | }
|
---|
[3338] | 94 |
|
---|
[3223] | 95 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[4722] | 96 | return new SymbolicExpressionTree(this, cloner);
|
---|
[2210] | 97 | }
|
---|
| 98 | }
|
---|
| 99 | }
|
---|