MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / harmonic_path

Function harmonic_path

nodedb/src/engine/graph/algo/harmonic.rs:79–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

77
78 #[test]
79 fn harmonic_path() {
80 // a - b - c. b has shortest distances to a (1) and c (1).
81 // HC(b) = (1/1 + 1/1) / 2 = 1.0
82 // HC(a) = (1/1 + 1/2) / 2 = 0.75
83 let mut csr = CsrIndex::new();
84 csr.add_edge("a", "L", "b").unwrap();
85 csr.add_edge("b", "L", "c").unwrap();
86 csr.compact().expect("no governor, cannot fail");
87
88 let batch = run(&csr);
89 let json = batch.to_json().unwrap();
90 let rows: Vec<serde_json::Value> = serde_json::from_slice(&json).unwrap();
91 let map: std::collections::HashMap<&str, f64> = rows
92 .iter()
93 .map(|r| {
94 (
95 r["node_id"].as_str().unwrap(),
96 r["centrality"].as_f64().unwrap(),
97 )
98 })
99 .collect();
100
101 assert!(map["b"] > map["a"]);
102 assert!(map["b"] > map["c"]);
103 }
104
105 #[test]
106 fn harmonic_disconnected() {

Callers

nothing calls this directly

Calls 9

add_edgeMethod · 0.80
collectMethod · 0.80
runFunction · 0.70
expectMethod · 0.45
compactMethod · 0.45
to_jsonMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45
as_f64Method · 0.45

Tested by

no test coverage detected