Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2582 created branch for Hive Web Job Manager

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