public void FindPath_InitializedNodegrid_ValuesPotentialFieldAreCorrect() { var potentialFieldAlgorithm = new PotentialFieldAlgorithm(0); var definitionNodeGrid = new DefinitionNodeGrid(GenerateNodeGridConnections.All, 3, 3, new Vector2(1, 1)); var start = definitionNodeGrid.NodeGrid[0, 0]; var end = definitionNodeGrid.NodeGrid[2, 2]; var pathfindingNetwork = new DijkstraNodeGrid(definitionNodeGrid); var pathRequest = new PathRequest <IPath>(start, end); var potentialField = potentialFieldAlgorithm.FindPath(pathfindingNetwork, pathRequest, out var _); const float tolerance = 0.001f; Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[0, 0]) - 4f) < tolerance, true); Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[1, 0]) - 3f) < tolerance, true); Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[2, 0]) - 2f) < tolerance, true); Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[0, 1]) - 3f) < tolerance, true); Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[1, 1]) - 2f) < tolerance, true); Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[2, 1]) - 1f) < tolerance, true); Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[0, 2]) - 2f) < tolerance, true); Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[1, 2]) - 1f) < tolerance, true); Assert.AreEqual(Math.Abs(Math.Abs(potentialField.PotentialArray[2, 2]) - 0f) < tolerance, true); }
public static IPathfinder <DefinitionNodeGrid, DijkstraNodeGrid, PotentialField> CreatePotentialFieldPathfinder(this IPathfindaxManager pathfindaxManager, DefinitionNodeGrid nodeGrid, int maxClearance, int maxCachedFlowFields, int amountOfThreads = 1) { var pathfinder = pathfindaxManager.CreatePathfinder(nodeGrid, new PotentialFieldAlgorithm(maxCachedFlowFields, nodeGrid.NodeCount), (definitionNodeGrid, algorithm) => { var dijkstraNodeGrid = new DijkstraNodeGrid(definitionNodeGrid, maxClearance); return(CreateRequestProcesser(dijkstraNodeGrid, algorithm)); }, amountOfThreads); pathfinder.Start(); return(pathfinder); }
public void Setup() { var factory = new DefinitionNodeGridFactory(); var nodeGrid = factory.GeneratePreFilledArray(GenerateNodeGridConnections.All, 320, 200); _definitionNodeGrid = new DefinitionNodeGrid(nodeGrid, new Vector2(1, 1)); _dijkstraNodeGrid = new DijkstraNodeGrid(_definitionNodeGrid, 1); _algorithm = new DijkstraAlgorithm(_definitionNodeGrid.NodeCount); _pathRequest = PathRequest.Create(Substitute.For <IPathfinder <NodePath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(319, 199)); _nodeNetwork = _dijkstraNodeGrid.GetCollisionLayerNetwork(_pathRequest.CollisionCategory); }
private PotentialField RunPotentialField(DefinitionNodeGrid definitionNodeGrid, Point2 gridStart, Point2 gridEnd, out bool succes) { var potentialFieldAlgorithm = new PotentialFieldAlgorithm(0, definitionNodeGrid.NodeCount); var start = definitionNodeGrid.NodeGrid.ToIndex(gridStart.X, gridStart.Y); var end = definitionNodeGrid.NodeGrid.ToIndex(gridEnd.X, gridEnd.Y); var pathfindingNetwork = new DijkstraNodeGrid(definitionNodeGrid, 5); var pathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), start, end, PathfindaxCollisionCategory.Cat1); return(potentialFieldAlgorithm.FindPath(pathfindingNetwork, pathRequest, out succes)); }
private WaypointPath RunDijkstra(DefinitionNodeGrid definitionNodeGrid, Point2 gridStart, Point2 gridEnd) { var dijkstraAlgorithm = new DijkstraAlgorithm(definitionNodeGrid.NodeCount); var start = definitionNodeGrid.NodeGrid.ToIndex(gridStart.X, gridStart.Y); var end = definitionNodeGrid.NodeGrid.ToIndex(gridEnd.X, gridEnd.Y); var pathfindingNetwork = new DijkstraNodeGrid(definitionNodeGrid, 5); var pathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), start, end, PathfindaxCollisionCategory.Cat1); var path = dijkstraAlgorithm.FindPath(pathfindingNetwork, pathRequest); return(path); }
public static IPathfinder <DefinitionNodeGrid, DijkstraNodeGrid, PotentialField> CreatePotentialFieldPathfinder(this IPathfindaxManager pathfindaxManager, DefinitionNodeGrid nodeGrid, int maxClearance, int maxCachedFlowFields, int amountOfThreads = 1) { var pathfinder = pathfindaxManager.CreatePathfinder(nodeGrid, new PotentialFieldAlgorithm(nodeGrid.NodeCount), (definitionNodeGrid, algorithm, cache) => { var dijkstraNodeGrid = new DijkstraNodeGrid(definitionNodeGrid, maxClearance); return(CreateRequestProcesser(dijkstraNodeGrid, algorithm, cache)); }, maxCachedFlowFields > 0 ? new ConcurrentCache <IPathRequest, PotentialField>(maxCachedFlowFields, new SingleSourcePathRequestComparer()) : null, amountOfThreads); pathfinder.Start(); return(pathfinder); }