[9835] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2013 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 HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 25 |
|
---|
| 26 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
|
---|
| 27 | [Item("Fragment", "Class that represents a tree fragment")]
|
---|
| 28 | [StorableClass]
|
---|
| 29 | public class Fragment : Item, IFragment {
|
---|
| 30 | [Storable]
|
---|
| 31 | private ISymbolicExpressionTreeNode root;
|
---|
| 32 | public ISymbolicExpressionTreeNode Root { get { return root; } set { root = value; } }
|
---|
| 33 | [Storable]
|
---|
| 34 | private int index = -1;
|
---|
| 35 | public int Index { get { return index; } set { index = value; } }
|
---|
| 36 | [Storable]
|
---|
| 37 | private int oldIndex = -1;
|
---|
| 38 | public int OldIndex { get { return oldIndex; } set { oldIndex = value; } }
|
---|
| 39 |
|
---|
| 40 | private int length = -1;
|
---|
| 41 | public int Length {
|
---|
| 42 | get {
|
---|
| 43 | if (Root == null) return 0;
|
---|
| 44 | if (length == -1) length = Root.GetLength();
|
---|
| 45 | return length;
|
---|
| 46 | }
|
---|
| 47 | set { length = value; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | [StorableConstructor]
|
---|
| 51 | private Fragment(bool serializing) : base(serializing) { }
|
---|
| 52 | private Fragment(Fragment original, Cloner cloner)
|
---|
| 53 | : base(original, cloner) {
|
---|
| 54 | // avoid deep copy of the symbolic expression tree node
|
---|
| 55 | Root = original.Root;
|
---|
| 56 | Length = original.Length;
|
---|
| 57 | Index = original.Index;
|
---|
[9996] | 58 | OldIndex = original.OldIndex;
|
---|
[9835] | 59 | }
|
---|
| 60 |
|
---|
| 61 | public Fragment() { }
|
---|
| 62 |
|
---|
| 63 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 64 | return new Fragment(this, cloner);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | } |
---|