Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/SymbolicExpressionTreeGenealogyGraph/SymbolicExpressionTreeGenealogyGraphNode.cs @ 9963

Last change on this file since 9963 was 9963, checked in by bburlacu, 11 years ago

#1772: Merged changes from the trunk and other branches. Added new ExtendedSymbolicExpressionTreeCanvas control for the visual exploration of tree genealogies. Reorganized some files and folders.

File size: 2.7 KB
Line 
1
2using System;
3using System.Collections.Generic;
4using System.Linq;
5using HeuristicLab.Common;
6using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9namespace HeuristicLab.EvolutionaryTracking {
10  [StorableClass]
11  public class SymbolicExpressionTreeGenealogyGraphNode : Vertex {
12    public ISymbolicExpressionTree SymbolicExpressionTree {
13      get { return (ISymbolicExpressionTree)Content; }
14      set { Content = value; }
15    }
16
17    [Storable]
18    private double quality;
19    public double Quality { get { return quality; } set { quality = value; } }
20    [Storable]
21    private bool isElite;
22    public bool IsElite { get { return isElite; } set { isElite = value; } }
23    [Storable]
24    private double rank;
25    public double Rank { get { return rank; } set { rank = value; } }
26
27    [StorableHook(HookType.AfterDeserialization)]
28    private void AfterDeserialization() {
29      if (Id == null) throw new Exception();
30    }
31
32    [StorableConstructor]
33    public SymbolicExpressionTreeGenealogyGraphNode(bool deserializing)
34      : base(deserializing) {
35    }
36
37    public SymbolicExpressionTreeGenealogyGraphNode() {
38    }
39
40    private SymbolicExpressionTreeGenealogyGraphNode(SymbolicExpressionTreeGenealogyGraphNode original, Cloner cloner)
41      : base(original, cloner) {
42      Quality = original.Quality;
43      IsElite = original.IsElite;
44      Rank = original.Rank;
45    }
46
47    public override IDeepCloneable Clone(Cloner cloner) {
48      return new SymbolicExpressionTreeGenealogyGraphNode(this, cloner);
49    }
50
51    public new IEnumerable<SymbolicExpressionTreeGenealogyGraphNode> Ancestors() {
52      return base.Ancestors().Cast<SymbolicExpressionTreeGenealogyGraphNode>();
53    }
54
55    public new IEnumerable<SymbolicExpressionTreeGenealogyGraphNode> Descendants() {
56      return base.Descendants().Cast<SymbolicExpressionTreeGenealogyGraphNode>();
57    }
58
59    public IEnumerable<SymbolicExpressionTreeGenealogyGraphNode> RootLineage() {
60      var lineage = new List<SymbolicExpressionTreeGenealogyGraphNode> { this };
61      int i = 0;
62      while (i != lineage.Count) {
63        if (lineage[i].InEdges != null) {
64          lineage.Add((SymbolicExpressionTreeGenealogyGraphNode)lineage[i].InEdges[0].Source);
65        }
66        ++i;
67      }
68      return lineage;
69    }
70
71    public new List<Arc> InEdges {
72      get {
73        return base.InEdges == null ? null : base.InEdges.Cast<Arc>().ToList();
74      }
75    }
76
77    public new List<Arc> OutEdges {
78      get {
79        return base.OutEdges == null ? null : base.InEdges.Cast<Arc>().ToList();
80      }
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.