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:
3 files changed
+89
-6
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user