Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTree.cs @ 15418

Last change on this file since 15418 was 14312, checked in by bburlacu, 8 years ago

#1772: Merge trunk changes. Delete unnecessary files (sliding window).

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Drawing;
25using System.Linq;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
31  [StorableClass]
32  [Item("SymbolicExpressionTree", "Represents a symbolic expression tree.")]
33  public class SymbolicExpressionTree : Item, ISymbolicExpressionTree {
34    public static new Image StaticItemImage {
35      get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; }
36    }
37    [Storable]
38    private ISymbolicExpressionTreeNode root;
39    public ISymbolicExpressionTreeNode Root {
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      }
48    }
49
50    public int Length {
51      get {
52        if (root == null)
53          return 0;
54        return root.GetLength();
55      }
56    }
57
58    public int Depth {
59      get {
60        if (root == null)
61          return 0;
62        return root.GetDepth();
63      }
64    }
65
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);
71    }
72    public SymbolicExpressionTree() : base() { }
73    public SymbolicExpressionTree(ISymbolicExpressionTreeNode root)
74      : base() {
75      this.Root = root;
76    }
77
78    public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesBreadth() {
79      if (root == null)
80        return Enumerable.Empty<SymbolicExpressionTreeNode>();
81      return root.IterateNodesBreadth();
82    }
83
84    public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPrefix() {
85      if (root == null)
86        return Enumerable.Empty<SymbolicExpressionTreeNode>();
87      return root.IterateNodesPrefix();
88    }
89    public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix() {
90      if (root == null)
91        return Enumerable.Empty<SymbolicExpressionTreeNode>();
92      return root.IterateNodesPostfix();
93    }
94
95    public override IDeepCloneable Clone(Cloner cloner) {
96      return new SymbolicExpressionTree(this, cloner);
97    }
98  }
99}
Note: See TracBrowser for help on using the repository browser.