Giraffe.Graph.Directed (giraffe v0.1.4)
Implementation of a directed graph with weighted edges. Vertices can be any term, and edges have numeric weights.
Summary
Functions
Adds a weighted edge between two vertices in the graph. The vertices will be added to the graph if they don't already exist.
Adds a vertex to the graph.
Finds all maximal cliques in the graph. A clique is a subset of vertices where every vertex is connected to every other vertex. Only considers bidirectional edges.
Returns a list of all edges in the graph as tuples of {from, to, weight}.
Finds all possible paths between two vertices. Returns a list of tuples containing the path and its total weight.
Finds the shortest path between two vertices using Dijkstra's algorithm. Returns {:ok, path, total_weight} if a path exists, or :no_path if no path exists.
Checks if the graph is acyclic.
Checks if the graph is cyclic.
Creates a new empty directed graph.
Finds the shortest paths from a source vertex to all other vertices using the Bellman-Ford algorithm. Returns {:ok, distances} with distances from source to all reachable vertices, or {:error, :negative_cycle} if a negative cycle is detected.
Returns a list of all vertices in the graph.
Types
Functions
Adds a weighted edge between two vertices in the graph. The vertices will be added to the graph if they don't already exist.
Adds a vertex to the graph.
Finds all maximal cliques in the graph. A clique is a subset of vertices where every vertex is connected to every other vertex. Only considers bidirectional edges.
Returns a list of all edges in the graph as tuples of {from, to, weight}.
Finds all possible paths between two vertices. Returns a list of tuples containing the path and its total weight.
Finds the shortest path between two vertices using Dijkstra's algorithm. Returns {:ok, path, total_weight} if a path exists, or :no_path if no path exists.
Checks if the graph is acyclic.
Returns true
if the graph is acyclic, otherwise false
.
Checks if the graph is cyclic.
Returns true
if the graph contains cycles, otherwise false
.
@spec new() :: t()
Creates a new empty directed graph.
@spec reachable(t(), [Giraffe.Graph.vertex()]) :: [Giraffe.Graph.vertex()]
Finds the shortest paths from a source vertex to all other vertices using the Bellman-Ford algorithm. Returns {:ok, distances} with distances from source to all reachable vertices, or {:error, :negative_cycle} if a negative cycle is detected.
Returns a list of all vertices in the graph.