1个不稳定版本

0.1.0 2023年1月13日

#1456数学

Download history 651/week @ 2024-03-14 1041/week @ 2024-03-21 859/week @ 2024-03-28 645/week @ 2024-04-04 786/week @ 2024-04-11 852/week @ 2024-04-18 818/week @ 2024-04-25 849/week @ 2024-05-02 1015/week @ 2024-05-09 912/week @ 2024-05-16 908/week @ 2024-05-23 965/week @ 2024-05-30 1166/week @ 2024-06-06 1207/week @ 2024-06-13 1049/week @ 2024-06-20 1181/week @ 2024-06-27

4,814 每月下载量
25 个crate中使用了(2个直接使用)

MIT/Apache

10KB
144

graph-cycles

找到图中的所有循环

Johnson算法寻找图中所有循环的原始实现。基于petgraph

示例

三角形图恰好有一个循环,即完全图本身。

use graph_cycles::Cycles;
use petgraph::graph::Graph;

let g = Graph::<(), ()>::from_edges([(0, 1), (1, 2), (2, 0)]);

// find all cycles
let cycles = g.cycles();
assert_eq!(cycles.len(), 1);
assert_eq!(cycles[0].len(), 3);

// print each cycle in turn
g.visit_all_cycles(|_g, c| {
   println!("Found new cycle with vertices {c:?}");
});

注意事项

此crate基本上未经测试。

参考文献

Donald B. Johnson, Finding all the elementary circuits of a directed graph, SIAM Journal on Computing, 1975.

许可证:MIT或Apache-2.0


lib.rs:

找到图中的所有循环

Johnson算法寻找图中所有循环的原始实现。基于petgraph

示例

三角形图恰好有一个循环,即完全图本身。

use graph_cycles::Cycles;
use petgraph::graph::Graph;

let g = Graph::<(), ()>::from_edges([(0, 1), (1, 2), (2, 0)]);

// find all cycles
let cycles = g.cycles();
assert_eq!(cycles.len(), 1);
assert_eq!(cycles[0].len(), 3);

// print each cycle in turn
g.visit_all_cycles(|_g, c| {
   println!("Found new cycle with vertices {c:?}");
});

注意事项

此crate基本上未经测试。

参考文献

Donald B. Johnson, Finding all the elementary circuits of a directed graph, SIAM Journal on Computing, 1975.

底层图的节点标识符

依赖

~3.5MB
~59K SLoC