Possibly incorrect Ord for SmallestCostHolder (in astar)
glchapman opened this issue · comments
Here is the code in question:
impl<K: Ord> Ord for SmallestCostHolder<K> {
fn cmp(&self, other: &Self) -> Ordering {
match other.estimated_cost.cmp(&self.estimated_cost) {
Ordering::Equal => self.cost.cmp(&other.cost),
s => s,
}
}
}
It seems to me that the inner cost comparison should be other.cost.cmp(&self.cost)
preserving the sense (of the outer comparison) that if self has a lesser cost than other, cmp will produce Ordering::Greater
(for the max heap).
My apologies, this isn't really an issue. If two states have equal estimated_cost, then the only the only way one of them could have a lower cost is if it has a positive heuristic. Assuming an admissible heuristic (which never overestimates), this means the lower cost state cannot be a goal state, so it doesn't matter if it's produced after the higher cost state.