Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11241 for trunk/sources


Ignore:
Timestamp:
07/30/14 15:02:27 (10 years ago)
Author:
mkommend
Message:

#2223: Copied directed graph implented in bottom up tree distance branch into the trunk.

Location:
trunk/sources/HeuristicLab.Core/3.3
Files:
2 added
1 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/Arc.cs

    r11239 r11241  
    2222using System;
    2323using HeuristicLab.Common;
    24 using HeuristicLab.Core;
    2524using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2625
    27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     26namespace HeuristicLab.Core {
    2827  /// <summary>
    2928  /// An arc that can have a weight, a label, and a data object for holding additional info
     
    6059
    6160    [Storable]
    62     protected object data;
    63     public object Data {
     61    protected IDeepCloneable data;
     62    public IDeepCloneable Data {
    6463      get { return data; }
    6564      set {
     
    8483      label = original.Label;
    8584      weight = original.Weight;
    86       data = original;
     85      data = cloner.Clone(data);
    8786    }
    88 
    89     public override IDeepCloneable Clone(Cloner cloner) {
    90       return new Arc(this, cloner);
    91     }
     87    public override IDeepCloneable Clone(Cloner cloner) { return new Arc(this, cloner); }
    9288
    9389    public event EventHandler Changed;
  • trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/DirectedGraph.cs

    r11239 r11241  
    2525using System.Linq;
    2626using HeuristicLab.Common;
    27 using HeuristicLab.Core;
     27using HeuristicLab.Common.Resources;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2929
    30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     30namespace HeuristicLab.Core {
    3131  [Item("DirectedGraph", "Generic class representing a directed graph with custom vertices and content")]
    3232  [StorableClass]
    3333  public class DirectedGraph : Item, IDirectedGraph {
    34     protected HashSet<IVertex> vertices;
     34    public override Image ItemImage { get { return VSImageLibrary.Graph; } }
     35
     36    private HashSet<IVertex> vertices;
    3537    [Storable]
    3638    public IEnumerable<IVertex> Vertices {
     
    3941    }
    4042
    41     protected HashSet<IArc> arcs;
     43    private HashSet<IArc> arcs;
    4244    [Storable]
    4345    public IEnumerable<IArc> Arcs {
    4446      get { return arcs; }
    4547      private set { arcs = new HashSet<IArc>(value); }
     48    }
     49
     50    public DirectedGraph() {
     51      vertices = new HashSet<IVertex>();
     52      arcs = new HashSet<IArc>();
     53    }
     54
     55    protected DirectedGraph(DirectedGraph original, Cloner cloner)
     56      : base(original, cloner) {
     57      vertices = new HashSet<IVertex>(original.vertices.Select(cloner.Clone));
     58      arcs = new HashSet<IArc>(original.arcs.Select(cloner.Clone));
     59    }
     60
     61    public override IDeepCloneable Clone(Cloner cloner) {
     62      return new DirectedGraph(this, cloner);
    4663    }
    4764
     
    6481        target.AddArc(arc);
    6582      }
    66     }
    67 
    68     public DirectedGraph() {
    69       vertices = new HashSet<IVertex>();
    70       arcs = new HashSet<IArc>();
    71     }
    72 
    73     protected DirectedGraph(DirectedGraph original, Cloner cloner)
    74       : base(original, cloner) {
    75       vertices = new HashSet<IVertex>(original.vertices.Select(cloner.Clone));
    76       arcs = new HashSet<IArc>(original.arcs.Select(cloner.Clone));
    77     }
    78 
    79     public override IDeepCloneable Clone(Cloner cloner) {
    80       return new DirectedGraph(this, cloner);
    8183    }
    8284
     
    104106    }
    105107
    106     public IArc AddArc(IVertex source, IVertex target) {
     108    public virtual IArc AddArc(IVertex source, IVertex target) {
    107109      var arc = new Arc(source, target);
    108110      AddArc(arc);
     
    110112    }
    111113
    112     public void AddArc(IArc arc) {
     114    public virtual void AddArc(IArc arc) {
    113115      var source = (Vertex)arc.Source;
    114116      var target = (Vertex)arc.Target;
     
    118120    }
    119121
    120     public void RemoveArc(IArc arc) {
     122    public virtual void RemoveArc(IArc arc) {
    121123      arcs.Remove(arc);
    122124      var source = (Vertex)arc.Source;
     
    126128    }
    127129
     130    public event EventHandler ArcAdded;
    128131    protected virtual void OnArcAdded(object sender, EventArgs<IArc> args) {
    129132      var arc = args.Value;
     
    135138    }
    136139
     140
     141    public event EventHandler ArcRemoved;
    137142    protected virtual void OnArcRemoved(object sender, EventArgs<IArc> args) {
    138143      var arc = args.Value;
     
    141146    }
    142147
    143     public override Image ItemImage {
    144       get { return Common.Resources.VSImageLibrary.Graph; }
    145     }
    146 
    147148    // events
    148149    public event EventHandler VertexAdded;
    149150    public event EventHandler VertexRemoved;
    150     public event EventHandler ArcAdded;
    151     public event EventHandler ArcRemoved;
    152151  }
    153152}
  • trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/Vertex.cs

    r11239 r11241  
    2424using System.Linq;
    2525using HeuristicLab.Common;
    26 using HeuristicLab.Core;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2827
    29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     28namespace HeuristicLab.Core {
    3029  [StorableClass]
    3130  public class Vertex : Item, IVertex {
    3231    [Storable]
    33     protected string label;
     32    private string label;
    3433    public string Label {
    3534      get { return label; }
     
    4241
    4342    [Storable]
    44     protected double weight;
     43    private double weight;
    4544    public double Weight {
    4645      get { return weight; }
     
    5352
    5453    [Storable]
    55     protected object content;
    56     public object Content {
    57       get { return content; }
     54    private IDeepCloneable data;
     55    public IDeepCloneable Data {
     56      get { return data; }
    5857      set {
    59         if (content == value) return;
    60         content = value;
     58        if (data == value) return;
     59        data = value;
    6160        OnChanged(this, EventArgs.Empty);
    6261      }
    6362    }
    6463
    65     private List<IArc> inArcs;
     64    private readonly List<IArc> inArcs = new List<IArc>();
    6665    public IEnumerable<IArc> InArcs {
    67       get { return inArcs ?? Enumerable.Empty<IArc>(); }
     66      get { return inArcs; }
    6867    }
    6968
    70     private List<IArc> outArcs;
     69    private readonly List<IArc> outArcs = new List<IArc>();
    7170    public IEnumerable<IArc> OutArcs {
    72       get { return outArcs ?? Enumerable.Empty<IArc>(); }
     71      get { return outArcs; }
    7372    }
    7473
     
    8382    private void AfterDeserialization() { }
    8483
    85     public Vertex(object content) {
    86       this.content = content;
     84    public Vertex(IDeepCloneable data) {
     85      this.data = data;
    8786    }
    8887
    8988    protected Vertex(Vertex original, Cloner cloner)
    9089      : base(original, cloner) {
    91       content = original.content;
     90      data = cloner.Clone(original.Data);
    9291      label = original.Label;
    9392      weight = original.Weight;
     
    106105
    107106      if (this == arc.Source) {
    108         if (outArcs == null)
    109           outArcs = new List<IArc>();
    110         else if (outArcs.Contains(arc))
    111           throw new InvalidOperationException("Arc already added.");
     107        if (outArcs.Contains(arc)) throw new InvalidOperationException("Arc already added.");
    112108        outArcs.Add(arc);
    113       } else if (this == arc.Target) {
    114         if (inArcs == null)
    115           inArcs = new List<IArc>();
    116         else if (inArcs.Contains(arc))
    117           throw new InvalidOperationException("Arc already added.");
     109      }
     110      if (this == arc.Target) {
     111        if (inArcs.Contains(arc)) throw new InvalidOperationException("Arc already added.");
    118112        inArcs.Add(arc);
    119113      }
     
    125119        throw new InvalidOperationException("The current vertex must be either the arc source or the arc target.");
    126120
    127       if (this == arc.Source && outArcs != null) {
    128         if (!outArcs.Remove(arc))
    129           throw new InvalidOperationException("Arc is not present in this vertex' outgoing arcs.");
    130       } else if (this == arc.Target && inArcs != null) {
    131         if (!inArcs.Remove(arc))
    132           throw new InvalidOperationException("Arc is not present in this vertex' incoming arcs.");
     121      if (this == arc.Source) {
     122        if (!outArcs.Remove(arc)) throw new InvalidOperationException("Arc is not present in this vertex' outgoing arcs.");
     123      }
     124      if (this == arc.Target) {
     125        if (!inArcs.Remove(arc)) throw new InvalidOperationException("Arc is not present in this vertex' incoming arcs.");
    133126      }
    134127      OnArcRemoved(this, new EventArgs<IArc>(arc));
     
    162155  [StorableClass]
    163156  public class Vertex<T> : Vertex, IVertex<T> where T : class,IItem {
    164     public new T Content {
    165       get { return (T)base.Content; }
    166       set { base.Content = value; }
     157    public new T Data {
     158      get { return (T)base.Data; }
     159      set { base.Data = value; }
    167160    }
    168161
  • trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r10291 r11241  
    116116    <Compile Include="Collections\CheckedItemCollection.cs" />
    117117    <Compile Include="Collections\CheckedItemList.cs" />
     118    <Compile Include="Collections\DirectedGraph\Arc.cs" />
     119    <Compile Include="Collections\DirectedGraph\DirectedGraph.cs" />
     120    <Compile Include="Collections\DirectedGraph\Vertex.cs" />
    118121    <Compile Include="Collections\ReadOnlyCheckedItemCollection.cs" />
    119122    <Compile Include="Collections\ReadOnlyCheckedItemList.cs">
     
    148151    <Compile Include="Constraints\IConstraint.cs" />
    149152    <Compile Include="Constraints\TypeCompatibilityConstraint.cs" />
     153    <Compile Include="Interfaces\DirectedGraph\IArc.cs" />
     154    <Compile Include="Interfaces\DirectedGraph\IDirectedGraph.cs" />
     155    <Compile Include="Interfaces\DirectedGraph\IVertex.cs" />
    150156    <Compile Include="Interfaces\ICheckedMultiOperator.cs" />
    151157    <Compile Include="Interfaces\IConstrainedValueParameter.cs" />
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/DirectedGraph/IArc.cs

    r11239 r11241  
    2121
    2222using System;
    23 using HeuristicLab.Core;
     23using HeuristicLab.Common;
    2424
    25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     25namespace HeuristicLab.Core {
    2626  public interface IArc : IItem {
    27     event EventHandler Changed; // generic event for when the label, weight or data were changed
    2827    IVertex Source { get; }
    2928    IVertex Target { get; }
    3029    string Label { get; set; }
    3130    double Weight { get; set; }
    32     object Data { get; set; }
     31    IDeepCloneable Data { get; set; }
     32
     33    event EventHandler Changed; // generic event for when the label, weight or data were changed
    3334  }
    3435
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/DirectedGraph/IDirectedGraph.cs

    r11239 r11241  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2222using System;
    2323using System.Collections.Generic;
    24 using HeuristicLab.Core;
    2524
    26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     25namespace HeuristicLab.Core {
    2726  public interface IDirectedGraph : IItem {
    2827    void Clear();
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/DirectedGraph/IVertex.cs

    r11239 r11241  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using System.Collections.Generic;
    2424using HeuristicLab.Common;
    25 using HeuristicLab.Core;
    2625
    27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     26namespace HeuristicLab.Core {
    2827  public interface IVertex : IItem {
    29     event EventHandler Changed; // generic event for when the content, label or weight have changed
    30     event EventHandler<EventArgs<IArc>> ArcAdded;
    31     event EventHandler<EventArgs<IArc>> ArcRemoved;
    32 
    3328    IEnumerable<IArc> InArcs { get; }
    3429    IEnumerable<IArc> OutArcs { get; }
     
    4136    double Weight { get; set; }
    4237
    43     object Content { get; set; }
     38    IDeepCloneable Data { get; set; }
    4439
    4540    void AddArc(IArc arc);
    4641    void RemoveArc(IArc arc);
     42
     43    event EventHandler Changed; // generic event for when the content, label or weight have changed
     44    event EventHandler<EventArgs<IArc>> ArcAdded;
     45    event EventHandler<EventArgs<IArc>> ArcRemoved;
    4746  }
    4847
    4948  public interface IVertex<T> : IVertex
    5049  where T : class {
    51     new T Content { get; set; }
     50    new T Data { get; set; }
    5251  }
    5352}
Note: See TracChangeset for help on using the changeset viewer.