Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/02/13 13:18:57 (11 years ago)
Author:
bburlacu
Message:

#1772: Refactoring of directed graph components, added code for correctly serializing vertices and edges. Added specific building blocks analyzers and new population diversity analyzer which correctly integrates with the parallel engine.

Location:
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/GenericGraph
Files:
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/GenericGraph/Vertex.cs

    r9247 r9419  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
     25using HeuristicLab.Core;
    2426using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2527
    2628namespace HeuristicLab.EvolutionaryTracking {
    2729  [StorableClass]
    28   public class Vertex : IVertex {
    29     public string Id { get; private set; }
    30     public string Label { get; set; }
    31     public double Weight { get; set; }
    32     public List<Arc> InEdges { get; private set; }
    33     public List<Arc> OutEdges { get; private set; }
    34     private object content;
     30  public class Vertex : Item, IVertex
     31  {
     32    [Storable]
     33    private string id;
     34    public string Id { get { return id; } }
     35    [Storable] private string label;
     36    public string Label { get { return label; } set { label = value; } }
     37    [Storable] private double weight;
     38    public double Weight { get { return weight; } set { weight = value; } }
     39    [Storable] private List<IEdge> inEdges;
     40    public List<IEdge> InEdges { get { return inEdges; } private set { inEdges = value; } }
     41    [Storable] private List<IEdge> outEdges;
     42    public List<IEdge> OutEdges { get { return outEdges; }private set { outEdges = value; }}
     43    [Storable] private object content;
    3544    public object Content {
    3645      get { return content; }
     
    4352
    4453    [StorableConstructor]
    45     public Vertex(bool deserializing) { }
     54    public Vertex(bool deserializing) : base(deserializing) { }
    4655
    4756    public Vertex() {
    48       Id = Guid.NewGuid().ToString();
     57      id = Guid.NewGuid().ToString();
     58    }
     59
     60    [StorableHook(HookType.AfterDeserialization)]
     61    private void AfterDeserialization()
     62    {
     63      if (id == null) {
     64        id = Guid.NewGuid().ToString();
     65      }
     66    }
     67
     68    protected Vertex(Vertex original, Cloner cloner)
     69      : base(original, cloner) {
     70      Content = original.Content;
     71      id = Guid.NewGuid().ToString();
     72      Label = original.Label;
     73      Content = original.Content;
     74      InEdges = new List<IEdge>(original.InEdges);
     75      OutEdges = new List<IEdge>(original.OutEdges);
     76    }
     77
     78    public override IDeepCloneable Clone(Cloner cloner) {
     79      return new Vertex(this, cloner);
    4980    }
    5081
    5182    public Vertex(Vertex node) {
    52       Id = Guid.NewGuid().ToString();
     83      id = Guid.NewGuid().ToString();
    5384      Label = node.Label;
    5485      Content = node.Content;
    55       InEdges = new List<Arc>(node.InEdges);
    56       OutEdges = new List<Arc>(node.OutEdges);
     86      InEdges = new List<IEdge>(node.InEdges);
     87      OutEdges = new List<IEdge>(node.OutEdges);
    5788    }
    5889
     
    108139    public void AddForwardArc(IVertex target, double weight = 0.0, object data = null) {
    109140      var e = new Arc { Source = this, Target = target, Data = data, Weight = weight };
    110       if (OutEdges == null) OutEdges = new List<Arc> { e };
     141      if (OutEdges == null) OutEdges = new List<IEdge> { e };
    111142      else OutEdges.Add(e);
    112143    }
    113     public void AddForwardArc(Arc arc) {
     144    public void AddForwardArc(IEdge arc) {
    114145      if (arc.Source == null) { arc.Source = this; }
    115146      if (arc.Source != this) { throw new Exception("AddForwardArc: Source should be equal to this."); }
    116       if (OutEdges == null) { OutEdges = new List<Arc> { arc }; } else { OutEdges.Add(arc); }
     147      if (OutEdges == null) { OutEdges = new List<IEdge> { arc }; } else { OutEdges.Add(arc); }
    117148    }
    118     public void AddReverseArc(Arc arc) {
     149    public void AddReverseArc(IEdge arc) {
    119150      if (arc.Target == null) { arc.Target = this; }
    120151      if (arc.Target != this) { throw new Exception("AddReverseArc: Target should be equal to this."); };
    121       if (InEdges == null) { InEdges = new List<Arc> { arc }; } else { InEdges.Add(arc); }
     152      if (InEdges == null) { InEdges = new List<IEdge> { arc }; } else { InEdges.Add(arc); }
    122153    }
    123154    public void AddReverseArc(IVertex source, double weight = 0.0, object data = null) {
    124155      var e = new Arc { Source = source, Target = this, Data = data, Weight = weight };
    125       if (InEdges == null) InEdges = new List<Arc> { e };
     156      if (InEdges == null) InEdges = new List<IEdge> { e };
    126157      else InEdges.Add(e);
    127158    }
Note: See TracChangeset for help on using the changeset viewer.