Gravy.PathFinder
0.1.1-alpha
See the version list below for details.
dotnet add package Gravy.PathFinder --version 0.1.1-alpha
NuGet\Install-Package Gravy.PathFinder -Version 0.1.1-alpha
<PackageReference Include="Gravy.PathFinder" Version="0.1.1-alpha" />
paket add Gravy.PathFinder --version 0.1.1-alpha
#r "nuget: Gravy.PathFinder, 0.1.1-alpha"
// Install Gravy.PathFinder as a Cake Addin #addin nuget:?package=Gravy.PathFinder&version=0.1.1-alpha&prerelease // Install Gravy.PathFinder as a Cake Tool #tool nuget:?package=Gravy.PathFinder&version=0.1.1-alpha&prerelease
Path Finder
A simple to use collection of various path finding algorithms.
This is a work in progress. All API's are subject to change significantly.
Goals
The goal of this project is to provide a variety of easy to use and well performing path finding algorithms that can be used with little modification of a projects existing code.
Why?
A* and other graph solvers are well documented, and honestly pretty "easy" to implement right? Well as I found out, not exactly. Yes they are well documented, but actually implementing them with good performance is another story. Also, most implementations I found were very specific to the project they were implemented in, and did not allow for much " configuration" of how the solver would perform. This project was born from that frustration.
Installing
via .NET CLI
dotnet add package Gravy.PathFinder --version 0.1.1-alpha
via PackageReference
<PackageReference Include="Gravy.PathFinder" Version="0.1.1-alpha"/>
WARNING Until v1 is release, the API is subject to breaking changes.
Usage
PathFinder uses the term "Graph" to represent any network of connected nodes. A 2d or 3d map is also a graph, with each position on the map being nodes in the graph connected by traversing through the map. A Graph could represent anything though, for example persons in a social network, with friendships allowing traversal through the graph.
View the Api Documentation for a complete reference.
Simple Usage
You can either update the "nodes" of your graph to implement
ITraversableNode
, or create
a INodeTraverser
.
To find a path, use one of the included solvers.
using PathFinder.Solvers.Generic;
YourNode fromNode = YourGraph.GetNode();
YourNode toNode = YourGraph.GetNode();
// just get a path using A*
var state = AStar.Solve(fromNode, toNode, out IList path);
if (state == SolverState.Success)
UsePath(path);
// create a greedy solver and run it manually
// giving time every 100 ticks for other work
// to be completed.
var solver = new Greedy(fromNode, toNode, new YourNodeTraverser());
solver.MaxTicks = 20000;
while (solver.State == SolverState.Incomplete) {
solver.Start(100); // run 100 ticks
DoOtherWork();
}
if (solver.State == SolverState.Success)
MoveEntity(entity, solver.Path)
For an example of ITraversableNode
, see
SimpleWorld.Map.Position
.
For examples of INodeTraverser
, see
Traversers
.
Note: When implementing, it is important to make sure EstimatedCostTo
/EstimatedCost
returns the best case cost for the best performance.
*Note 2: You must implement either a INodeTraverser
, or
implement ITraversableNode
on your existing graph. If no traverser is given to
a solver, and the nodes do not implement ITraversableNode
, then the solver
will throw an exception.
Solver Types
All Generic solvers implement IGraphSolver .
An implementation of the traditional A* algorithm with an adjustable greed factor.
The greed factor determines how exhaustive the search will be. Greed factors closer to zero will check more possible nodes, while greater than zero will favor reducing the estimated. A greed factor of one is equivalent to the standard A* method.
The greedy solvers traverses a graph ignoring any travel costs and attempts to reduce the remaining distance only. This can be useful to determine if a path is even possible, or in very open graphs with little to no obstacles or movement costs.
An exhaustive graph searcher, or crawler. Starts at node and searches every found node until the destination is found. This is really only useful in graphs when an estimation function is impossible, as the A* algorithm with greed ⇐ 1 will always find the best path, at a fraction of the cost of Breadth First.
Node Traversers
All of the generic solvers can be given an INodeTraverser to replace or augment the graphs own traversal methods. An example of when to use an INodeTraverser could be to implement custom traversal patterns in a game on the entities themselves.
Future Plans
- Writing more documentation/guides to using.
- Adding "Dynamic" algorithms which modify their running parameters based on a set of configurable metrics (time to solve, distance remaining, etc).
- Adding "Spatially aware" path finding algorithms (Hierarchical, clustered, ray tracing, etc).
- Adding Thread Safety to the solvers (or maybe thread safe alternatives at the cost of performance).
- Testing in Unity and MonoGame.
License
The MIT License (MIT) Copyright © 2021 Kevin Gravier
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 was computed. netstandard1.2 was computed. netstandard1.3 was computed. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.0
- C5 (>= 2.5.3)
- JetBrains.Annotations (>= 2021.1.0)
- NETStandard.Library (>= 1.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.2-alpha | 197 | 4/21/2021 |
0.1.1-alpha | 145 | 4/21/2021 |
0.1.0-alpha | 181 | 4/21/2021 |