Changeset 11912 for trunk/sources/HeuristicLab.Core/3.3/Collections
- Timestamp:
- 02/05/15 13:55:04 (10 years ago)
- Location:
- trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/Arc.cs
r11879 r11912 56 56 } 57 57 58 [Storable]59 protected object data;60 public object Data {61 get { return data; }62 set {63 if (data == value) return;64 data = value;65 OnChanged(this, EventArgs.Empty);66 }67 }68 58 69 59 [StorableConstructor] … … 81 71 label = original.Label; 82 72 weight = original.Weight; 83 if (data is IDeepCloneable)84 data = cloner.Clone((IDeepCloneable)data);85 else data = original.Data;86 73 } 87 74 public override IDeepCloneable Clone(Cloner cloner) { return new Arc(this, cloner); } … … 96 83 97 84 [StorableClass] 98 public class Arc<T> : Arc, IArc<T> where T : class,IItem { 85 public class Arc<T> : Arc, IArc<T> where T : class,IDeepCloneable { 86 [Storable] 87 protected T data; 88 public T Data { 89 get { return data; } 90 set { 91 if (data == value) return; 92 data = value; 93 OnChanged(this, EventArgs.Empty); 94 } 95 } 96 97 public override IDeepCloneable Clone(Cloner cloner) { 98 return new Arc<T>(this, cloner); 99 } 100 101 protected Arc(Arc<T> original, Cloner cloner) 102 : base(original, cloner) { 103 if (original.Data != null) 104 Data = cloner.Clone(original.Data); 105 } 106 99 107 public Arc(bool deserializing) 100 108 : base(deserializing) { … … 108 116 : base(original, cloner) { 109 117 } 110 111 new public IVertex<T> Source {112 get { return (IVertex<T>)base.Source; }113 }114 new public IVertex<T> Target {115 get { return (IVertex<T>)base.Target; }116 }117 118 } 118 119 } -
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/DirectedGraph.cs
r11444 r11912 102 102 vertex.ArcAdded += Vertex_ArcAdded; 103 103 vertex.ArcRemoved += Vertex_ArcRemoved; 104 OnVerte dAdded(this, new EventArgs<IVertex>(vertex));104 OnVertexAdded(this, new EventArgs<IVertex>(vertex)); 105 105 } 106 106 } 107 107 108 108 public virtual void AddVertices(IEnumerable<IVertex> vertexList) { 109 var hash = new HashSet<IVertex>(vertexList); 110 var arcList = vertexList.SelectMany(v => v.InArcs.Concat(v.OutArcs)); 111 if (arcList.Any(x => !hash.Contains(x.Source) || !hash.Contains(x.Target))) 112 throw new ArgumentException("Vertex arcs are connected to vertices not in the graph."); 113 // if everything is in order, add the vertices to the directed graph 114 foreach (var v in vertexList) 115 vertices.Add(v); 116 foreach (var a in arcList) 117 arcs.Add(a); 109 foreach (var v in vertexList) { AddVertex(v); } 118 110 } 119 111 120 112 public virtual void RemoveVertices(IEnumerable<IVertex> vertexList) { 121 foreach (var v in vertexList) 122 RemoveVertex(v); 113 foreach (var v in vertexList) { RemoveVertex(v); } 123 114 } 124 115 … … 156 147 } 157 148 149 public virtual void AddArcs(IEnumerable<IArc> arcList) { 150 foreach (var a in arcList) { AddArc(a); } 151 } 152 158 153 public virtual void RemoveArc(IArc arc) { 159 154 arcs.Remove(arc); … … 164 159 } 165 160 161 public virtual void RemoveArcs(IEnumerable<IArc> arcList) { 162 foreach (var a in arcList) { RemoveArc(a); } 163 } 164 166 165 protected virtual void Vertex_ArcAdded(object sender, EventArgs<IArc> args) { 167 166 // the ArcAdded event is fired by a vertex when an arc from/to another vertex is added to its list of connections … … 178 177 // events 179 178 public event EventHandler<EventArgs<IVertex>> VertexAdded; 180 protected virtual void OnVerte dAdded(object sender, EventArgs<IVertex> args) {179 protected virtual void OnVertexAdded(object sender, EventArgs<IVertex> args) { 181 180 var added = VertexAdded; 182 181 if (added != null) -
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/Vertex.cs
r11263 r11912 52 52 } 53 53 54 [Storable]55 private IDeepCloneable data;56 public IDeepCloneable Data {57 get { return data; }58 set {59 if (data == value) return;60 data = value;61 OnChanged(this, EventArgs.Empty);62 }63 }64 65 54 private readonly List<IArc> inArcs = new List<IArc>(); 66 55 public IEnumerable<IArc> InArcs { … … 83 72 private void AfterDeserialization() { } 84 73 85 public Vertex(IDeepCloneable data) { 86 this.data = data; 87 } 74 public Vertex() { } 88 75 89 76 protected Vertex(Vertex original, Cloner cloner) 90 77 : base(original, cloner) { 91 data = cloner.Clone(original.Data);92 78 label = original.Label; 93 79 weight = original.Weight; 94 95 80 // we do not clone the arcs here (would cause too much recursion and ultimately a stack overflow) 96 81 } … … 157 142 158 143 [StorableClass] 159 public class Vertex<T> : Vertex, IVertex<T> where T : class,IItem { 160 public new T Data { 161 get { return (T)base.Data; } 162 set { base.Data = value; } 144 public class Vertex<T> : Vertex, IVertex<T> where T : class,IDeepCloneable { 145 [Storable] 146 private T data; 147 public T Data { 148 get { return data; } 149 set { 150 if (data == value) return; 151 data = value; 152 OnChanged(this, EventArgs.Empty); 153 } 163 154 } 164 155 … … 168 159 protected Vertex(Vertex<T> original, Cloner cloner) 169 160 : base(original, cloner) { 161 if (original.Data != null) 162 Data = cloner.Clone(original.Data); 170 163 } 171 164 172 public Vertex(IDeepCloneable data) 173 : base(data) { 174 } 165 public Vertex() : base() { } 175 166 176 167 public override IDeepCloneable Clone(Cloner cloner) {
Note: See TracChangeset
for help on using the changeset viewer.