pub fn layout_graphopt(
graph: &Graph,
seed: Option<&[[f64; 2]]>,
params: &GraphoptParams,
) -> IgraphResult<Vec<[f64; 2]>>Expand description
Compute the GraphOpt force-directed layout.
Vertices repel each other via Coulomb force and are attracted along
edges via Hooke spring force. The system is iterated for niter
steps; each step accumulates forces, divides by mass, clamps
displacement, and moves vertices.
Edge directions are ignored (treated as undirected).
§Arguments
graph— input graph.seed— optional initial positions. IfNone, random positions are generated.params— algorithm parameters.
Returns [x, y] positions for each vertex.
§Errors
Returns InvalidArgument if node_mass is zero (division by zero)
or if seed length doesn’t match vertex count.
§Examples
use rust_igraph::{Graph, layout_graphopt, GraphoptParams};
let mut g = Graph::with_vertices(5);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 4).unwrap();
g.add_edge(4, 0).unwrap();
let params = GraphoptParams::default();
let pos = layout_graphopt(&g, None, ¶ms).unwrap();
assert_eq!(pos.len(), 5);
assert!(pos.iter().all(|p| p[0].is_finite() && p[1].is_finite()));