Changeset 11233


Ignore:
Timestamp:
07/30/14 01:41:54 (8 years ago)
Author:
bburlacu
Message:

#1772: Worked towards integrating the new graph api with the tracking operators.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
23 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs

    r11227 r11233  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using HeuristicLab.Analysis;
     
    268269        #region add elite in the graph and connect it with the previous elite
    269270        if (elite != null) {
    270           var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.GetVertex(elite);
     271          var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.GetByContent(elite);
    271272          prevVertex.IsElite = true; // mark elites in the graph retroactively
    272273
    273274          var clone = (T)elite.Clone();
    274275
    275           var vertex = new GenealogyGraphNode<T>(prevVertex.Content) {
     276          var v = new GenealogyGraphNode<T>(prevVertex.Content) {
    276277            Rank = generation,
    277278            Quality = prevVertex.Quality,
     
    279280          };
    280281
    281           prevVertex.Content = clone;
     282          var w = new GenealogyGraphNode<T>(clone) {
     283            Rank = generation - 1,
     284            Quality = prevVertex.Quality,
     285            IsElite = true
     286          };
     287
     288          // replace previous elite with vertex w
     289          List<IGenealogyGraphNode<T>> parents = null;
     290          object data = null;
     291          if (prevVertex.InArcs.Any()) {
     292            data = prevVertex.InArcs.Last().Data;
     293            parents = prevVertex.InArcs.Select(x => (IGenealogyGraphNode<T>)x.Source).ToList();
     294            //            v.InArcs.Last().Data = prevVertex.InArcs.Last().Data; // save the fragment in case there is one
     295            //            var p = prevVertex.InArcs.First().Source;
     296            //            GenealogyGraph.AddArc(p, w);
     297          }
     298          GenealogyGraph.RemoveVertex(prevVertex);
     299          GenealogyGraph.AddVertex(w);
     300          GenealogyGraph.AddVertex(v);
     301          GenealogyGraph.AddArc(w, v); // connect current elite with previous elite
     302
     303          v.InArcs.Last().Data = data;
     304          if (parents != null) {
     305            foreach (var p in parents)
     306              GenealogyGraph.AddArc(p, w);
     307          }
     308
    282309          // inject the graph node unique id to the scope
    283           ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(vertex.Id);
    284           GenealogyGraph.AddVertex(vertex);
    285           GenealogyGraph.AddArc(prevVertex, vertex); // connect current elite with previous elite
    286 
    287           if (prevVertex.InArcs.Any()) {
    288             vertex.InArcs.Last().Data = prevVertex.InArcs.Last().Data; // save the fragment in case there is one
    289           }
     310          ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(v.Id);
    290311        }
    291312        #endregion
     
    295316      // update qualities
    296317      for (int i = 0; i < population.Length; ++i) {
    297         var vertex = (IGenealogyGraphNode)GenealogyGraph.GetVertex(population[i]);
     318        var vertex = (IGenealogyGraphNode)GenealogyGraph.GetByContent(population[i]);
    298319        vertex.Quality = qualities[i].Value;
    299320      }
     
    301322      // remove extra graph nodes (added by the instrumented operators in the case of offspring selection)
    302323      var discardedOffspring = GenealogyGraph.Ranks[generation].Select(x => (T)x.Content).Except(population).ToList();
    303       foreach (var vertex in discardedOffspring.Select(individual => GenealogyGraph.GetVertex(individual))) {
     324      foreach (var vertex in discardedOffspring.Select(individual => GenealogyGraph.GetByContent(individual))) {
    304325        GenealogyGraph.RemoveVertex(vertex);
    305326      }
     
    313334      // compute the weight of each genealogy graph node as the ratio (produced offspring) / (surviving offspring)
    314335      foreach (var ind in population) {
    315         var v = (IGenealogyGraphNode)GenealogyGraph.GetVertex(ind);
     336        var v = (IGenealogyGraphNode)GenealogyGraph.GetByContent(ind);
    316337        foreach (var p in v.Parents)
    317338          p.Weight++;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Arc.cs

    r11229 r11233  
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2626
    27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     27namespace HeuristicLab.EvolutionTracking {
    2828  /// <summary>
    2929  /// An arc that can have a weight, a label, and a data object for holding additional info
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/DirectedGraph.cs

    r11229 r11233  
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2929
    30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     30namespace HeuristicLab.EvolutionTracking {
    3131  [Item("DirectedGraph", "Generic class representing a directed graph with custom vertices and content")]
    3232  [StorableClass]
     
    9494      vertex.ArcAdded += OnArcAdded;
    9595      vertex.ArcRemoved += OnArcRemoved;
    96       OnVertexAdded(this, EventArgs.Empty);
    9796    }
    9897
     
    106105      vertex.ArcRemoved -= OnArcRemoved;
    107106      vertex.Changed -= OnVertexChanged;
    108       OnVertexRemoved(this, EventArgs.Empty);
    109107    }
    110108
    111     public IArc AddArc(IVertex source, IVertex target) {
     109    public virtual IArc AddArc(IVertex source, IVertex target) {
    112110      var arc = new Arc(source, target);
    113111      AddArc(arc);
     
    131129    }
    132130
    133     public event EventHandler VertexAdded;
    134     protected virtual void OnVertexAdded(object sender, EventArgs args) {
    135       var added = VertexAdded;
    136       if (added != null)
    137         added(sender, args);
    138     }
    139131
    140     public event EventHandler VertexChanged;
    141     protected virtual void OnVertexChanged(object sender, EventArgs args) {
    142       var changed = VertexChanged;
    143       if (changed != null)
    144         changed(sender, args);
    145     }
    146 
    147     public event EventHandler VertexRemoved;
    148     protected virtual void OnVertexRemoved(object sender, EventArgs args) {
    149       var removed = VertexRemoved;
    150       if (removed != null)
    151         removed(sender, args);
    152     }
     132    protected virtual void OnVertexChanged(object sender, EventArgs args) { }
    153133
    154134    protected virtual void OnArcAdded(object sender, EventArgs<IArc> args) {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IArc.cs

    r11229 r11233  
    2323using HeuristicLab.Core;
    2424
    25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     25namespace HeuristicLab.EvolutionTracking {
    2626  public interface IArc : IItem {
    2727    event EventHandler Changed; // generic event for when the label, weight or data were changed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IDirectedGraph.cs

    r11229 r11233  
    2323using HeuristicLab.Core;
    2424
    25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     25namespace HeuristicLab.EvolutionTracking {
    2626  public interface IDirectedGraph : IItem {
    2727    void Clear();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IVertex.cs

    r11229 r11233  
    2525using HeuristicLab.Core;
    2626
    27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     27namespace HeuristicLab.EvolutionTracking {
    2828  public interface IVertex : IItem {
    2929    event EventHandler Changed; // generic event for when the content, label or weight have changed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Vertex.cs

    r11229 r11233  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     29namespace HeuristicLab.EvolutionTracking {
    3030  [StorableClass]
    3131  public class Vertex : Item, IVertex {
     
    126126        if (outArcs == null)
    127127          outArcs = new List<IArc>();
    128         else if (outArcs.Contains(arc) || outArcs.Any(a => a.Target == arc.Target && a.Source == arc.Source))
     128        else if (outArcs.Contains(arc) || outArcs.Any(a => a.Target == arc.Target))
    129129          throw new InvalidOperationException("Arc already added.");
    130130        outArcs.Add(arc);
     
    132132        if (inArcs == null)
    133133          inArcs = new List<IArc>();
    134         else if (inArcs.Contains(arc) || inArcs.Any(a => a.Target == arc.Target && a.Source == arc.Source))
     134        else if (inArcs.Contains(arc) || inArcs.Any(a => a.Source == arc.Source))
    135135          throw new InvalidOperationException("Arc already added.");
    136136        inArcs.Add(arc);
     
    175175    }
    176176
     177    public Vertex(object content) : base(content) { }
     178
    177179    [StorableConstructor]
    178180    protected Vertex(bool deserializing) : base(deserializing) { }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs

    r10903 r11233  
    3232  public class GenealogyGraph : DirectedGraph, IGenealogyGraph {
    3333    [Storable]
     34    private readonly Dictionary<object, IGenealogyGraphNode> contentMap;
     35
     36    [Storable]
     37    private readonly Dictionary<string, IGenealogyGraphNode> idMap;
     38
     39    [Storable]
    3440    private Dictionary<double, List<IGenealogyGraphNode>> ranks; // use a linked list for fast insertion/removal
    3541    public Dictionary<double, List<IGenealogyGraphNode>> Ranks {
     
    3743      set { ranks = value; }
    3844    }
    39     public new IEnumerable<IGenealogyGraphNode> Vertices {
    40       get { return from n in base.Vertices select (IGenealogyGraphNode)n; }
    41     }
    4245
    4346    protected GenealogyGraph(GenealogyGraph original, Cloner cloner)
    4447      : base(original, cloner) {
    4548      Ranks = new Dictionary<double, List<IGenealogyGraphNode>>(original.Ranks);
    46     }
     49      contentMap = new Dictionary<object, IGenealogyGraphNode>(original.contentMap);
     50      idMap = new Dictionary<string, IGenealogyGraphNode>(original.idMap);
     51    }
     52
    4753    public override IDeepCloneable Clone(Cloner cloner) {
    4854      return new GenealogyGraph(this, cloner);
    4955    }
     56
    5057    [StorableConstructor]
    5158    protected GenealogyGraph(bool deserializing) : base(deserializing) { }
    5259    public GenealogyGraph() {
    5360      Ranks = new Dictionary<double, List<IGenealogyGraphNode>>();
     61      contentMap = new Dictionary<object, IGenealogyGraphNode>();
     62      idMap = new Dictionary<string, IGenealogyGraphNode>();
     63    }
     64
     65    public new IEnumerable<IGenealogyGraphNode> Vertices {
     66      get { return from n in base.Vertices select (IGenealogyGraphNode)n; }
    5467    }
    5568
    5669    public override IArc AddArc(IVertex source, IVertex target) {
    5770      var arc = new GenealogyGraphArc((IGenealogyGraphNode)source, (IGenealogyGraphNode)target);
    58       source.AddForwardArc(arc);
    59       target.AddReverseArc(arc);
     71      source.AddArc(arc);
     72      target.AddArc(arc);
    6073      arcs.Add(arc);
    6174      return arc;
     
    6881        Ranks[node.Rank] = new List<IGenealogyGraphNode>();
    6982      Ranks[node.Rank].Add(node);
    70     }
     83
     84      if (contentMap.ContainsKey(node.Content))
     85        throw new InvalidOperationException("Duplicate content is not allowed in the genealogy graph.");
     86      contentMap[node.Content] = node;
     87
     88      if (idMap.ContainsKey(node.Id))
     89        throw new InvalidOperationException("Duplicate content is not allowed in the genealogy graph.");
     90      idMap[node.Id] = node;
     91
     92      vertex.Changed += OnVertexChanged;
     93    }
     94
    7195    public override void RemoveVertex(IVertex vertex) {
    7296      var node = (IGenealogyGraphNode)vertex;
     97      contentMap.Remove(node.Content);
     98      idMap.Remove(node.Id);
    7399      if (Ranks.ContainsKey(node.Rank)) {
    74100        Ranks[node.Rank].Remove(node);
     
    76102      base.RemoveVertex(vertex);
    77103    }
     104
     105    public IGenealogyGraphNode GetByContent(object content) {
     106      IGenealogyGraphNode result;
     107      contentMap.TryGetValue(content, out result);
     108      return result;
     109    }
     110
     111    public IGenealogyGraphNode GetById(string id) {
     112      IGenealogyGraphNode result;
     113      idMap.TryGetValue(id, out result);
     114      return result;
     115    }
     116
     117    public bool Contains(object content) {
     118      return contentMap.ContainsKey(content);
     119    }
     120
    78121    public event EventHandler GraphUpdated;
    79122    private void OnGraphUpdated(object sender, EventArgs args) {
     
    86129      ranks.Clear();
    87130    }
     131
     132    protected override void OnVertexChanged(object sender, EventArgs args) {
     133      base.OnVertexChanged(sender, args);
     134
     135      var vertex = (IGenealogyGraphNode)sender;
     136      if (!contentMap.ContainsKey(vertex.Content)) {
     137        // vertex has received new content
     138      }
     139    }
    88140  }
    89141
     142  //  [StorableClass]
     143  //  [Item("GenealogyGraph", "A class representing a genealogy graph")]
     144  //  public class GenealogyGraph<T> : DirectedGraph, IGenealogyGraph<T> where T : class, IItem {
     145  //    // members and properties
     146  //    [Storable]
     147  //    private Dictionary<double, List<IGenealogyGraphNode>> ranks;
     148  //    public Dictionary<double, List<IGenealogyGraphNode>> Ranks {
     149  //      get { return ranks; }
     150  //      set { ranks = value; }
     151  //    }
     152  //    public new IEnumerable<IGenealogyGraphNode<T>> Vertices {
     153  //      get { return from n in base.Vertices select (IGenealogyGraphNode<T>)n; }
     154  //    }
     155  //    // contructors
     156  //    protected GenealogyGraph(GenealogyGraph<T> original, Cloner cloner)
     157  //      : base(original, cloner) {
     158  //    }
     159  //    public override IDeepCloneable Clone(Cloner cloner) {
     160  //      return new GenealogyGraph<T>(this, cloner);
     161  //    }
     162  //
     163  //    [StorableConstructor]
     164  //    protected GenealogyGraph(bool deserializing) : base(deserializing) { }
     165  //    public GenealogyGraph() {
     166  //      Ranks = new Dictionary<double, List<IGenealogyGraphNode>>();
     167  //    }
     168  //
     169  //    // methods
     170  //    public override void AddVertex(IVertex vertex) {
     171  //      base.AddVertex(vertex);
     172  //      var node = (IGenealogyGraphNode)vertex;
     173  //      if (!Ranks.ContainsKey(node.Rank)) {
     174  //        Ranks[node.Rank] = new List<IGenealogyGraphNode>();
     175  //      }
     176  //      Ranks[node.Rank].Add(node);
     177  //    }
     178  //
     179  //    public override void RemoveVertex(IVertex vertex) {
     180  //      var node = (IGenealogyGraphNode<T>)vertex;
     181  //      if (Ranks.ContainsKey(node.Rank)) {
     182  //        Ranks[node.Rank].Remove(node);
     183  //      }
     184  //      base.RemoveVertex(vertex);
     185  //    }
     186  //
     187  //    public override IArc AddArc(IVertex source, IVertex target) {
     188  //      var arc = new GenealogyGraphArc((IGenealogyGraphNode)source, (IGenealogyGraphNode)target);
     189  //      source.AddArc(arc);
     190  //      target.AddArc(arc);
     191  //      arcs.Add(arc);
     192  //      return arc;
     193  //    }
     194  //
     195  //    IEnumerable<IGenealogyGraphNode> IGenealogyGraph.Vertices {
     196  //      get { return Vertices; }
     197  //    }
     198  //
     199  //    public IGenealogyGraphNode GetByContent(object content)
     200  //    {
     201  //      IGenealogyGraphNode result;
     202  //      contentMap.
     203  //    }
     204  //
     205  //    public event EventHandler GraphUpdated;
     206  //    private void OnGraphUpdated(object sender, EventArgs args) {
     207  //      var updated = GraphUpdated;
     208  //      if (updated != null) updated(sender, args);
     209  //    }
     210  //  }
    90211  [StorableClass]
    91   [Item("GenealogyGraph", "A class representing a genealogy graph")]
    92   public class GenealogyGraph<T> : DirectedGraph, IGenealogyGraph<T> where T : class, IItem {
    93     // members and properties
    94     [Storable]
    95     private Dictionary<double, List<IGenealogyGraphNode>> ranks;
    96     public Dictionary<double, List<IGenealogyGraphNode>> Ranks {
    97       get { return ranks; }
    98       set { ranks = value; }
    99     }
     212
     213  [Item("GenealogyGraph", "A specialization of the genealogy graph with T as content for vertices")]
     214  public class GenealogyGraph<T> : GenealogyGraph, IGenealogyGraph<T> where T : class, IItem {
    100215    public new IEnumerable<IGenealogyGraphNode<T>> Vertices {
    101       get { return from n in base.Vertices select (IGenealogyGraphNode<T>)n; }
    102     }
    103     // contructors
    104     protected GenealogyGraph(GenealogyGraph<T> original, Cloner cloner)
    105       : base(original, cloner) {
    106     }
    107     public override IDeepCloneable Clone(Cloner cloner) {
    108       return new GenealogyGraph<T>(this, cloner);
    109     }
    110     [StorableConstructor]
    111     protected GenealogyGraph(bool deserializing) : base(deserializing) { }
    112     public GenealogyGraph() {
    113       Ranks = new Dictionary<double, List<IGenealogyGraphNode>>();
    114     }
    115     // methods
    116     public override void AddVertex(IVertex vertex) {
    117       base.AddVertex(vertex);
    118       var node = (IGenealogyGraphNode)vertex;
    119       if (!Ranks.ContainsKey(node.Rank)) {
    120         Ranks[node.Rank] = new List<IGenealogyGraphNode>();
    121       }
    122       Ranks[node.Rank].Add(node);
    123     }
    124     public override void RemoveVertex(IVertex vertex) {
    125       var node = (IGenealogyGraphNode<T>)vertex;
    126       if (Ranks.ContainsKey(node.Rank)) {
    127         Ranks[node.Rank].Remove(node);
    128       }
    129       base.RemoveVertex(vertex);
    130     }
    131     public override IArc AddArc(IVertex source, IVertex target) {
    132       var arc = new GenealogyGraphArc((IGenealogyGraphNode)source, (IGenealogyGraphNode)target);
    133       source.AddForwardArc(arc);
    134       target.AddReverseArc(arc);
    135       arcs.Add(arc);
    136       return arc;
    137     }
    138     IEnumerable<IGenealogyGraphNode> IGenealogyGraph.Vertices {
    139       get { return Vertices; }
    140     }
    141     public event EventHandler GraphUpdated;
    142     private void OnGraphUpdated(object sender, EventArgs args) {
    143       var updated = GraphUpdated;
    144       if (updated != null) updated(sender, args);
     216      get { return base.Vertices.Cast<IGenealogyGraphNode<T>>(); }
    145217    }
    146218  }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphArc.cs

    r10903 r11233  
    3333      : base(original, cloner) { }
    3434
    35     protected GenealogyGraphArc() { }
    36 
    37     public GenealogyGraphArc(IGenealogyGraphNode source, IGenealogyGraphNode target, object data = null) {
    38       Source = source;
    39       Target = target;
    40       Data = data;
     35    public GenealogyGraphArc(IGenealogyGraphNode source, IGenealogyGraphNode target)
     36      : base(source, target) {
    4137    }
    4238
     
    4743    public new IGenealogyGraphNode Source {
    4844      get { return (IGenealogyGraphNode)base.Source; }
    49       set { base.Source = value; }
    5045    }
    5146
    5247    public new IGenealogyGraphNode Target {
    5348      get { return (IGenealogyGraphNode)base.Target; }
    54       set { base.Target = value; }
    5549    }
    5650  }
     
    6357    protected GenealogyGraphArc(GenealogyGraphArc<T> original, Cloner cloner)
    6458      : base(original, cloner) {
    65       Data = (T)original.Data;
     59      Data = original.Data;
    6660    }
    6761
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs

    r10897 r11233  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    3940    }
    4041
    41     public GenealogyGraphNode() { }
    42     public GenealogyGraphNode(object content) : base(content) { }
     42    public GenealogyGraphNode(object content)
     43      : base(content) {
     44      Id = Guid.NewGuid().ToString();
     45    }
    4346
    4447    public new IEnumerable<IGenealogyGraphArc> InArcs {
    4548      get { return base.InArcs.Cast<IGenealogyGraphArc>(); }
    46       set { base.InArcs = value; }
    4749    }
    4850    public new IEnumerable<IGenealogyGraphArc> OutArcs {
    4951      get { return base.OutArcs.Cast<IGenealogyGraphArc>(); }
    50       set { base.OutArcs = value; }
    5152    }
    5253    public IEnumerable<IGenealogyGraphNode> Ancestors {
     
    8889    }
    8990    [Storable]
     91    public string Id { get; private set; }
     92
     93    [Storable]
    9094    private double rank;
    9195    public double Rank {
     
    124128    }
    125129
    126     public GenealogyGraphNode() { }
    127130    public GenealogyGraphNode(object content) : base(content) { }
    128131
    129132    protected GenealogyGraphNode(GenealogyGraphNode<T> original, Cloner cloner)
    130133      : base(original, cloner) {
     134      // we do not clone the content
    131135      Content = original.Content;
    132136    }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraph.cs

    r10903 r11233  
    2727    Dictionary<double, List<IGenealogyGraphNode>> Ranks { get; }
    2828    new IEnumerable<IGenealogyGraphNode> Vertices { get; }
     29    IGenealogyGraphNode GetByContent(object content);
     30    IGenealogyGraphNode GetById(string id);
     31    bool Contains(object content);
    2932  }
    3033
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraphArc.cs

    r10888 r11233  
    2020#endregion
    2121
    22 using HeuristicLab.Core;
    23 
    2422namespace HeuristicLab.EvolutionTracking {
    2523  public interface IGenealogyGraphArc : IArc {
    26     new IGenealogyGraphNode Source { get; set; }
    27     new IGenealogyGraphNode Target { get; set; }
    28   }
    29 
    30   public interface IGenealogyGraphArc<T> : IGenealogyGraphArc where T : class, IItem {
    31     new T Data { get; set; }
     24    new IGenealogyGraphNode Source { get; }
     25    new IGenealogyGraphNode Target { get; }
    3226  }
    3327}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraphNode.cs

    r10890 r11233  
    2828    double Quality { get; set; }
    2929    bool IsElite { get; set; }
     30    string Id { get; }
    3031
    3132    IEnumerable<IGenealogyGraphNode> Parents { get; }
     
    3334    IEnumerable<IGenealogyGraphNode> Ancestors { get; }
    3435    IEnumerable<IGenealogyGraphNode> Descendants { get; }
    35     new IEnumerable<IGenealogyGraphArc> InArcs { get; set; }
    36     new IEnumerable<IGenealogyGraphArc> OutArcs { get; set; }
     36    new IEnumerable<IGenealogyGraphArc> InArcs { get; }
     37    new IEnumerable<IGenealogyGraphArc> OutArcs { get; }
    3738  }
    3839
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs

    r11227 r11233  
    7676
    7777      var subScopes = ExecutionContext.Scope.SubScopes;
    78       var parentVertices = subScopes.Select(x => (GenealogyGraphNode<T>)GenealogyGraph.GetVertex(getScopeId(x))).ToList();
     78      var parentVertices = subScopes.Select(x => (GenealogyGraphNode<T>)GenealogyGraph.GetById(getScopeId(x))).ToList();
    7979
    8080      var parents = ParentsParameter.ActualValue.ToList();
     
    8484      GenealogyGraph.AddVertex(childVertex);
    8585
    86       foreach (var parentVertex in parentVertices) {
     86      foreach (var parentVertex in parentVertices.Distinct()) {
    8787        GenealogyGraph.AddArc(parentVertex, childVertex);
    8888      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs

    r11227 r11233  
    2020#endregion
    2121
    22 using System.Linq;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    3938      : base(original, cloner) {
    4039    }
     40
    4141    public override IDeepCloneable Clone(Cloner cloner) {
    4242      return new BeforeManipulatorOperator<T>(this, cloner);
    4343    }
     44
    4445    [StorableConstructor]
    4546    protected BeforeManipulatorOperator(bool deserializing) : base(deserializing) { }
     
    5152    public override IOperation Apply() {
    5253      // since mutation always takes place after crossover, the vertex for the current child is already in the tree
    53       var v = (IGenealogyGraphNode<T>)GenealogyGraph.GetVertex(ChildParameter.ActualValue);
     54      var v = (IGenealogyGraphNode<T>)GenealogyGraph.GetByContent(ChildParameter.ActualValue);
    5455      var clone = (T)ChildParameter.ActualValue.Clone();
    5556
    5657      var c = new GenealogyGraphNode<T>(clone) { Rank = v.Rank - 0.5 };
    5758
    58       foreach (var a in v.InArcs) {
    59         a.Target = c;
    60         c.AddReverseArc(a);
     59      foreach (var arc in v.InArcs) {
     60        var p = arc.Source;
     61        GenealogyGraph.RemoveArc(arc);
     62        GenealogyGraph.AddArc(new GenealogyGraphArc(p, c));
    6163      }
    6264
    63       v.InArcs = Enumerable.Empty<IGenealogyGraphArc>();
     65      //      foreach (var a in v.InArcs) {
     66      //        a.Target = c;
     67      //        c.AddReverseArc(a);
     68      //      }
     69
     70      //      v.InArcs = Enumerable.Empty<IGenealogyGraphArc>();
    6471
    6572      GenealogyGraph.AddVertex(c);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymboldDataAnalysisGenealogyView.cs

    r11015 r11233  
    109109        var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer));
    110110
    111         var matchingVertices = matchingTrees.Select(x => Content.GetVertex(x)).Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>();
     111        var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x)).Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>();
    112112        graphChart_highlightMatchingVertices(matchingVertices);
    113113      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r11232 r11233  
    176176    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" />
    177177    <Compile Include="Analyzers\SymbolicDataAnalysisGenealogyAnalyzer.cs" />
    178     <Compile Include="Analyzers\SymbolicDataAnalysisPopulationDiversityAnalyzer.cs" />
    179178    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" />
    180179    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs" />
     
    190189      <SubType>Code</SubType>
    191190    </Compile>
    192     <Compile Include="DirectedGraph\Arc.cs" />
    193     <Compile Include="DirectedGraph\DirectedGraph.cs" />
    194     <Compile Include="DirectedGraph\Interfaces\IArc.cs" />
    195     <Compile Include="DirectedGraph\Interfaces\IDirectedGraph.cs" />
    196     <Compile Include="DirectedGraph\Interfaces\IVertex.cs" />
    197     <Compile Include="DirectedGraph\Vertex.cs" />
    198191    <Compile Include="Interfaces\IModelBacktransformator.cs" />
    199192    <Compile Include="Interfaces\IDistanceCalculator.cs" />
     
    213206    <Compile Include="SlidingWindow\SlidingWindowQualitiesAnalyzer.cs" />
    214207    <Compile Include="SlidingWindow\SlidingWindowVisualizer.cs" />
    215     <Compile Include="SymbolGraph\FPGraph.cs" />
    216     <Compile Include="SymbolGraph\SymbolGraph.cs" />
    217208    <Compile Include="SymbolicDataAnalysisExpressionPruningOperator.cs" />
    218209    <Compile Include="SymbolicDataAnalysisExpressionTreeSimilarityCalculator.cs" />
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r11232 r11233  
    235235      Operators.Add(new SingleObjectivePopulationDiversityAnalyzer());
    236236      Operators.Add(new BottomUpSimilarityCalculator());
     237      Operators.Add(new SymbolicDataAnalysisGenealogyAnalyzer());
    237238      ParameterizeOperators();
    238239    }
     
    361362        op.SimilarityCalculator = operators.OfType<BottomUpSimilarityCalculator>().SingleOrDefault();
    362363      }
     364      // add tracking analyzer
     365      foreach (var op in operators.OfType<SymbolicDataAnalysisGenealogyAnalyzer>()) {
     366        op.BeforeCrossoverOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionBeforeCrossoverOperator();
     367        op.AfterCrossoverOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionAfterCrossoverOperator();
     368        op.BeforeManipulatorOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionBeforeManipulatorOperator();
     369        op.AfterManipulatorOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionAfterManipulatorOperator();
     370        // get crossover parameter names
     371        var crossover = operators.OfType<ISymbolicExpressionTreeCrossover>().FirstOrDefault();
     372        if (crossover != null) {
     373          op.BeforeCrossoverOperator.ParentsParameter.ActualName = crossover.ParentsParameter.Name;
     374          op.AfterCrossoverOperator.ParentsParameter.ActualName = crossover.ParentsParameter.Name;
     375          op.BeforeCrossoverOperator.ChildParameter.ActualName = crossover.ChildParameter.Name;
     376          op.AfterCrossoverOperator.ChildParameter.ActualName = crossover.ChildParameter.Name;
     377        }
     378        // get manipulator parameter names
     379        var manipulator = operators.OfType<ISymbolicExpressionTreeManipulator>().FirstOrDefault();
     380        if (manipulator != null) {
     381          op.BeforeManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name;
     382          op.AfterManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name;
     383        }
     384        var creator = operators.OfType<ISymbolicExpressionTreeCreator>().FirstOrDefault();
     385        if (creator != null) {
     386          op.PopulationParameter.ActualName = creator.SymbolicExpressionTreeParameter.ActualName;
     387        }
     388      }
    363389    }
    364390
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs

    r10897 r11233  
    3030  public class SymbolicDataAnalysisExpressionAfterCrossoverOperator : AfterCrossoverOperator<ISymbolicExpressionTree> {
    3131    public override IOperation Apply() {
    32       var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetVertex(ChildParameter.ActualValue);
     32      var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetByContent(ChildParameter.ActualValue);
    3333      var arcs = childVertex.InArcs.ToList();
    3434      var nodes0 = (List<ISymbolicExpressionTreeNode>)arcs[0].Data;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs

    r10897 r11233  
    4040
    4141    public override IOperation Apply() {
    42       var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetVertex(ChildParameter.ActualValue);
     42      var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetByContent(ChildParameter.ActualValue);
    4343      var nodesBefore = (List<ISymbolicExpressionTreeNode>)vChild.InArcs.First().Data;
    4444      var nodesAfter = ChildParameter.ActualValue.IterateNodesPrefix().ToList();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs

    r10897 r11233  
    3030      var result = base.Apply(); // the base operator will add the child to the graph before the actual crossover operation takes place
    3131      var parents = ParentsParameter.ActualValue.ToList();
    32       var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetVertex(parents[0]); // use the parent since it is actually the child before crossover (and the ChildParameter doesn't have a value yet)
     32      var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetByContent(parents[0]); // use the parent since it is actually the child before crossover (and the ChildParameter doesn't have a value yet)
    3333      var arcs = childVertex.InArcs.ToList();
    3434
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs

    r10897 r11233  
    3030      var result = base.Apply(); // add the vertex in the genealogy graph
    3131
    32       var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetVertex(ChildParameter.ActualValue);
     32      var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetByContent(ChildParameter.ActualValue);
    3333      var vClone = vChild.Parents.Last();
    3434      vChild.InArcs.First().Data = vClone.Content.IterateNodesPrefix().ToList();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs

    r10888 r11233  
    3030  public static class SymbolicDataAnalysisExpressionTracing {
    3131    public static FragmentGraph TraceSubtree(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, int subtreeIndex) {
    32       var graph = new FragmentGraph { AllowDuplicateContent = true };
     32      var graph = new FragmentGraph();
    3333      var nodes = Trace(graphNode, subtreeIndex);
    3434      foreach (var n in nodes) {
     
    5151      while (true) {
    5252        if (!node.Parents.Any()) {
    53           var fragmentNode = new FragmentNode {
    54             Content = node,
     53          var fragmentNode = new FragmentNode(node) {
    5554            SubtreeIndex = index,
    5655          };
    5756          if (parent != null) {
    5857            var arc = new Arc(parent, fragmentNode);
    59             parent.AddForwardArc(arc);
    60             fragmentNode.AddReverseArc(arc);
     58            parent.AddArc(arc);
     59            fragmentNode.AddArc(arc);
     60
     61            //            parent.AddForwardArc(arc);
     62            //            fragmentNode.AddReverseArc(arc);
    6163          }
    6264          yield return fragmentNode; // no tracing if there are no parents
     
    7981        if (parents.Count == 1) {
    8082          // we are tracing a mutation operation
    81           var fragmentNode = new FragmentNode {
    82             Content = node,
     83          var fragmentNode = new FragmentNode(node) {
    8384            SubtreeIndex = index,
    8485            FragmentIndex = fragment.Index1
     
    8687          if (parent != null) {
    8788            var arc = new Arc(parent, fragmentNode);
    88             parent.AddForwardArc(arc);
    89             fragmentNode.AddReverseArc(arc);
     89            parent.AddArc(arc);
     90            fragmentNode.AddArc(arc);
    9091          }
    9192          node = parents[0];
     
    138139            if (fragment.Index1 < index + subtreeLength) {
    139140              // subtree contains fragment => bifurcation point in the fragment graph
    140               var fragmentNode = new FragmentNode {
    141                 Content = node,
     141              var fragmentNode = new FragmentNode(node) {
    142142                SubtreeIndex = index,
    143143                FragmentIndex = fragment.Index1
     
    145145              if (parent != null) {
    146146                var arc = new Arc(parent, fragmentNode);
    147                 parent.AddForwardArc(arc);
    148                 fragmentNode.AddReverseArc(arc);
     147                parent.AddArc(arc);
     148                fragmentNode.AddArc(arc);
    149149              }
    150150              yield return fragmentNode;
Note: See TracChangeset for help on using the changeset viewer.