-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0ad6d0
commit 483cb84
Showing
3 changed files
with
37 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Dijkstra.NET.ShortestPath | ||
{ | ||
internal class HeuristicNodeComparer : NodeComparer | ||
{ | ||
private readonly Func<uint, uint, int> _heuristic; | ||
|
||
public HeuristicNodeComparer(IDictionary<uint, int> distance, Func<uint, uint, int> heuristic) : base(distance) | ||
{ | ||
_heuristic = heuristic; | ||
} | ||
|
||
public override int Compare(uint x, uint y) | ||
{ | ||
int xDistance = _distance.ContainsKey(x) ? _distance[x] + _heuristic(x, y) : Int32.MaxValue; | ||
int yDistance = _distance.ContainsKey(y) ? _distance[y] + _heuristic(y, x) : Int32.MaxValue; | ||
|
||
int comparer = xDistance.CompareTo(yDistance); | ||
|
||
if (comparer == 0) | ||
{ | ||
return x.CompareTo(y); | ||
} | ||
|
||
return comparer; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters