Doloro GDK 22 .1.0 Beta
by Tauri Interactive
Doloro.Graphs.AStarPath Class Reference

Detailed Description

Implementation of the A* pathfinding algorithm.

Python script:

frontier = PriorityQueue()
frontier.put(start, 0)
came_from = {}
cost_so_far = {}
came_from[start] = None
cost_so_far[start] = 0
while not frontier.empty():
current = frontier.get()
if current == goal:
break
for next in graph.neighbors(current):
new_cost = cost_so_far[current] + graph.cost(current, next)
if next not in cost_so_far or new_cost < cost_so_far[next]:
cost_so_far[next] = new_cost
priority = new_cost + heuristic(goal, next)
frontier.put(next, priority)
came_from[next] = current
An abstract data-type in which each element additionally has a "priority" associated with it....
Definition: PriorityQueue.cs:18
Inheritance diagram for Doloro.Graphs.AStarPath:
Collaboration diagram for Doloro.Graphs.AStarPath:

Public Types

enum  State {
  NotComputed , Built , Failed , Relayed ,
  InProgress
}
 

Public Member Functions

 AStarPath (GraphNode from, GraphNode to)
 
override ICollection< GraphNodeBuild ()
 Builds path using A* algorithm between declared points. More...
 
override IEnumerator BuildCoroutine ()
 Builds the path using A* algorithm in Coroutine friendly way. More...
 
override async Task< ICollection< GraphNode > > BuildAsync ()
 Builds the path using A* algorithm asynchronously. More...
 
Connection GetConection (GraphNode achivedNode)
 Looking for connection that leaded the path to the certain node. More...
 
bool TryLoadCache ()
 Loads path cache to the instance in case if exists. More...
 
void Release ()
 Releasing cached path between two nodes in case if has been built.
 
void MakeFailed ()
 Forces path to has State.Failed state.
 
IEnumerator< GraphNodeGetEnumerator ()
 Enumerated computed path. More...
 

Static Public Member Functions

static void ReleaseCache ()
 Releases entire cache.
 
static bool TryGetCachedPath (GraphNode from, GraphNode to, out Path path)
 Looking for last cached path between two nodes. More...
 
static bool TryGetCachedPath (Type pathType, GraphNode from, GraphNode to, out Path path)
 Looking for cached path between two nodes. More...
 
static bool TryGetCachedPath< T > (GraphNode from, GraphNode to, out T path)
 Looking for cached path between two nodes. More...
 

Static Protected Member Functions

static void SetPathToCache (Path path)
 Updating cache registry with a path entry. More...
 

Properties

static int CachedPathsCount [get]
 Count of paths in cache.
 
ReadOnlyCollection< GraphNodepath [get, protected set]
 Public built path.
 
int Length [get]
 Length of the built path. -1 is not built yet.
 
GraphNode from [get]
 Path start graph's node.
 
GraphNode to [get]
 Path finish graph's node.
 
State state [get, protected set]
 Current state of the path build.
 
bool isComputed [get]
 Is the path has been computed.
 
bool isCached [get]
 Checks is the path located at the cache registry to fast access. More...
 

Events

static Action< PathPathReleased
 Occurs when any path is no longer exists in cache.
 

Member Enumeration Documentation

◆ State

enum Doloro.Graphs.Path.State
inherited
Enumerator
NotComputed 

Path has no been computed yet.

Built 

Pathfinding has been finished with a success.

Failed 

Pathfinding has been failed.

Relayed 

Path build has been skipped due to exist of cached path.

InProgress 

Pathfinding in the process.

Member Function Documentation

◆ Build()

override ICollection< GraphNode > Doloro.Graphs.AStarPath.Build ( )
virtual

Builds path using A* algorithm between declared points.

Returns
Collection of nodes selected as path.

Reimplemented from Doloro.Graphs.Path.

◆ BuildAsync()

override async Task< ICollection< GraphNode > > Doloro.Graphs.AStarPath.BuildAsync ( )
virtual

Builds the path using A* algorithm asynchronously.

Returns
Task that returns collection of nodes selected as path.

Reimplemented from Doloro.Graphs.Path.

◆ BuildCoroutine()

override IEnumerator Doloro.Graphs.AStarPath.BuildCoroutine ( )
virtual

Builds the path using A* algorithm in Coroutine friendly way.

Returns
Enumerator can be used in unity coroutines.

Reimplemented from Doloro.Graphs.Path.

◆ GetConection()

Connection Doloro.Graphs.AStarPath.GetConection ( GraphNode  achivedNode)

Looking for connection that leaded the path to the certain node.

Parameters
achivedNodeNode that has been achieved by the path.
Returns
Connection instance.

◆ GetEnumerator()

IEnumerator< GraphNode > Doloro.Graphs.Path.GetEnumerator ( )
inherited

Enumerated computed path.

Returns
Enumerator of the path included nodes. Empty collection in case if state is not State.Built or State.Relayed.

◆ SetPathToCache()

static void Doloro.Graphs.Path.SetPathToCache ( Path  path)
staticprotectedinherited

Updating cache registry with a path entry.

Parameters
pathPath to set.

Decline caching of garbage paths with the 1 length.

◆ TryGetCachedPath() [1/2]

static bool Doloro.Graphs.Path.TryGetCachedPath ( GraphNode  from,
GraphNode  to,
out Path  path 
)
staticinherited

Looking for last cached path between two nodes.

Parameters
fromStart point.
toEnd point
pathPath instance if found.
Returns
Is the instance has been found.

◆ TryGetCachedPath() [2/2]

static bool Doloro.Graphs.Path.TryGetCachedPath ( Type  pathType,
GraphNode  from,
GraphNode  to,
out Path  path 
)
staticinherited

Looking for cached path between two nodes.

Parameters
pathTypeType of the path processor.
fromStart point.
toEnd point
pathPath instance if found.
Returns
Is the instance has been found.

◆ TryGetCachedPath< T >()

static bool Doloro.Graphs.Path.TryGetCachedPath< T > ( GraphNode  from,
GraphNode  to,
out T  path 
)
staticinherited

Looking for cached path between two nodes.

Template Parameters
TType of the path processor.
Parameters
fromStart point.
toEnd point
pathPath instance if found.
Returns
Is the instance has been found.
Type Constraints
T :Path 

◆ TryLoadCache()

bool Doloro.Graphs.Path.TryLoadCache ( )
inherited

Loads path cache to the instance in case if exists.

Returns
Is the cache has been loaded.

Property Documentation

◆ isCached

bool Doloro.Graphs.Path.isCached
getinherited

Checks is the path located at the cache registry to fast access.

See also
Release

The documentation for this class was generated from the following file: