Skip to main content

hamiltonian_path

Function hamiltonian_path 

Source
pub fn hamiltonian_path(graph: &Graph) -> IgraphResult<Option<Vec<u32>>>
Expand description

Find a Hamiltonian path using backtracking.

Returns Some(path) if one exists, None otherwise. Only feasible for small graphs.

ยงExamples

use rust_igraph::{Graph, hamiltonian_path, is_hamiltonian_path};

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, Some(4)).unwrap();
let p = hamiltonian_path(&g).unwrap();
assert!(p.is_some());
assert!(is_hamiltonian_path(&g, &p.unwrap()).unwrap());