43#include <gtest/gtest.h>
75 if (it.has_current_arc())
76 w += it.get_current_arc_ne()->get_info();
83 std::vector<typename GT::Node *>
build(
GT & g)
85 std::vector<typename GT::Node *> v;
86 for (
int i = 0; i < 10; ++i)
88 for (
int i = 0; i < 5; ++i)
100 struct UndirectedKinds :
public ::testing::Test {};
103 struct DirectedKinds :
public ::testing::Test {};
121 using GT = TypeParam;
127 cut_nodes(v[0], cuts);
128 EXPECT_EQ(cuts.
size(), 3u);
135 using GT = TypeParam;
140 EXPECT_EQ(depth_first_traversal<GT>(g, v[0],
nullptr), 10u);
142 EXPECT_EQ(breadth_first_traversal<GT>(g, v[0],
nullptr), 10u);
149 using GT = TypeParam;
159 EXPECT_EQ(bfs_path.
size(), 6u);
171 using GT = TypeParam;
177 EXPECT_EQ(weight_of(path), 12);
180 EXPECT_EQ(weight_of(floyd.
get_min_path(v[0], v[9])), 12);
185 using GT = TypeParam;
195 EXPECT_EQ(blocks.
size(), 3u);
201 using GT = TypeParam;
203 std::vector<typename GT::Node *> v;
204 for (
int i = 0; i < 6; ++i)
213 auto check = [&g, &v](
const auto & order)
215 ASSERT_EQ(order.size(), v.size());
216 std::vector<size_t> position(v.size());
218 for (
auto it = order.get_it(); it.has_curr(); it.next_ne())
219 position[
size_t(it.get_curr()->get_info())] = i++;
220 for (
typename GT::Arc_Iterator it(g); it.has_curr(); it.next_ne())
221 EXPECT_LT(position[
size_t(g.
get_src_node(it.get_curr())->get_info())],
222 position[size_t(g.
get_tgt_node(it.get_curr())->get_info())]);
230 using GT = TypeParam;
236 EXPECT_EQ(weight_of(path), 15);
244 EXPECT_EQ(weight_of(floyd.
get_min_path(v[0], v[9])), 15);
Bellman-Ford algorithm for single-source shortest paths.
Dijkstra's shortest path algorithm.
Floyd-Warshall algorithm for all-pairs shortest paths.
Johnson's algorithm for all-pairs shortest paths.
Tarjan's algorithm for strongly connected components.
Bellman-Ford algorithm for shortest paths with negative weights.
bool paint_spanning_tree(Node *start)
Paint the shortest paths tree from a start node.
Distance_Type get_min_path(typename GT::Node *end, Path< GT > &path)
Extract the shortest path to a node from a previously painted tree.
Computation of cut nodes (articulation points) of a graph.
auto has_curr() const noexcept(noexcept(std::declval< I & >().has_curr())) -> decltype(std::declval< I & >().has_curr())
true if there is a current item.
Stateful depth-first traversal functor.
Generic directed graph (digraph) wrapper template.
Spanning tree calculation of all shortest paths from a given node according to Dijkstra's algorithm.
Dynamic doubly linked list with O(1) size and bidirectional access.
const size_t & size() const noexcept
Return the number of elements (constant time)
Doubly-linked list (defined in tpl_dynList.H).
size_t size() const noexcept
Return the number of items of the list, in constant time.
Performs a breadth-first search for a path between a pair of nodes.
Performs a depth-first search for a path between a pair of nodes.
Compute the all-pairs shortest path distance matrix and the path reconstruction matrix for a graph g ...
Path< GT > get_min_path(const long src_idx, const long tgt_idx) const
Reconstruct the shortest path between two nodes by matrix indices.
Arc for graphs implemented with simple adjacency lists.
Johnson's algorithm for all-pairs shortest paths.
Distance_Type get_distance(Node *src, Node *tgt)
Get the shortest distance from source to target.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Graph class implemented with singly-linked adjacency lists.
Iterator on nodes and arcs of a path.
size_t size() const noexcept
Return the path length in nodes.
Node * get_first_node() const
Return the first node of path; throws overflow_error if path is empty.
Node * get_last_node() const
Return the last node of path; throws overflow_error if path is empty.
Computes topological ordering using breadth-first search (Kahn's algorithm).
Computes strongly connected components (SCCs) in a directed graph using Tarjan's algorithm.
void connected_components(const GT &g, DynList< GT > &blk_list, DynList< typename GT::Arc * > &arc_list)
Computes the strongly connected components (SCCs) of a digraph.
Test whether a cycle is reachable from a given node.
Checks whether a path exists between two nodes.
Computes topological ordering using depth-first search.
Compute the connected components of a graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
TYPED_TEST(UndirectedKinds, CutNodesAndBridges)
TYPED_TEST_SUITE(UndirectedKinds, Undirected)
bool has_cycle(const GT &g)
Return true if an undirected graph has at least one cycle.
void kosaraju_connected_components(const GT &g, DynList< GT > &blk_list, DynList< typename GT::Arc * > &arc_list)
Compute strongly connected components using Kosaraju's algorithm.
DynList< GT > inconnected_components(const GT &g)
Forward declaration for inconnected_components().
bool test_for_cycle(const GT &g, typename GT::Node *src)
Search for a cycle reachable from a given node.
DynList< typename GT::Node * > compute_cut_nodes(const GT &g, typename GT::Node *start)
Compute articulation points (cut vertices) of an undirected graph.
bool test_for_path(const GT &g, typename GT::Node *start_node, typename GT::Node *end_node)
Return true if there is a path between two nodes.
DynList< typename GT::Arc * > find_bridges(const GT &g, typename GT::Node *start, SA sa=SA())
Find all bridge edges in a connected undirected graph.
bool is_graph_acyclique(const GT &g, typename GT::Node *start_node)
Return true if an undirected graph is acyclic.
void find_min_path(Mat &p, long src_idx, long tgt_idx, Path< typename Mat::Graph_Type > &path)
Build a minimum path from Floyd-Warshall path matrix using indices.
Kosaraju's algorithm for finding strongly connected components.
void build(Tree_Node< Key > *troot, Convert &&convert, typename GT::Node *groot, Args &&... args)
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
bool between(const Point &a, const Point &b, const Point &c)
Arc of graph implemented with double-linked adjacency lists.
Topological sorting algorithms for directed acyclic graphs (DAGs).
Array-based graph implementation.
Graph connectivity and connected components.
Articulation points (cut nodes), bridges, and biconnected components.
Path finding algorithms in graphs.
Generic graph and digraph implementations.
Utility algorithms and operations for graphs.
Simple graph implementation with adjacency lists.
DAG (acyclic) graph testing.
Cycle detection in graphs.