Graaf

Work with directed graphs in Rust.
Table of Contents
- Installation
- Digraph Types
- Creating Digraphs
- Operations
- Algorithms
- Naming Conventions
- Project Goals
- Changelog
- License
Installation
Add the following to your Cargo.toml:
[]
= "0.70.0"
Digraph Types
Graaf provides three representations of directed graphs.
- The Adjacency List type represents unweighted sparse digraphs.
- The Adjacency Matrix type represents unweighted dense digraphs.
- The Weighted Adjacency List type represents arc-weighted sparse digraphs.
These types eagerly implement digraph operations and digraph algorithms.
Creating Digraphs
The gen module provides six digraph generators.
- The
Bicliquetrait generates a complete bipartite digraph. - The
Completetrait generates a digraph in which an arc connects every ordered pair of distinct vertices. - The
Cycletrait generates a digraph with a cycle of a given length. - The
Emptytrait generates a digraph with no arcs. - The
RandomTournamenttrait generates a random digraph in which an arc connects every unordered pair of distinct vertices. - The
Startrait generates 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.
Basic Operations
Individual digraph types implement the basic operations.
- The
AddArcWeightedtrait adds an arc to an arc-weighted digraph. - The
AddArctrait adds an arc to an unweighted digraph. - The
ArcWeighttrait returns the weight of an arc. - The
ArcsWeightedtrait returns the arcs and their weights in a digraph. - The
Arcstrait returns the arcs in a digraph. - The
Conversetrait returns the converse of a digraph. - The
HasArctrait checks if an arc exists in a digraph. - The
Indegreetrait returns the indegree of a vertex. - The
IsSimpletrait checks if a digraph contains no loops or parallel arcs. - The
Ordertrait returns the number of vertices. - The
OutNeighborsWeightedtrait returns the weighted out-neighbors of a vertex. - The
OutNeighborstrait returns the out-neighbors of a vertex. - The
Outdegreetrait returns the outdegree of a vertex. - The
RemoveArctrait removes an arc from a digraph. - The
Sizetrait returns the number of arcs in a digraph. - The
Verticestrait returns the vertices in a digraph.
Extended Operations
The extended traits derive their implementation from the basic operations.
- The
Degreetrait returns the degree of a vertex. - The
DegreeSequencetrait returns the degree sequence of a digraph. - The
HasEdgetrait checks if an edge exists in a digraph. - The
InNeighborstrait returns the in-neighbors of a vertex. - The
IsBalancedtrait checks if a digraph is balanced. - The
IsCompletetrait checks if a digraph is complete. - The
IsIsolatedtrait checks if a vertex is isolated. - The
IsOrientedtrait checks if a digraph is oriented. - The
IsPendanttrait checks if a vertex is a pendant. - The
IsRegulartrait checks if a digraph is regular. - The
IsSemicompletetrait checks if a digraph is semicomplete. - The
IsSubdigraphtrait checks if a digraph is a subdigraph. - The
IsSuperdigraphtrait checks if a digraph is a superdigraph. - The
IsSymmetrictrait checks if a digraph is symmetric. - The
IsTournamenttrait checks if a digraph is a tournament. - The
IsWalktrait checks if a sequence of vertices is a walk in a digraph.
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.
- The
single_source_distancesfunction finds 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.
These functions start from one or more source vertices and allow a custom step function, target predicate, distance array, breadth-first tree, and queue, where applicable.
- The
distancesfunction finds the shortest distances. - The
predecessorsfunction finds the predecessors. - The
shortest_pathfunction finds the shortest path.
These functions start from one source vertex.
- The
single_source_distancesfunction finds the shortest distances. - The
single_source_predecessorsfunction finds the predecessors. - The
single_pair_shortest_pathfunction finds 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.
- The
dfsafunction traverses the digraph. - The
dfsa_predecessorsfunction finds the predecessors. - The
acyclic_orderingfunction generates an acyclic ordering.
Dijkstra's Algorithm
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.
- The
distancesfunction finds the shortest distances. - The
predecessorsfunction finds the predecessors. - The
shortest_pathfunction finds the shortest path.
These functions start from one source vertex.
- The
single_source_distancesfunction finds the shortest distances. - The
single_source_predecessorsfunction finds the predecessors. - The
single_pair_shortest_pathfunction finds the shortest path.
Floyd-Warshall
The Floyd-Warshall algorithm finds the shortest paths between all pairs of vertices in an arc-weighted digraph.
- The
distancesfunction finds the shortest distances.
Breadth-First Tree
A breadth-first tree is the result of a breadth-first search.
These functions produce a breadth-first tree.
bfs::single_source_predecessorsbfs::predecessorsdijkstra::single_source_predecessorsdijkstra::predecessors
Distance Matrix
A distance matrix contains the shortest distances between all pairs of vertices in a digraph.
- The
centermethod finds the center of the digraph. - The
diametermethod finds the diameter of the digraph. - The
eccentricitiesmethod returns the eccentricities of the vertices. - The
is_connectedmethod checks if the digraph is connected. - The
peripherymethod finds 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
- Full documentation
- Extensive property tests
- Complete unit test and benchmark coverage
Changelog
See CHANGELOG.md for a list of changes.
License
Licensed under Apache License, Version 2.0 or MIT license at your option.