/// <summary> /// Converts a set of edges into an adjacency graph. /// </summary> /// <typeparam name="TVertex">The type of the vertex.</typeparam> /// <typeparam name="TEdge">The type of the edge.</typeparam> /// <param name="edges">The edges.</param> /// <returns></returns> public static AdjacencyGraph <TVertex, TEdge> ToAdjacencyGraph <TVertex, TEdge>(this IEnumerable <TEdge> edges) where TEdge : IEdge <TVertex> { Contract.Requires(edges != null); Contract.Requires(EnumerableContract.ElementsNotNull(edges)); return(ToAdjacencyGraph <TVertex, TEdge>(edges, true)); }
/// <summary> /// Converts a set of edges into an adjacency graph. /// </summary> /// <typeparam name="TVertex">The type of the vertex.</typeparam> /// <typeparam name="TEdge">The type of the edge.</typeparam> /// <param name="edges">The edges.</param> /// <param name="allowParallelEdges">if set to <c>true</c>, the graph allows parallel edges.</param> /// <returns></returns> public static AdjacencyGraph <TVertex, TEdge> ToAdjacencyGraph <TVertex, TEdge> (this IEnumerable <TEdge> edges, bool allowParallelEdges) where TEdge : IEdge <TVertex> { Contract.Requires(edges != null); Contract.Requires(EnumerableContract.ElementsNotNull(edges)); var g = new AdjacencyGraph <TVertex, TEdge>(allowParallelEdges); g.AddVerticesAndEdgeRange(edges); return(g); }
/// <summary> /// Converts a set of edges into a bidirectional graph. /// </summary> /// <typeparam name="TVertex">The type of the vertex.</typeparam> /// <typeparam name="TEdge">The type of the edge.</typeparam> /// <param name="edges">The edges.</param> /// <returns></returns> public static BidirectionalGraph <TVertex, TEdge> ToBidirectionalGraph <TVertex, TEdge>( #if !NET20 this #endif IEnumerable <TEdge> edges ) where TEdge : IEdge <TVertex> { Contract.Requires(edges != null); Contract.Requires(EnumerableContract.ElementsNotNull(edges)); return(ToBidirectionalGraph <TVertex, TEdge>(edges, true)); }
/// <summary> /// Converts a set of edges into a bidirectional graph. /// </summary> /// <typeparam name="TVertex">The type of the vertex.</typeparam> /// <typeparam name="TEdge">The type of the edge.</typeparam> /// <param name="edges">The edges.</param> /// <param name="allowParallelEdges">if set to <c>true</c>, the graph allows parallel edges.</param> /// <returns></returns> public static BidirectionalGraph <TVertex, TEdge> ToBidirectionalGraph <TVertex, TEdge>( #if !NET20 this #endif IEnumerable <TEdge> edges, bool allowParallelEdges ) where TEdge : IEdge <TVertex> { Contract.Requires(edges != null); Contract.Requires(EnumerableContract.ElementsNotNull(edges)); var g = new BidirectionalGraph <TVertex, TEdge>(allowParallelEdges); g.AddVerticesAndEdgeRange(edges); return(g); }
/// <summary> /// Converts a set of vertices into a bidirectional graph, /// using an edge factory. /// </summary> /// <typeparam name="TVertex">The type of the vertex.</typeparam> /// <typeparam name="TEdge">The type of the edge.</typeparam> /// <param name="vertices">The vertices.</param> /// <param name="outEdgesFactory">The out edges factory.</param> /// <param name="allowParallelEdges">if set to <c>true</c>, the graph allows parallel edges.</param> /// <returns></returns> public static BidirectionalGraph <TVertex, TEdge> ToBidirectionalGraph <TVertex, TEdge> (this IEnumerable <TVertex> vertices, Func <TVertex, IEnumerable <TEdge> > outEdgesFactory, bool allowParallelEdges ) where TEdge : IEdge <TVertex> { Contract.Requires(vertices != null); Contract.Requires(outEdgesFactory != null); Contract.Requires(EnumerableContract.ElementsNotNull(vertices)); var g = new BidirectionalGraph <TVertex, TEdge>(allowParallelEdges); g.AddVertexRange(vertices); foreach (var vertex in g.Vertices) { g.AddEdgeRange(outEdgesFactory(vertex)); } return(g); }