Giraffe.Algorithms.BellmanFord (giraffe v0.1.3)

Implementation of the Bellman-Ford algorithm for finding shortest paths in graphs.

Summary

Functions

Finds the shortest paths from a source vertex to all other vertices in the graph.

Types

edge()

@type edge() :: {vertex(), vertex(), number()}

graph()

@type graph() :: %{required(vertex()) => [edge()]}

vertex()

@type vertex() :: any()

Functions

shortest_paths(graph, source)

@spec shortest_paths(graph(), vertex()) ::
  {:ok, %{required(vertex()) => number()}} | {:error, :negative_cycle}

Finds the shortest paths from a source vertex to all other vertices in the graph.

Returns a map of vertices to their shortest distance from the source. If a negative cycle is detected, returns {:error, :negative_cycle}.