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.71.5"
Digraph Types
Graaf provides three 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 six 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.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.
Basic Operations
Individual digraph types implement the basic operations.
AddArcWeightedadds an arc to an arc-weighted digraph.AddArcadds an arc to an unweighted digraph.ArcWeightreturns the weight of an arc.ArcsWeightedreturns the arcs and their weights in a digraph.Arcsreturns the arcs in a digraph.Conversereturns the converse of a digraph.HasArcchecks if an arc exists in a digraph.Indegreereturns the indegree of a vertex.IsSimplechecks if a digraph contains no loops or parallel arcs.Orderreturns the number of vertices.OutNeighborsWeightedreturns the weighted out-neighbors of a vertex.OutNeighborsreturns the out-neighbors of a vertex.Outdegreereturns the outdegree of a vertex.RemoveArcremoves an arc from a digraph.Sizereturns the number of arcs in a digraph.Verticesreturns the vertices in a digraph.
Extended Operations
The extended traits derive their implementation from the basic operations.
Complementreturns the complement of a digraph.Degreereturns the degree of a vertex.DegreeSequencereturns the degree sequence of a digraph.HasEdgechecks if an edge exists in a digraph.InNeighborsreturns the in-neighbors of a vertex.IsBalancedchecks if a digraph is balanced.IsCompletechecks if a digraph is complete.IsIsolatedchecks if a vertex is isolated.IsOrientedchecks if a digraph is oriented.IsPendantchecks if a vertex is a pendant.IsRegularchecks if a digraph is regular.IsSemicompletechecks if a digraph is semicomplete.IsSpanningSubdigraphchecks if a digraph is a spanning subdigraph.IsSubdigraphchecks if a digraph is a subdigraph.IsSuperdigraphchecks if a digraph is a superdigraph.IsSymmetricchecks if a digraph is symmetric.IsTournamentchecks if a digraph is a tournament.IsWalkchecks 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.
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.
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.
distancesfinds the shortest distances.predecessorsfinds the predecessors.shortest_pathfinds the shortest path.
These functions start from one source vertex.
single_source_distancesfinds the shortest distances.single_source_predecessorsfinds the predecessors.single_pair_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.
dfsatraverses the digraph.dfsa_predecessorsfinds the predecessors.acyclic_orderinggenerates 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.
distancesfinds the shortest distances.predecessorsfinds the predecessors.shortest_pathfinds the shortest path.
These functions start from one source vertex.
single_source_distancesfinds the shortest distances.single_source_predecessorsfinds the predecessors.single_pair_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's Algorithm
Tarjan's algorithm finds the strongly connected components in a digraph.
strongly_connected_componentsfinds the strongly connected components.
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.
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
- 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.