Changeset 11241 for trunk/sources
- Timestamp:
- 07/30/14 15:02:27 (10 years ago)
- 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 22 22 using System; 23 23 using HeuristicLab.Common; 24 using HeuristicLab.Core;25 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 25 27 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{26 namespace HeuristicLab.Core { 28 27 /// <summary> 29 28 /// An arc that can have a weight, a label, and a data object for holding additional info … … 60 59 61 60 [Storable] 62 protected objectdata;63 public objectData {61 protected IDeepCloneable data; 62 public IDeepCloneable Data { 64 63 get { return data; } 65 64 set { … … 84 83 label = original.Label; 85 84 weight = original.Weight; 86 data = original;85 data = cloner.Clone(data); 87 86 } 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); } 92 88 93 89 public event EventHandler Changed; -
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/DirectedGraph.cs
r11239 r11241 25 25 using System.Linq; 26 26 using HeuristicLab.Common; 27 using HeuristicLab.Co re;27 using HeuristicLab.Common.Resources; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 30 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{30 namespace HeuristicLab.Core { 31 31 [Item("DirectedGraph", "Generic class representing a directed graph with custom vertices and content")] 32 32 [StorableClass] 33 33 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; 35 37 [Storable] 36 38 public IEnumerable<IVertex> Vertices { … … 39 41 } 40 42 41 pr otectedHashSet<IArc> arcs;43 private HashSet<IArc> arcs; 42 44 [Storable] 43 45 public IEnumerable<IArc> Arcs { 44 46 get { return arcs; } 45 47 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); 46 63 } 47 64 … … 64 81 target.AddArc(arc); 65 82 } 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);81 83 } 82 84 … … 104 106 } 105 107 106 public IArc AddArc(IVertex source, IVertex target) {108 public virtual IArc AddArc(IVertex source, IVertex target) { 107 109 var arc = new Arc(source, target); 108 110 AddArc(arc); … … 110 112 } 111 113 112 public v oid AddArc(IArc arc) {114 public virtual void AddArc(IArc arc) { 113 115 var source = (Vertex)arc.Source; 114 116 var target = (Vertex)arc.Target; … … 118 120 } 119 121 120 public v oid RemoveArc(IArc arc) {122 public virtual void RemoveArc(IArc arc) { 121 123 arcs.Remove(arc); 122 124 var source = (Vertex)arc.Source; … … 126 128 } 127 129 130 public event EventHandler ArcAdded; 128 131 protected virtual void OnArcAdded(object sender, EventArgs<IArc> args) { 129 132 var arc = args.Value; … … 135 138 } 136 139 140 141 public event EventHandler ArcRemoved; 137 142 protected virtual void OnArcRemoved(object sender, EventArgs<IArc> args) { 138 143 var arc = args.Value; … … 141 146 } 142 147 143 public override Image ItemImage {144 get { return Common.Resources.VSImageLibrary.Graph; }145 }146 147 148 // events 148 149 public event EventHandler VertexAdded; 149 150 public event EventHandler VertexRemoved; 150 public event EventHandler ArcAdded;151 public event EventHandler ArcRemoved;152 151 } 153 152 } -
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/Vertex.cs
r11239 r11241 24 24 using System.Linq; 25 25 using HeuristicLab.Common; 26 using HeuristicLab.Core;27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 27 29 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{28 namespace HeuristicLab.Core { 30 29 [StorableClass] 31 30 public class Vertex : Item, IVertex { 32 31 [Storable] 33 pr otectedstring label;32 private string label; 34 33 public string Label { 35 34 get { return label; } … … 42 41 43 42 [Storable] 44 pr otecteddouble weight;43 private double weight; 45 44 public double Weight { 46 45 get { return weight; } … … 53 52 54 53 [Storable] 55 pr otected object content;56 public object Content{57 get { return content; }54 private IDeepCloneable data; 55 public IDeepCloneable Data { 56 get { return data; } 58 57 set { 59 if ( content== value) return;60 content= value;58 if (data == value) return; 59 data = value; 61 60 OnChanged(this, EventArgs.Empty); 62 61 } 63 62 } 64 63 65 private List<IArc> inArcs;64 private readonly List<IArc> inArcs = new List<IArc>(); 66 65 public IEnumerable<IArc> InArcs { 67 get { return inArcs ?? Enumerable.Empty<IArc>(); }66 get { return inArcs; } 68 67 } 69 68 70 private List<IArc> outArcs;69 private readonly List<IArc> outArcs = new List<IArc>(); 71 70 public IEnumerable<IArc> OutArcs { 72 get { return outArcs ?? Enumerable.Empty<IArc>(); }71 get { return outArcs; } 73 72 } 74 73 … … 83 82 private void AfterDeserialization() { } 84 83 85 public Vertex( object content) {86 this. content = content;84 public Vertex(IDeepCloneable data) { 85 this.data = data; 87 86 } 88 87 89 88 protected Vertex(Vertex original, Cloner cloner) 90 89 : base(original, cloner) { 91 content = original.content;90 data = cloner.Clone(original.Data); 92 91 label = original.Label; 93 92 weight = original.Weight; … … 106 105 107 106 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."); 112 108 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."); 118 112 inArcs.Add(arc); 119 113 } … … 125 119 throw new InvalidOperationException("The current vertex must be either the arc source or the arc target."); 126 120 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."); 133 126 } 134 127 OnArcRemoved(this, new EventArgs<IArc>(arc)); … … 162 155 [StorableClass] 163 156 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; } 167 160 } 168 161 -
trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj
r10291 r11241 116 116 <Compile Include="Collections\CheckedItemCollection.cs" /> 117 117 <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" /> 118 121 <Compile Include="Collections\ReadOnlyCheckedItemCollection.cs" /> 119 122 <Compile Include="Collections\ReadOnlyCheckedItemList.cs"> … … 148 151 <Compile Include="Constraints\IConstraint.cs" /> 149 152 <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" /> 150 156 <Compile Include="Interfaces\ICheckedMultiOperator.cs" /> 151 157 <Compile Include="Interfaces\IConstrainedValueParameter.cs" /> -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/DirectedGraph/IArc.cs
r11239 r11241 21 21 22 22 using System; 23 using HeuristicLab.Co re;23 using HeuristicLab.Common; 24 24 25 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{25 namespace HeuristicLab.Core { 26 26 public interface IArc : IItem { 27 event EventHandler Changed; // generic event for when the label, weight or data were changed28 27 IVertex Source { get; } 29 28 IVertex Target { get; } 30 29 string Label { get; set; } 31 30 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 33 34 } 34 35 -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/DirectedGraph/IDirectedGraph.cs
r11239 r11241 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 0Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Core;25 24 26 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{25 namespace HeuristicLab.Core { 27 26 public interface IDirectedGraph : IItem { 28 27 void Clear(); -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/DirectedGraph/IVertex.cs
r11239 r11241 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using System.Collections.Generic; 24 24 using HeuristicLab.Common; 25 using HeuristicLab.Core;26 25 27 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{26 namespace HeuristicLab.Core { 28 27 public interface IVertex : IItem { 29 event EventHandler Changed; // generic event for when the content, label or weight have changed30 event EventHandler<EventArgs<IArc>> ArcAdded;31 event EventHandler<EventArgs<IArc>> ArcRemoved;32 33 28 IEnumerable<IArc> InArcs { get; } 34 29 IEnumerable<IArc> OutArcs { get; } … … 41 36 double Weight { get; set; } 42 37 43 object Content{ get; set; }38 IDeepCloneable Data { get; set; } 44 39 45 40 void AddArc(IArc arc); 46 41 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; 47 46 } 48 47 49 48 public interface IVertex<T> : IVertex 50 49 where T : class { 51 new T Content{ get; set; }50 new T Data { get; set; } 52 51 } 53 52 }
Note: See TracChangeset
for help on using the changeset viewer.