- Timestamp:
- 08/04/14 14:58:47 (10 years ago)
- Location:
- trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/DirectedGraph.cs
r11251 r11263 57 57 vertices = new HashSet<IVertex>(original.vertices.Select(cloner.Clone)); 58 58 arcs = new HashSet<IArc>(original.arcs.Select(cloner.Clone)); 59 60 // add the arcs to the newly cloned vertices 61 foreach (var arc in arcs) { 62 arc.Source.AddArc(arc); 63 arc.Target.AddArc(arc); 64 } 59 65 } 60 66 … … 89 95 90 96 public virtual void AddVertex(IVertex vertex) { 91 vertices.Add(vertex); 92 // register event handlers 93 vertex.ArcAdded += Vertex_ArcAdded; 94 vertex.ArcRemoved += Vertex_ArcRemoved; 95 OnVertedAdded(this, new EventArgs<IVertex>(vertex)); 97 if (!vertices.Contains(vertex) && vertex.Degree > 0) 98 throw new ArgumentException("New vertices cannot have any arcs."); 99 100 if (vertices.Add(vertex)) { 101 // register event handlers 102 vertex.ArcAdded += Vertex_ArcAdded; 103 vertex.ArcRemoved += Vertex_ArcRemoved; 104 OnVertedAdded(this, new EventArgs<IVertex>(vertex)); 105 } 96 106 } 97 107 -
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/Vertex.cs
r11248 r11263 93 93 weight = original.Weight; 94 94 95 inArcs = original.InArcs.Select(cloner.Clone).ToList(); 96 outArcs = original.OutArcs.Select(cloner.Clone).ToList(); 95 // we do not clone the arcs here (would cause too much recursion and ultimately a stack overflow) 97 96 } 98 97 … … 103 102 public void AddArc(IArc arc) { 104 103 if (this != arc.Source && this != arc.Target) 105 throw new InvalidOperationException("The current vertex must be either the arc source or the arc target."); 104 throw new ArgumentException("The current vertex must be either the arc source or the arc target."); 105 106 if (arc.Source == arc.Target) 107 throw new ArgumentException("Arc source and target must be different."); 106 108 107 109 if (this == arc.Source) { … … 118 120 public void RemoveArc(IArc arc) { 119 121 if (this != arc.Source && this != arc.Target) 120 throw new InvalidOperationException("The current vertex must be either the arc source or the arc target.");122 throw new ArgumentException("The current vertex must be either the arc source or the arc target."); 121 123 122 124 if (this == arc.Source) { … … 168 170 } 169 171 172 public Vertex(IDeepCloneable data) 173 : base(data) { 174 } 175 170 176 public override IDeepCloneable Clone(Cloner cloner) { 171 177 return new Vertex<T>(this, cloner);
Note: See TracChangeset
for help on using the changeset viewer.