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.80.0"
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 digraph 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.
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 arcs and their weights.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.- [
HasWalk] checks 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 does not contain loops or parallel arcs.IsSpanningSubdigraphchecks whether a digraph is a spanning subdigraph.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 out-neighbors and their weights.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_depth::Bfs::distancesfinds the distances.bfs_depth::Bfsiterates over the vertices and their depths.bfs_successors::Bfs::predecessorsfinds the predecessors.bfs_successors::Bfs::shortest_pathfinds the shortest path.bfs_successors::Bfsiterates over the vertices and their successors.
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_depth::Dfsiterates over the vertices and their depths.
Dijkstra
Dijkstra's algorithm finds the shortest paths in an arc-weighted digraph.
These functions start from one or more source vertices and allow a custom step function, target predicate, distance array, and heap, where applicable.
distancesfinds the shortest distances.predecessorsfinds the predecessors.shortest_pathfinds the shortest path.
These functions start from one source vertex.
single_pair_shortest_pathfinds the shortest path.single_source_distancesfinds the shortest distances.single_source_predecessorsfinds the predecessors.
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.
Types
These types are produced by the algorithms.
Predecessor Tree
A predecessor tree is the result of a breadth-first search.
These functions produce a predecessor tree.
Distance Matrix
A distance matrix 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.