Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10903 for branches


Ignore:
Timestamp:
05/28/14 14:18:24 (11 years ago)
Author:
bburlacu
Message:

#1772: Removed Storable property from Vertex in- and outArcs as it causes a stack overflow exception during serialization. Added a list of arcs to the DirectedGraph class which is persisted. The Vertex in- and outArcs lists are then restored by the graph after the deserialization. Renamed Nodes data member to Vertices.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphChart.cs

    r10888 r10903  
    129129
    130130      // add arcs
    131       foreach (var node in GenealogyGraph.Nodes) {
     131      foreach (var node in GenealogyGraph.Vertices) {
    132132        if (!node.InArcs.Any()) continue;
    133133        var visualNode = GetMappedNode(node);
     
    246246      Chart.UpdateEnabled = false;
    247247      ClearPrimitives();
    248       var arcs = GenealogyGraph.Nodes.SelectMany(n => n.InArcs).ToList();
     248      var arcs = GenealogyGraph.Vertices.SelectMany(n => n.InArcs).ToList();
    249249      foreach (var arc in arcs) { arc.Weight = 1.0; } // reset weights
    250250      var rank = GenealogyGraph.Ranks.Keys.Max();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/DirectedGraph.cs

    r10897 r10903  
    3535
    3636    [Storable]
    37     private readonly List<IVertex> nodes; // for performance reasons, maybe this should be a linked list (fast remove)
    38     public IEnumerable<IVertex> Nodes {
    39       get { return nodes; }
     37    protected readonly List<IVertex> vertices; // for performance reasons, maybe this should be a linked list (fast remove)
     38    public IEnumerable<IVertex> Vertices {
     39      get { return vertices; }
    4040    }
    4141
     
    4646    private readonly Dictionary<object, IVertex> contentMap;
    4747
     48    [Storable]
     49    protected readonly List<IArc> arcs;
     50    public IEnumerable<IArc> Arcs {
     51      get { return arcs; }
     52    }
     53
    4854    [StorableConstructor]
    4955    protected DirectedGraph(bool serializing)
     
    5157    }
    5258
     59    [StorableHook(HookType.AfterDeserialization)]
     60    private void AfterDeserialization() {
     61      foreach (var arc in arcs) {
     62        arc.Source.AddForwardArc(arc);
     63        arc.Target.AddReverseArc(arc);
     64      }
     65
     66      foreach (var vertex in vertices) {
     67        vertex.PreContentChanged += Vertex_PreContentChanged;
     68        vertex.PostContentChanged += Vertex_PostContentChanged;
     69      }
     70    }
     71
    5372    public DirectedGraph() {
    54       nodes = new List<IVertex>();
     73      vertices = new List<IVertex>();
     74      arcs = new List<IArc>();
    5575      contentMap = new Dictionary<object, IVertex>();
    5676      idMap = new Dictionary<string, IVertex>();
     
    5979    protected DirectedGraph(DirectedGraph original, Cloner cloner)
    6080      : base(original, cloner) {
    61       nodes = new List<IVertex>(original.Nodes);
     81      vertices = new List<IVertex>(original.vertices);
     82      arcs = new List<IArc>(original.arcs);
    6283      contentMap = new Dictionary<object, IVertex>(original.contentMap);
    6384      idMap = new Dictionary<string, IVertex>(original.idMap);
     
    6990
    7091    public bool Contains(IVertex t) {
    71       return nodes.Contains(t);
     92      return vertices.Contains(t);
    7293    }
    7394
     
    89110
    90111    public virtual bool Any(Func<IVertex, bool> predicate) {
    91       return nodes.Any(predicate);
     112      return vertices.Any(predicate);
    92113    }
    93114
    94115    public virtual bool IsEmpty {
    95       get { return !nodes.Any(); }
     116      get { return !vertices.Any(); }
    96117    }
    97118
    98119    public virtual void Clear() {
    99       nodes.Clear();
     120      vertices.Clear();
    100121      contentMap.Clear();
    101122      idMap.Clear();
     
    110131      }
    111132      idMap.Add(vertex.Id, vertex);
    112       nodes.Add(vertex);
     133      vertices.Add(vertex);
    113134
    114135      vertex.PreContentChanged += Vertex_PreContentChanged;
     
    119140      contentMap.Remove(vertex.Content);
    120141      idMap.Remove(vertex.Id);
    121       nodes.Remove(vertex);
     142      vertices.Remove(vertex);
    122143
     144      // remove connections to/from the removed vertex
     145      foreach (var arc in vertex.InArcs) {
     146        arc.Source.OutArcs = arc.Source.OutArcs.Where(x => x.Target != vertex);
     147      }
     148      foreach (var arc in vertex.OutArcs) {
     149        arc.Target.InArcs = arc.Target.InArcs.Where(x => x.Source != vertex);
     150      }
     151      // de-register event handlers
    123152      vertex.PreContentChanged -= Vertex_PreContentChanged;
    124153      vertex.PostContentChanged -= Vertex_PostContentChanged;
     
    129158      source.AddForwardArc(arc);
    130159      target.AddReverseArc(arc);
     160      arcs.Add(arc);
    131161      return arc;
    132162    }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IDirectedGraph.cs

    r10897 r10903  
    3232    IArc AddArc(IVertex source, IVertex target);
    3333    void RemoveVertex(IVertex vertex);
    34     IEnumerable<IVertex> Nodes { get; }
     34    IEnumerable<IVertex> Vertices { get; }
    3535    bool Contains(object content);
    3636    IVertex GetVertex(string id);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Vertex.cs

    r10897 r10903  
    7070    }
    7171
    72     [Storable]
    7372    private List<IArc> inArcs;
    7473    public IEnumerable<IArc> InArcs {
     
    7776    }
    7877
    79     [Storable]
    8078    private List<IArc> outArcs;
    8179    public IEnumerable<IArc> OutArcs {
     
    111109
    112110    [StorableHook(HookType.AfterDeserialization)]
    113     protected void AfterDeserialization() {
     111    private void AfterDeserialization() {
    114112      if (Id == null) {
    115113        id = Guid.NewGuid().ToString();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs

    r10897 r10903  
    3737      set { ranks = value; }
    3838    }
    39     public new IEnumerable<IGenealogyGraphNode> Nodes {
    40       get { return from n in base.Nodes select (IGenealogyGraphNode)n; }
     39    public new IEnumerable<IGenealogyGraphNode> Vertices {
     40      get { return from n in base.Vertices select (IGenealogyGraphNode)n; }
    4141    }
    4242
     
    5858      source.AddForwardArc(arc);
    5959      target.AddReverseArc(arc);
     60      arcs.Add(arc);
    6061      return arc;
    6162    }
     
    9798      set { ranks = value; }
    9899    }
    99     public new IEnumerable<IGenealogyGraphNode<T>> Nodes {
    100       get { return from n in base.Nodes select (IGenealogyGraphNode<T>)n; }
     100    public new IEnumerable<IGenealogyGraphNode<T>> Vertices {
     101      get { return from n in base.Vertices select (IGenealogyGraphNode<T>)n; }
    101102    }
    102103    // contructors
     
    132133      source.AddForwardArc(arc);
    133134      target.AddReverseArc(arc);
     135      arcs.Add(arc);
    134136      return arc;
    135137    }
    136     IEnumerable<IGenealogyGraphNode> IGenealogyGraph.Nodes {
    137       get { return Nodes; }
     138    IEnumerable<IGenealogyGraphNode> IGenealogyGraph.Vertices {
     139      get { return Vertices; }
    138140    }
    139141    public event EventHandler GraphUpdated;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphArc.cs

    r10888 r10903  
    3131    protected GenealogyGraphArc(bool deserializing) : base(deserializing) { }
    3232    protected GenealogyGraphArc(GenealogyGraphArc original, Cloner cloner)
    33       : base(original, cloner) {
    34       this.Target = original.Target;
    35       this.Source = original.Source;
    36       this.Label = original.Label;
    37       this.Weight = original.Weight;
    38       this.Data = original.Data;
    39     }
     33      : base(original, cloner) { }
    4034
    4135    protected GenealogyGraphArc() { }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraph.cs

    r10888 r10903  
    2626  public interface IGenealogyGraph : IDirectedGraph {
    2727    Dictionary<double, List<IGenealogyGraphNode>> Ranks { get; }
    28     new IEnumerable<IGenealogyGraphNode> Nodes { get; }
     28    new IEnumerable<IGenealogyGraphNode> Vertices { get; }
    2929  }
    3030
    3131  public interface IGenealogyGraph<T> : IGenealogyGraph where T : class, IItem {
    32     new IEnumerable<IGenealogyGraphNode<T>> Nodes { get; }
     32    new IEnumerable<IGenealogyGraphNode<T>> Vertices { get; }
    3333  }
    3434}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymboldDataAnalysisGenealogyView.cs

    r10897 r10903  
    106106        // perform matching like it was done before
    107107        // currently there is no possibility to specify the subtree matching criteria
    108         var trees = Content.Nodes.Select(x => x.Content);
     108        var trees = Content.Vertices.Select(x => x.Content);
    109109        var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer));
    110110
Note: See TracChangeset for help on using the changeset viewer.