From 75b012bab85b5089b95d3163b90c0b1c21c7c559 Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Sat, 5 Aug 2023 23:06:10 +0800 Subject: [PATCH] fix Yen K-shortest when there are not enough shortest paths https://github.com/cozodb/cozo/issues/166 --- cozo-core/src/fixed_rule/algos/yen.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cozo-core/src/fixed_rule/algos/yen.rs b/cozo-core/src/fixed_rule/algos/yen.rs index f5986f30..be72e8e6 100644 --- a/cozo-core/src/fixed_rule/algos/yen.rs +++ b/cozo-core/src/fixed_rule/algos/yen.rs @@ -202,7 +202,10 @@ fn k_shortest_path_yen( } candidates.sort_by(|(a_cost, _), (b_cost, _)| b_cost.total_cmp(a_cost)); let shortest = candidates.pop().unwrap(); - k_shortest.push(shortest); + let shortest_dist = shortest.0; + if shortest_dist.is_finite() { + k_shortest.push(shortest); + } } Ok(k_shortest) }