Skip to content

Instantly share code, notes, and snippets.

@mfe-
Last active October 26, 2021 18:25
Show Gist options
  • Save mfe-/bf262695677bd8ad0cb31d51e24ce7c4 to your computer and use it in GitHub Desktop.
Save mfe-/bf262695677bd8ad0cb31d51e24ce7c4 to your computer and use it in GitHub Desktop.
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