pub fn random_weighted_digraph<K: SampleUniform + PartialOrd + Copy>(
    nodes: usize,
    nedges: usize,
    min_w: K,
    max_w: K
) -> Result<HashMap<(usize, usize), K>, EdgeNumberError>
Expand description

Random directed weighted graph.

Create and return a random digraph with a specified number of vertices and edges and random edge weights from a given range [min_w, max_w). Note: weights must have the SampleUniform trait.

Arguments

  • nodes: number of nodes.
  • nedges: number of edges.
  • min_w: lower bound of possible weights.
  • max_w: upper bound of possible weights.

Returns

  • Err: if the required number of vertices is greater than the maximum possible.
  • Ok: set HashMap<(usize, usize), K> of edges with usize vertex indices, where K is the type of weights.

Examples

use graphalgs::generate::random_weighted_digraph;
use petgraph::{ Graph, Directed };

let graph: Graph::<(), f64, Directed, usize> = Graph::from_edges(
    random_weighted_digraph(5, 16, -10.0, 10.0)
    .unwrap().into_iter().map(|(edge, w)| (edge.0, edge.1, w))
);