pub fn split_edges_connected(
graph: &Graph,
test_fraction: f64,
seed: u64,
) -> IgraphResult<EdgeSplit>Expand description
Split edges ensuring the training graph remains connected.
Like split_edges but guarantees that removing the test edges does
not disconnect the graph. Edges whose removal would create a bridge
(disconnection) are kept in training. If maintaining connectivity
limits the test set size, fewer edges than requested may end up in test.
ยงExamples
use rust_igraph::{Graph, split_edges_connected};
// Cycle: every edge can be removed without disconnecting
let g = Graph::from_edges(
&[(0,1),(1,2),(2,3),(3,0)], false, Some(4)
).unwrap();
let split = split_edges_connected(&g, 0.5, 42).unwrap();
assert_eq!(split.train.len() + split.test.len(), 4);
// Test set has at most 2 edges (50%)
assert!(split.test.len() <= 2);