pub fn sample_graph_from<R, S, ND, ED, F, G, N, E>(
rng: R,
elements: Vec<S>,
num_nodes: usize,
num_edges: usize,
node_density: ND,
edge_density: ED,
node_weight: F,
edge_weight: G,
) -> Graph<N, E, Undirected, u32>Expand description
Samples a graph from the given Densitys.
Arguments:
rng: random number generator.elements: of the given space from which should be sampled.num_nodes: number of villages to be chosen.num_edges: number of roads connecting the villages to be chosen.node_density: defines the probability from which the elements are chosen.edge_density: defines the probability of the edges.node_weight: sets the node weights of the resulting graph.edge_weight: sets the edge weights of the resulting graph.
Returns:
Graph: which is an undirectedpetgraphwhose node weights are defined bynode_weightand edge_weight are defined byedge_weight. NOTE: the graph could have fewer thannum_nodesnodes ornum_edgesedges if at one point in the sampling process the probabilities for each node or edges is zero.
Example:
use gengraph::{sample_graph_from, Density};
let rng = rand::rng();
let dist = |x: &u8, y: &u8| if x > y {x - y} else {y - x};
let graph = sample_graph_from(
rand::rng(),
(0..10).collect::<Vec<u8>>(),
5,
10,
|_: &u8, _: &[u8]| 1.0, // Vertex probability
|(x, y): &(u8, u8), _: &[(u8, u8)]| 1.0 / dist(x, y) as f64, // Edge probability
|_| (), // Vertex weight
|(x, y): &(u8, u8)| dist(x, y), // Edge weight
);