|
ADS
Algorithms and Data Structures
|
The visits of a GRAPH of section 9.5 and their applications, each in \( \Theta( n + m ) \) time on lists or vectors of adjacency: More...
#include "ADS/Contract.h"#include "ADS/graph/Graph.h"#include "ADS/graph/ListGraph.h"#include "ADS/queue/ArrayQueue.h"#include <algorithm>#include <concepts>#include <cstddef>#include <deque>#include <limits>#include <set>#include <utility>#include <vector>#include "ADS/graph/impl/Visit.tpp"#include "ADS/graph/StrongComponents.h"Go to the source code of this file.
Classes | |
| struct | ADS::VisitCounts |
| what a visit did: the nodes taken out of its structure and the edges examined More... | |
| class | ADS::DfsSchema< G > |
| the discovery and finish times and the kind of each edge, the procedure dfs-schema of the book More... | |
Namespaces | |
| namespace | ADS |
Enumerations | |
| enum class | ADS::Choice { ADS::Choice::NEWEST , ADS::Choice::OLDEST } |
| the node of \( Q \) that genericVisit() chooses More... | |
| enum class | ADS::EdgeKind { ADS::EdgeKind::TREE , ADS::EdgeKind::BACK , ADS::EdgeKind::FORWARD , ADS::EdgeKind::CROSS } |
| the kind of an edge with respect to a depth-first visit More... | |
Functions | |
| template<Graph G> | |
| std::pair< std::vector< int >, std::vector< std::pair< int, int > > > | ADS::genericVisit (const G &g, int r, Choice c) |
| the general visit from \( r \): the nodes in the order in which they join \( R \), and the edges of the tree \( B \) in the order in which they join it | |
| template<Graph G, class FN, class FE> | |
| void | ADS::bfs (const G &g, int r, FN &&node, FE &&edge) |
| the visit in breadth from \( r \), calling node( u ) when \( u \) is examined and edge( u , v ) when \( ( u , v ) \) is examined | |
| template<Graph G> | |
| std::pair< std::vector< int >, std::vector< int > > | ADS::distance (const G &g, int r) |
| the distances from \( r \), INF if not reachable, and the parents in the tree of the shortest paths, NIL for \( r \) and the unreachable nodes | |
| template<Graph G, class Q> requires requires( Q q , int v ) { q.enqueue( v ); { q.dequeue() } -> std::convertible_to< int >; } | |
| std::pair< std::vector< int >, std::vector< int > > | ADS::distance (const G &g, int r, Q &S, VisitCounts *c=nullptr) |
| the distances of distance() above, with the queue \( S \) given, empty, whose enqueue() and dequeue() keep the order of arrival [see ArrayQueue.h]; its work in *c, if given | |
| std::vector< int > | ADS::path (int r, int s, const std::vector< int > &p) |
| the path from \( r \) to \( s \) in the tree of the parents \( p \), empty if there is none (the procedure printPath of the book) | |
| template<Graph G, class Pre, class Edge, class Post> | |
| void | ADS::dfs (const G &g, int u, std::vector< bool > &visited, Pre &&pre, Edge &&edge, Post &&post) |
| the visit in depth from \( u \), calling pre( u ) in the previsit, edge( u , v ) on each edge and post( u ) in the postvisit | |
| template<Graph G> | |
| std::vector< int > | ADS::cc (const G &g, std::vector< int > S) |
| the component of each node, numbered from 1, the visits starting from the nodes as they leave the stack \( S \) (its last item first) | |
| template<Graph G> | |
| std::vector< int > | ADS::cc (const G &g) |
| the components of cc() above, the visits starting from the nodes in increasing order | |
| template<Graph G> | |
| bool | ADS::hasCycle (const G &g) |
| true if the oriented graph has a cycle, i.e., if a visit finds a back edge; on an unoriented graph each edge, met again from its other end, is a back edge, so it is true if and only if there is an edge | |
| template<Graph G> | |
| bool | ADS::isTopologicalOrder (const G &g, const std::vector< int > &S) |
| whether \( S \) has each node once and each edge \( ( u , v ) \) has \( u \) before \( v \) | |
| template<Graph G> | |
| std::vector< int > | ADS::topsort (const G &g) |
| the nodes by decreasing finish time, which for an acyclic graph is a topological order; the first is the top of the stack of the book | |
| template<Graph G> | |
| std::vector< int > | ADS::topsortKahn (const G &g) |
| the topological order by removing the nodes with no entering edge, in the order of V() and then of discovery; fewer than \( n \) nodes if there is a cycle | |
| template<Graph G> | |
| ListGraph | ADS::transpose (const G &g) |
| the transposed graph, with the edges reversed | |
| template<Graph G> | |
| std::vector< int > | ADS::scc (const G &g) |
| the strongly connected component of each node, numbered from 1 | |
| template<Graph G> | |
| bool | ADS::unilaterallyConnected (const G &g) |
| true if every two nodes have a path between them in one direction | |
Variables | |
| constexpr int | ADS::INF = std::numeric_limits< int >::max() |
| the infinite distance | |
| constexpr int | ADS::NIL = -1 |
| no node | |
The visits of a GRAPH of section 9.5 and their applications, each in \( \Theta( n + m ) \) time on lists or vectors of adjacency:
The strongly connected components by one visit in depth and no transposed graph, sccTarjan() and sccPearce() (beyond the book), are in StrongComponents.h, which this header includes.
Nil is -1 and the infinite distance is INF. The visits in depth and path() keep their recursion on an explicit stack, in the order of the recursive ones, so that a path of 10^5 nodes does not overflow the stack of the calls.
The properties on which the visits rest, and the arguments behind their bounds, are in the theory page of the area (see Visits).
The contracts [see Contract.h]: a visit starts from a node of the graph (and dfs() from one not visited yet, with a vector of a place per name); distance() ensures, at the level of the audits, that its distances are those of a breadth first tree, topsort() and topsortKahn() that their order is topological when the graph is acyclic, transpose() that it reverses each edge. The functions are defined in Visit.tpp.