Changeset 11324 for trunk/sources/HeuristicLab.Core/3.3/Collections
- Timestamp:
- 09/01/14 13:50:36 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/DirectedGraph.cs
r11263 r11324 106 106 } 107 107 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); 118 } 119 108 120 public virtual void RemoveVertex(IVertex vertex) { 109 121 vertices.Remove(vertex); … … 125 137 126 138 public virtual void AddArc(IArc arc) { 127 var source = (Vertex)arc.Source; 128 var target = (Vertex)arc.Target; 139 var source = arc.Source; 140 var target = arc.Target; 141 142 if (!vertices.Contains(source) || !vertices.Contains(target)) 143 throw new InvalidOperationException("Cannot add arc connecting vertices that are not in the graph."); 144 129 145 source.AddArc(arc); 130 146 target.AddArc(arc);
Note: See TracChangeset
for help on using the changeset viewer.