Giraffe.Graph.Undirected (giraffe v0.1.3)
Implementation of an undirected graph with weighted edges. Vertices can be any term, and edges have numeric weights.
Summary
Functions
Adds an edge between two vertices with the given weight. If the vertices don't exist, they will be added to the graph.
Adds a vertex to the graph.
Detects all maximal cliques in the graph using the Bron-Kerbosch algorithm.
Returns a list of all edges in the graph. Each edge is represented as a tuple {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, :no_path otherwise.
Checks if the graph is acyclic (contains no cycles). Returns true if the graph has no cycles, false otherwise.
Checks if the graph contains any cycles. Returns true if the graph has cycles, false otherwise.
Creates a new empty undirected graph.
Returns a list of vertices that are reachable from any of the given vertices. Includes the starting vertices themselves as paths of length zero are allowed.
Returns a list of all vertices in the graph.
Types
Functions
Adds an edge between two vertices with the given weight. If the vertices don't exist, they will be added to the graph.
Adds a vertex to the graph.
Detects all maximal cliques in the graph using the Bron-Kerbosch algorithm.
Returns a list of cliques, where each clique is a list of vertices. A clique is a subset of vertices that forms a complete subgraph.
Returns a list of all edges in the graph. Each edge is represented as a tuple {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, :no_path otherwise.
Checks if the graph is acyclic (contains no cycles). Returns true if the graph has no cycles, false otherwise.
Checks if the graph contains any cycles. Returns true if the graph has cycles, false otherwise.
@spec new() :: t()
Creates a new empty undirected graph.
Returns a list of vertices that are reachable from any of the given vertices. Includes the starting vertices themselves as paths of length zero are allowed.
Examples
iex> g = Giraffe.Graph.Undirected.new()
...> g = g |> Giraffe.Graph.Undirected.add_edge(1, 2, 1) |> Giraffe.Graph.Undirected.add_edge(2, 3, 1)
...> Giraffe.Graph.Undirected.reachable(g, [1])
[1, 2, 3]
Returns a list of all vertices in the graph.