Graaf

Rust-powered directed graphs.
Table of Contents
- Installation
- Digraph Types
- Creating Digraphs
- Operations
- Algorithms
- Naming Conventions
- Project Goals
- Changelog
- License
- Contact
- Links
Installation
Add the following to your Cargo.toml:
[]
= "0.82.2"
Digraph Types
Graaf provides representations of directed graphs.
adjacency_listrepresents unweighted sparse digraphs.adjacency_matrixrepresents unweighted dense digraphs.adjacency_list_weightedrepresents arc-weighted sparse digraphs.
These types eagerly implement digraph operations and algorithms.
Creating Digraphs
The gen module provides digraph generators.
Bicliquegenerates a complete bipartite digraph.Circuitgenerates a circuit digraph.Completegenerates a complete digraph.Cyclegenerates a bidirectional circuit.Emptygenerates a digraph with no arcs.ErdosRenyigenerates a random digraph.Pathgenerates a path digraph.RandomTournamentgenerates a random tournament.Stargenerates a star digraph.
Each digraph representation can be constructed with the operations in the op module.
Operations
The op module provides digraph operation traits. The digraph types implement these traits. One can implement these traits for custom digraph types. Operations form the foundation for algorithms.
AddArcWeightedadds an arc to an arc-weighted digraph.AddArcadds an arc to an unweighted digraph.ArcWeightreturns an arc's weight.ArcsWeightedreturns a digraph's weighted arcs.Arcsreturns a digraph's arcs.Complementreturns a digraph's complement.Conversereturns a digraph's converse.DegreeSequencereturns a digraph's degree sequence.Degreereturns a vertex's degree.HasArcchecks whether a digraph contains an arc.HasEdgechecks whether a digraph contains an edge.HasWalkchecks whether a digraph contains a walk.InNeighborsreturns a vertex's in-neighbors.IndegreeSequencereturns a digraph's indegree sequence.Indegreereturns a vertex's indegree.IsBalancedchecks whether a digraph is balanced.IsCompletechecks whether a digraph is complete.IsIsolatedchecks whether a vertex is isolated.IsOrientedchecks whether a digraph is oriented.IsPendantchecks whether a vertex is a pendant.IsRegularchecks whether a digraph is regular.IsSemicompletechecks whether a digraph is semicomplete.IsSimplechecks whether a digraph is simple.IsSpanningSubdigraphchecks whether a digraph spans a superdigraph.IsSubdigraphchecks whether a digraph is a subdigraph.IsSuperdigraphchecks whether a digraph is a superdigraph.IsSymmetricchecks whether a digraph is symmetric.IsTournamentchecks whether a digraph is a tournament.Orderreturns the number of vertices in a digraph.OutNeighborsWeightedreturns a vertex's weighted out-neighbors.OutNeighborsreturns a vertex's out-neighbors.OutdegreeSequencereturns a digraph's outdegree sequence.Outdegreereturns a vertex's outdegree.RemoveArcremoves an arc from a digraph.SemidegreeSequencereturns a digraph's semidegree sequence.Sinksreturns a digraph's sinks.Sizereturns the number of arcs in a digraph.Sourcesreturns a digraph's sources.Verticesreturns a digraph's vertices.
Algorithms
The algo module provides digraph algorithms.
Bellman-Ford-Moore
The Bellman-Ford-Moore algorithm finds the shortest paths in an arc-weighted digraph with negative weights.
single_source_distancesfinds the shortest distances.
Breadth-First Search (BFS)
A breadth-first search explores the vertices of an unweighted digraph in order of their distance from a source.
bfs::Bfsiterates over the vertices.bfs_dist::Bfsiterates over the vertices and their distance from the source.bfs_successors::Bfsiterates over the vertices and their successors.bfs_dist::Bfs::distancesfinds the shortest distances.bfs_successors::Bfs::predecessorsfinds the predecessors.bfs_successors::Bfs::shortest_pathfinds the shortest path.
Depth-First Search (DFS)
A depth-first search explores the vertices of an unweighted digraph in order of their depth from a source.
dfs::Dfsiterates over the vertices.dfs_dist::Dfsiterates over the vertices and their distance from the source.
Dijkstra
Dijkstra's algorithm finds the shortest paths in an arc-weighted digraph.
dijkstra::Dijkstraiterates over the vertices.dijkstra_dist::Dijkstraiterates over the vertices.dijkstra_pred::Dijkstraiterates over the vertices and their predecessors.dijkstra_dist::Dijkstra::distancesfinds the shortest distances.dijkstra_pred::Dijkstra::predecessorsfinds the predecessors.dijkstra_pred::Dijkstra::shortest_pathfinds the shortest path.
Floyd-Warshall
The Floyd-Warshall algorithm finds the shortest paths between all pairs of vertices in an arc-weighted digraph.
distancesfinds the shortest distances.
Tarjan
Tarjan's algorithm finds the strongly connected components in a digraph.
strongly_connected_componentsfinds the strongly connected components.
Predecessor Tree
A PredecessorTree is the result of a breadth-first search.
These functions produce a predecessor tree.
Distance Matrix
A DistanceMatrix contains the shortest distances between all pairs of vertices in a digraph.
centerfinds the center of the digraph.diameterfinds the diameter of the digraph.eccentricitiesreturns the eccentricities of the vertices.is_connectedchecks if the digraph is connected.peripheryfinds the periphery of the digraph.
Naming Conventions
sdenotes a source vertex.tdenotes a target vertex.udenotes a tail vertex or the first vertex in scope.vdenotes a head vertex or the second vertex in scope.wdenotes the weight of an arc.xdenotes a tail vertex or the third vertex in scope.ydenotes a head vertex or the fourth vertex in scope.
Project Goals
- A flexible API for digraph operations
- A comprehensive set of algorithms
- Generators for common digraphs
- Competitive performance
- Complete documentation
- Extensive property tests
- Complete unit test coverage
Changelog
See CHANGELOG.md for a list of changes.
License
Licensed under Apache License, Version 2.0 or MIT license at your option.
Contact
Feel free to reach out with questions or suggestions.