Skip to main content

layout_fruchterman_reingold

Function layout_fruchterman_reingold 

Source
pub fn layout_fruchterman_reingold(
    graph: &Graph,
    params: &FrParams,
) -> IgraphResult<Vec<(f64, f64)>>
Expand description

2D Fruchterman-Reingold force-directed layout.

Simulates attractive force f_a(d) = -w * d² between connected vertices and repulsive force f_r(d) = 1/d between all vertex pairs. Temperature cools linearly from start_temp to 0 over niter iterations.

For disconnected graphs, a weak global attraction n^(-3/2) keeps components from drifting apart.

Reference: Fruchterman & Reingold, “Graph Drawing by Force-directed Placement”, Software—Practice and Experience 21(11), 1991.

§Examples

use rust_igraph::{Graph, layout_fruchterman_reingold, FrParams};

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 coords = layout_fruchterman_reingold(&g, &FrParams::default()).unwrap();
assert_eq!(coords.len(), 5);