Last active
October 26, 2021 18:25
-
-
Save mfe-/bf262695677bd8ad0cb31d51e24ce7c4 to your computer and use it in GitHub Desktop.
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
public IDictionary<Guid, IEdge> AStarManhattanDistanceDictionary() | |
{ | |
IVertex goalToFind = null; | |
IVertex VertexFactoryDouble(int x, int y) | |
{ | |
var vertex = new Vertex<Point>(); | |
vertex.Value = new Point(x, y); | |
return vertex; | |
} | |
var g = GraphExtensions.GenerateGridGraph(1024, 1024, VertexFactoryDouble, (lastVertex) => goalToFind = lastVertex, null, 0.1); | |
Point goalPoint = ((IVertex<Point>)goalToFind).Value; | |
Func<IVertex, double> funcManhattanDistanceHeuristic = new Func<IVertex, double>((vertex) => | |
{ | |
Point currentPoint = ((IVertex<Point>)vertex).Value; | |
return Math.Abs(currentPoint.X - goalPoint.X) + Math.Abs(currentPoint.Y - goalPoint.Y); | |
}); | |
return g.Start.AStar(goalToFind, funcManhattanDistanceHeuristic); | |
} | |
[Benchmark] | |
public void AStarManhattanDistance() | |
{ | |
AStarManhattanDistanceDictionary().Consume(consumer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment