Class RandomGraph
- Namespace
- AlgorithmsSW.EdgeWeightedGraph
- Assembly
- AlgorithmsSW.dll
Provides methods for generating random graphs.
public static class RandomGraph
- Inheritance
-
RandomGraph
- Inherited Members
Methods
AssignWeights<TWeight>(IReadOnlyGraph, IEnumerable<TWeight>)
Assigns weights from a list to edges of a graph.
public static IEdgeWeightedGraph<TWeight> AssignWeights<TWeight>(IReadOnlyGraph graph, IEnumerable<TWeight> weights)
Parameters
graph
IReadOnlyGraphThe graph to assign weights to.
weights
IEnumerable<TWeight>The weights to assign to the edges of the graph.
Returns
- IEdgeWeightedGraph<TWeight>
Type Parameters
TWeight
The type of the weights.
Examples
You can use a IEnumerable<T> such as the following to assign random weights:
/// <summary>
/// Returns an infinite sequence of random integers in the range [0, maxValue).
/// </summary>
/// <param name="maxValue">The exclusive upper bound of the random integers.</param>
/// <remarks> Use <see cref="Enumerable.Take{TSource}(System.Collections.Generic.IEnumerable{TSource},int)"/> to
/// get a finite amount of elements. </remarks>
public static IEnumerable<int> UniformRandomInt(int maxValue)
{
while (true)
{
yield return NextUniformRandomInt(maxValue);
}
// ReSharper disable once IteratorNeverReturns
}