astar: A* algorithm for shortest path finding.

Description Usage Arguments Examples

Description

A* algorithm for shortest path finding.

Usage

1
2
astar(start, goal, cost_estimate, edge_distance, neighbors,
  is_goal_reached, hash_func = identity, search_node_env = NULL)

Arguments

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).

Examples

 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)

machow/astar-r documentation built on May 12, 2019, 7:35 a.m.