예제 #1
0
        /// <summary>
        /// Converts a set of edges into an <see cref="AdjacencyGraph{TVertex,TEdge}"/>.
        /// </summary>
        /// <typeparam name="TVertex">Vertex type.</typeparam>
        /// <typeparam name="TEdge">Edge type.</typeparam>
        /// <param name="edges">Set of edges to convert.</param>
        /// <param name="allowParallelEdges">Indicates if parallel edges are allowed.</param>
        /// <returns>A corresponding <see cref="AdjacencyGraph{TVertex,TEdge}"/>.</returns>


        public static AdjacencyGraph <TVertex, TEdge> ToAdjacencyGraph <TVertex, TEdge>(
            this IEnumerable <TEdge> edges,
            bool allowParallelEdges = true)
            where TEdge : IEdge <TVertex>
        {
            var graph = new AdjacencyGraph <TVertex, TEdge>(allowParallelEdges);

            graph.AddVerticesAndEdgeRange(edges);
            return(graph);
        }
예제 #2
0
        /// <summary>
        /// Converts a set of vertex pairs into an <see cref="AdjacencyGraph{TVertex,TEdge}"/>.
        /// </summary>
        /// <typeparam name="TVertex">Vertex type.</typeparam>
        /// <param name="vertexPairs">Set of vertex pairs to convert.</param>
        /// <returns>A corresponding <see cref="AdjacencyGraph{TVertex,TEdge}"/>.</returns>


        public static AdjacencyGraph <TVertex, SEquatableEdge <TVertex> > ToAdjacencyGraph <TVertex>(
            this IEnumerable <SEquatableEdge <TVertex> > vertexPairs)
        {
            if (vertexPairs is null)
            {
                throw new ArgumentNullException(nameof(vertexPairs));
            }

            var graph = new AdjacencyGraph <TVertex, SEquatableEdge <TVertex> >();

            graph.AddVerticesAndEdgeRange(vertexPairs);
            return(graph);
        }