//************************************************************************* // Method: AddEdges() // /// <summary> /// Adds a specified number of vertices to m_oGraph using one of the Add() /// methods, then connects some of them with edges. /// </summary> /// /// <param name="iVerticesToAdd"> /// Number of vertices to add. /// </param> /// /// <param name="eDirectedness"> /// Directedness of the added edges. /// </param> /// /// <param name="eAddOverload"> /// Specifies which overload of Add() to call. /// </param> /// /// <param name="aoVertices"> /// Where the added vertices get stored. /// </param> /// /// <param name="aoEdges"> /// Where the added edges get stored. /// </param> /// /// <remarks> /// The first vertex is connected to every other vertex. Thus, the number /// of added edges is <paramref name="iVerticesToAdd" /> minus one. /// </remarks> //************************************************************************* protected void AddEdges( Int32 iVerticesToAdd, GraphDirectedness eDirectedness, AddOverload eAddOverload, out IVertex [] aoVertices, out IEdge [] aoEdges ) { Debug.Assert(iVerticesToAdd >= 0); aoVertices = AddVertices(iVerticesToAdd); aoEdges = new IEdge[ Math.Max(0, iVerticesToAdd - 1) ]; for (Int32 i = 1; i < iVerticesToAdd; i++) { Boolean bDirected = false; switch (eDirectedness) { case GraphDirectedness.Directed: bDirected = true; break; case GraphDirectedness.Undirected: bDirected = false; break; case GraphDirectedness.Mixed: // Make every other edge directed. bDirected = (i % 2 == 0); break; default: Debug.Assert(false); break; } m_bEdgeAdded = false; m_oAddedEdge = null; IVertex oVertex1 = aoVertices[0]; IVertex oVertex2 = aoVertices[i]; IEdge oEdge = null; switch (eAddOverload) { case AddOverload.IEdge: oEdge = new Edge(oVertex1, oVertex2, bDirected); m_oEdgeCollection.Add(oEdge); break; case AddOverload.IVertex: oEdge = m_oEdgeCollection.Add( oVertex1, oVertex2, bDirected); break; case AddOverload.IVertexUndirected: oEdge = m_oEdgeCollection.Add(oVertex1, oVertex2); break; default: Debug.Assert(false); break; } oEdge.Name = oEdge.ID.ToString(); aoEdges[i - 1] = oEdge; Assert.IsTrue(m_bEdgeAdded); Assert.AreEqual(oEdge, m_oAddedEdge); } Assert.AreEqual( Math.Max(0, iVerticesToAdd - 1), m_oEdgeCollection.Count); }
//************************************************************************* // Method: AddEdges() // /// <summary> /// Adds a specified number of vertices to m_oGraph using one of the Add() /// methods, then connects some of them with edges. /// </summary> /// /// <param name="iVerticesToAdd"> /// Number of vertices to add. /// </param> /// /// <param name="eDirectedness"> /// Directedness of the added edges. /// </param> /// /// <param name="eAddOverload"> /// Specifies which overload of Add() to call. /// </param> /// /// <returns> /// An array of the added edges. /// </returns> /// /// <remarks> /// The first vertex is connected to every other vertex. Thus, the number /// of added edges is <paramref name="iVerticesToAdd" /> minus one. /// </remarks> //************************************************************************* protected IEdge[] AddEdges( Int32 iVerticesToAdd, GraphDirectedness eDirectedness, AddOverload eAddOverload ) { Debug.Assert(iVerticesToAdd >= 0); IVertex [] aoVertices; IEdge[] aoEdges; AddEdges(iVerticesToAdd, eDirectedness, eAddOverload, out aoVertices, out aoEdges); return (aoEdges); }