routing: improve equal cost route comparison

When the (virtual) payment attempt cost is set to zero, probabilities
are no longer a factor in determining the best route. In case of routes
with equal costs, we'd just go with the first one found. This commit
refines this behavior by picking the route with the highest probability.
So even though probability doesn't affect the route cost, it is still
used as a tie breaker.
This commit is contained in:
Joost Jager committed 2019-12-02 14:23:57 +01:00
1 parent d59aba35a0
commit 3aaf32dc2e
3 files changed
+89 -6

No files matched your search

+5
View File
@@ -73,6 +73,11 @@ func (d *distanceHeap) Len() int { return len(d.nodes) }
//
// NOTE: This is part of the heap.Interface implementation.
func (d *distanceHeap) Less(i, j int) bool {
// If distances are equal, tie break on probability.
if d.nodes[i].dist == d.nodes[j].dist {
return d.nodes[i].probability > d.nodes[j].probability
}
return d.nodes[i].dist < d.nodes[j].dist
}