Description Usage Arguments Examples
A* algorithm for shortest path finding.
1 2 |
start |
beginning node |
goal |
ending node |
cost_estimate |
binary function of node, goal. Should return Lower bound guess of distance between them. |
edge_distance |
binary function of node, neighbor. Should return distance between them. |
neighbors |
function that takes a node and returns its neighbors as a list. |
is_goal_reached |
binary function of a node and the goal. Returns whether that node reached the goal. |
hash_func |
function that takes a node and returns something that can be used as the key in a list (e.g. a number, a string...). |
search_node_env |
custom environment to put node information in (may be useful for visualization). |
1 2 3 4 5 6 7 8 9 10 11 | nodes <- list(
A = c(B = 100, C = 20),
C = c(D = 20),
D = c(B = 20)
)
neighbors <- function(node) names(nodes[[node]])
cost_estimate <- function(node, goal) 1
edge_distance <- function(src, dst) nodes[[src]][dst]
is_goal_reached <- function(node, goal) identical(node, goal)
path <- astar('A', 'B', cost_estimate, edge_distance, neighbors, is_goal_reached)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.