Free cookie consent management tool by TermsFeed Policy Generator

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/Collections/DirectedGraph
Files:
1 added
1 copied

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.