yog/pathfinding/path

Shared types and utilities for pathfinding algorithms.

Types

Represents a path through the graph with its total weight.

pub type Path(e) {
  Path(nodes: List(Int), total_weight: e)
}

Constructors

  • Path(nodes: List(Int), total_weight: e)

Values

pub fn hydrate_path(
  graph: model.Graph(n, e),
  node_ids: List(Int),
) -> List(#(Int, Int, e))

Hydrates a list of node IDs with the actual edge data between consecutive nodes.

This is useful when you have a path from a pathfinding algorithm and need to reconstruct the full sequence of edges with their weights/attributes.

Example

let graph =
  model.new(model.Directed)
  |> model.add_edge_ensure(from: 1, to: 2, with: "CAR", default: Nil)
  |> model.add_edge_ensure(from: 2, to: 3, with: "BUS", default: Nil)

let path = [1, 2, 3]
let edges = path.hydrate_path(graph, path)
// => [#(1, 2, "CAR"), #(2, 3, "BUS")]
Search Document