Meridian.Pathfinding (Meridian v0.1.0)

Copy Markdown View Source

Spatially-aware pathfinding wrappers around yog_ex algorithms.

Injects geographic heuristics and distance-based edge weight functions into the core graph pathfinders.

Summary

Functions

A* shortest path using haversine distance as the heuristic.

Functions

a_star(graph, opts)

@spec a_star(
  Meridian.Graph.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

A* shortest path using haversine distance as the heuristic.

Options

  • :from — start node id (required)
  • :to — goal node id (required)
  • :weight_fn — function (graph, from, to) -> number for edge cost. Defaults to Meridian.CRS.distance/3 if nodes have point geometries.

Examples

iex> g = Meridian.Graph.new()
iex> g = g
...>   |> Meridian.Graph.add_node(:a, %{geometry: %Geo.Point{coordinates: {0.0, 0.0}}})
...>   |> Meridian.Graph.add_node(:b, %{geometry: %Geo.Point{coordinates: {0.0, 1.0}}})
...>   |> Meridian.Graph.add_edge_ensure(:a, :b, 100.0)
iex> {:ok, path} = Meridian.Pathfinding.a_star(g, from: :a, to: :b)
iex> path.nodes
[:a, :b]

iex> g = Meridian.Graph.new()
iex> Meridian.Pathfinding.a_star(g, from: :missing, to: :also_missing)
** (ArgumentError) start node :missing does not exist in graph