Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTree.cs @ 16349

Last change on this file since 16349 was 13656, checked in by ascheibe, 8 years ago

#2582 created branch for Hive Web Job Manager

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
30  [StorableClass]
31  [Item("SymbolicExpressionTree", "Represents a symbolic expression tree.")]
32  public class SymbolicExpressionTree : Item, ISymbolicExpressionTree {
33
34    [Storable]
35    private ISymbolicExpressionTreeNode root;
36    public ISymbolicExpressionTreeNode Root
37    {
38      get { return root; }
39      set
40      {
41        if (value == null) throw new ArgumentNullException();
42        else if (value != root) {
43          root = value;
44          OnToStringChanged();
45        }
46      }
47    }
48
49    public int Length
50    {
51      get
52      {
53        if (root == null)
54          return 0;
55        return root.GetLength();
56      }
57    }
58
59    public int Depth
60    {
61      get
62      {
63        if (root == null)
64          return 0;
65        return root.GetDepth();
66      }
67    }
68
69    [StorableConstructor]
70    protected SymbolicExpressionTree(bool deserializing) : base(deserializing) { }
71    protected SymbolicExpressionTree(SymbolicExpressionTree original, Cloner cloner)
72      : base(original, cloner) {
73      root = cloner.Clone(original.Root);
74    }
75    public SymbolicExpressionTree() : base() { }
76    public SymbolicExpressionTree(ISymbolicExpressionTreeNode root)
77      : base() {
78      this.Root = root;
79    }
80
81    public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesBreadth() {
82      if (root == null)
83        return Enumerable.Empty<SymbolicExpressionTreeNode>();
84      return root.IterateNodesBreadth();
85    }
86
87    public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPrefix() {
88      if (root == null)
89        return Enumerable.Empty<SymbolicExpressionTreeNode>();
90      return root.IterateNodesPrefix();
91    }
92    public IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix() {
93      if (root == null)
94        return Enumerable.Empty<SymbolicExpressionTreeNode>();
95      return root.IterateNodesPostfix();
96    }
97
98    public override IDeepCloneable Clone(Cloner cloner) {
99      return new SymbolicExpressionTree(this, cloner);
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.