public void AddEdge(IEdgeMutableGraph g) { IVertex v = g.AddVertex(); IVertex u = g.AddVertex(); IEdge e = g.AddEdge(u,v); Assert.AreEqual(e.Source,u); Assert.AreEqual(e.Target,v); }

/// <summary> /// Generates a random graph /// </summary> /// <param name="g">Graph to fill</param> /// <param name="V">number of vertices</param> /// <param name="E">number of edges</param> /// <param name="rnd">random generator</param> /// <param name="selfEdges">self edges allowed</param> public static void Graph( IEdgeMutableGraph g, int V, int E, Random rnd, bool selfEdges ) { if (g == null) throw new ArgumentNullException("g"); if (rnd == null) throw new ArgumentNullException("random generator"); IVertex a=null; IVertex b=null; // When parallel edges are not allowed, we create a new graph which // does not allow parallel edges, construct it and copy back. // This is not efficient if 'g' already disallow parallel edges, // but that's task for later. if (!g.AllowParallelEdges) { throw new Exception("not implemented"); } else { for (int i = 0; i < V; ++i) g.AddVertex(); for (int j = 0; j < E; ++j) { a = Vertex((IVertexListGraph)g, rnd); do { b = Vertex((IVertexListGraph)g, rnd); } while (selfEdges == false && a == b); g.AddEdge(a, b); } } }

/// <summary> /// Makes a copy of the source graph to the clone graph. /// </summary> /// <param name="source">source graph</param> /// <param name="target">clone graph</param> public void Clone(IVertexAndEdgeListGraph source, IEdgeMutableGraph target) { VertexVertexDictionary vertexMap = new VertexVertexDictionary(); // copy vertices foreach(IVertex v in source.Vertices) { IVertex vc = target.AddVertex(); // clone properties OnCloneVertex(v,vc); // store in table vertexMap[v]=vc; } // copy edges foreach(IEdge e in source.Edges) { IEdge ec = target.AddEdge(vertexMap[e.Source], vertexMap[e.Target]); // cone properties OnCloneEdge(e,ec); } }

public void AddEdgeSourceNotFound(IEdgeMutableGraph g) { IVertex u = g.AddVertex(); g.RemoveVertex(u); IVertex v = g.AddVertex(); IEdge e = g.AddEdge(u,v); }

public void RemoveEdgeNotFound(IEdgeMutableGraph g) { IVertex v = g.AddVertex(); IVertex u = g.AddVertex(); IEdge e = g.AddEdge(u,v); g.RemoveEdge(e); g.RemoveEdge(e); }

public void ClearVertexTargetSource(IEdgeMutableGraph g) { IVertex u = g.AddVertex(); IVertex v = g.AddVertex(); g.AddEdge(u,v); g.ClearVertex(v); g.ClearVertex(u); }

public void AddRemoveVertexNotFound(IEdgeMutableGraph g) { IVertex v = g.AddVertex(); g.RemoveVertex(v); g.RemoveVertex(v); }

/// <summary> /// Removes temporary edges /// </summary> /// <param name="g"></param> public void RemoveTemporaryEdges(IEdgeMutableGraph g) { // remove from graph foreach(IEdge e in TemporaryEdges) g.RemoveEdge(e); }

/// <summary> /// Generates a random graph /// </summary> /// <param name="g">Graph to fill</param> /// <param name="vertexCount">number of vertices</param> /// <param name="edgeCount">number of edges</param> /// <param name="rnd">random generator</param> /// <param name="selfEdges">self edges allowed</param> public static void Graph( IEdgeMutableGraph g, int vertexCount, int edgeCount, Random rnd, bool selfEdges ) { if (g == null) throw new ArgumentNullException("g"); if (rnd == null) throw new ArgumentNullException("random generator"); IVertex a=null; IVertex b=null; for (int i = 0; i < vertexCount; ++i) g.AddVertex(); int j=0; while(j<edgeCount) { a = Vertex((IVertexListGraph)g, rnd); do { b = Vertex((IVertexListGraph)g, rnd); } while (selfEdges == false && a == b); try { g.AddEdge(a, b); ++j; } catch(Exception) {} } }

public void RemoveTemporaryEdges(IEdgeMutableGraph g) { EdgeCollection.Enumerator enumerator = this.TemporaryEdges.GetEnumerator(); while (enumerator.MoveNext()) { IEdge edge = enumerator.get_Current(); g.RemoveEdge(edge); } }