Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
graph_exhaustive_tree_queries_test.cc File Reference

The queries on a tree given as a graph, on every small labeled tree with every root, against naive answers: lowest common ancestors, heavy-light and centroid decompositions, dynamic programming on trees and Mo's algorithm on trees. More...

#include <algorithm>
#include <cstddef>
#include <limits>
#include <random>
#include <set>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include <gtest/gtest.h>
#include <tpl_graph.H>
#include <tpl_tree_node.H>
#include <LCA.H>
#include <HLD.H>
#include <Tree_Decomposition.H>
#include <Tree_DP.H>
#include <tpl_mo_on_trees.H>
#include "graph_filter_catalog.H"
#include "graph_harness.H"
#include "graph_oracles.H"
Include dependency graph for graph_exhaustive_tree_queries_test.cc:

Go to the source code of this file.

Classes

class  ExhaustiveTreeQueries< GT >
 
class  ExhaustiveTreeDp< GT >
 
class  ExhaustiveMoOnTrees< GT >
 

Functions

 TYPED_TEST_SUITE (ExhaustiveTreeQueries, Undirected_Kinds)
 
 TYPED_TEST (ExhaustiveTreeQueries, LcaEnginesAnswerEveryQuery)
 
 TYPED_TEST (ExhaustiveTreeQueries, BinaryLiftingLcaTakesExactlyTheTrees)
 
 TYPED_TEST (ExhaustiveTreeQueries, EulerRmqLcaTakesExactlyTheTrees)
 
 TYPED_TEST (ExhaustiveTreeQueries, LcaEnginesOnRandomTrees)
 
 TYPED_TEST (ExhaustiveTreeQueries, HldFoldsAndLayoutMatchTheTree)
 
 TYPED_TEST (ExhaustiveTreeQueries, HldFoldsFollowPointUpdates)
 
 TYPED_TEST (ExhaustiveTreeQueries, HldSumTakesExactlyTheTrees)
 
 TYPED_TEST (ExhaustiveTreeQueries, HldWithAnOperationOfTheUserTakesExactlyTheTrees)
 
 TYPED_TEST (ExhaustiveTreeQueries, HldOnRandomTrees)
 
 TYPED_TEST (ExhaustiveTreeQueries, HeavyLightDecompositionMatchesItsDefinition)
 
 TYPED_TEST (ExhaustiveTreeQueries, HldPathQueriesFoldAndFollowUpdates)
 
 TYPED_TEST (ExhaustiveTreeQueries, CentroidDecompositionMatchesItsDefinition)
 
 TYPED_TEST (ExhaustiveTreeQueries, HeavyLightDecompositionTakesExactlyTheTrees)
 
 TYPED_TEST (ExhaustiveTreeQueries, HldPathQueryTakesExactlyTheTrees)
 
 TYPED_TEST (ExhaustiveTreeQueries, CentroidDecompositionTakesExactlyTheTrees)
 
 TYPED_TEST (ExhaustiveTreeQueries, TreeDecompositionsOnRandomTrees)
 
 TYPED_TEST_SUITE (ExhaustiveTreeDp, All_Kinds)
 
 TYPED_TEST (ExhaustiveTreeDp, TreeDpFoldsEverySubtree)
 
 TYPED_TEST (ExhaustiveTreeDp, RerootDpAnswersForEveryRoot)
 
 TYPED_TEST (ExhaustiveTreeDp, TreeDpTakesTheTreesAndCountsParallelArcsOnce)
 
 TYPED_TEST (ExhaustiveTreeDp, RerootDpTakesTheTreesAndCountsParallelArcsOnce)
 
 TYPED_TEST (ExhaustiveTreeDp, TreeDpOnRandomTrees)
 
 TYPED_TEST_SUITE (ExhaustiveMoOnTrees, All_Kinds)
 
 TYPED_TEST (ExhaustiveMoOnTrees, MoAnswersOnEverySubtreeAndPath)
 
 TYPED_TEST (ExhaustiveMoOnTrees, MoTakesWhatItDocuments)
 
 TYPED_TEST (ExhaustiveMoOnTrees, MoOnRandomTrees)
 
 TEST (ExhaustiveMoOnTreeNodes, MoAnswersOnEverySubtreeAndPath)
 
 TYPED_TEST (ExhaustiveTreeQueries, QueriesRejectWhatIsNotOfTheTree)
 
 TYPED_TEST (ExhaustiveTreeQueries, CopiesAndMovesAnswerAsTheOriginal)
 
 TYPED_TEST (ExhaustiveTreeQueries, LongPathsAndStarsRunOnASmallStack)
 

Detailed Description

The queries on a tree given as a graph, on every small labeled tree with every root, against naive answers: lowest common ancestors, heavy-light and centroid decompositions, dynamic programming on trees and Mo's algorithm on trees.

Every labeled tree of 1 to 5 nodes, by its Prüfer sequence, and a sample of those of 6 and 7 nodes (all of them with ALEPH_GRAPH_HARNESS=heavy) is rooted at each of its nodes, with its arcs inserted from either end and in either order, and its nodes get values from -2 to 2. Each answer of LCA.H, HLD.H, Tree_Decomposition.H, Tree_DP.H and tpl_mo_on_trees.H is compared with the naive one, computed on the Spec with the standard library only: the parents and the depths by a search from the root, the path between two nodes by walking up, the subtrees by ancestry, the distances by breadth-first search, and the folds and the counts over the nodes of a path or of a subtree. Random trees of up to 64 nodes come from fixed seeds.

Every multigraph of the domain of graph_harness.H, with each set of hidden arcs (with ALEPH_GRAPH_HARNESS=heavy, on those of up to 3 arcs or 3 nodes), tells whether each class takes what its documentation says: a cycle, a forest, a loop, parallel arcs and a root of another graph are rejected, the empty graph makes an empty tree, and an arc filter that leaves a tree makes that tree. The classes that check their tree as another one of their header does try only the sets of hidden arcs that leave a tree or n - 1 arcs. Tree_DP.H, which takes the arcs as not directed, and Mo on trees, which follows the arcs out of each node, also run on the three kinds of digraph. The queries on nodes out of the tree throw, the copies and the moves answer as the originals, and a path of 10 000 nodes and a star of 2 000 (100 000 and 20 000 with ALEPH_GRAPH_HARNESS=heavy) run in a thread with a stack of 256 KiB.

Definition in file graph_exhaustive_tree_queries_test.cc.

Function Documentation

◆ TEST()

◆ TYPED_TEST() [1/27]

◆ TYPED_TEST() [2/27]

◆ TYPED_TEST() [3/27]

◆ TYPED_TEST() [4/27]

◆ TYPED_TEST() [5/27]

TYPED_TEST ( ExhaustiveTreeDp  ,
RerootDpTakesTheTreesAndCountsParallelArcsOnce   
)

◆ TYPED_TEST() [6/27]

◆ TYPED_TEST() [7/27]

◆ TYPED_TEST() [8/27]

TYPED_TEST ( ExhaustiveTreeDp  ,
TreeDpTakesTheTreesAndCountsParallelArcsOnce   
)

Definition at line 2222 of file graph_exhaustive_tree_queries_test.cc.

References root().

◆ TYPED_TEST() [9/27]

TYPED_TEST ( ExhaustiveTreeQueries  ,
BinaryLiftingLcaTakesExactlyTheTrees   
)

Definition at line 816 of file graph_exhaustive_tree_queries_test.cc.

References graph_harness::Built< GT >::g, r, and root().

◆ TYPED_TEST() [10/27]

◆ TYPED_TEST() [11/27]

TYPED_TEST ( ExhaustiveTreeQueries  ,
CentroidDecompositionTakesExactlyTheTrees   
)

Definition at line 1853 of file graph_exhaustive_tree_queries_test.cc.

References graph_harness::Built< GT >::g, r, and root().

◆ TYPED_TEST() [12/27]

◆ TYPED_TEST() [13/27]

TYPED_TEST ( ExhaustiveTreeQueries  ,
EulerRmqLcaTakesExactlyTheTrees   
)

Definition at line 829 of file graph_exhaustive_tree_queries_test.cc.

References graph_harness::Built< GT >::g, r, and root().

◆ TYPED_TEST() [14/27]

◆ TYPED_TEST() [15/27]

TYPED_TEST ( ExhaustiveTreeQueries  ,
HeavyLightDecompositionTakesExactlyTheTrees   
)

Definition at line 1814 of file graph_exhaustive_tree_queries_test.cc.

References graph_harness::Built< GT >::g, r, and root().

◆ TYPED_TEST() [16/27]

◆ TYPED_TEST() [17/27]

◆ TYPED_TEST() [18/27]

◆ TYPED_TEST() [19/27]

◆ TYPED_TEST() [20/27]

TYPED_TEST ( ExhaustiveTreeQueries  ,
HldPathQueryTakesExactlyTheTrees   
)

◆ TYPED_TEST() [21/27]

TYPED_TEST ( ExhaustiveTreeQueries  ,
HldSumTakesExactlyTheTrees   
)

◆ TYPED_TEST() [22/27]

TYPED_TEST ( ExhaustiveTreeQueries  ,
HldWithAnOperationOfTheUserTakesExactlyTheTrees   
)

◆ TYPED_TEST() [23/27]

◆ TYPED_TEST() [24/27]

◆ TYPED_TEST() [25/27]

◆ TYPED_TEST() [26/27]

TYPED_TEST ( ExhaustiveTreeQueries  ,
QueriesRejectWhatIsNotOfTheTree   
)

Definition at line 2822 of file graph_exhaustive_tree_queries_test.cc.

References Aleph::and, Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_ancestors_of_id(), Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_distances_of_id(), Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_level_of_id(), Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_parent(), Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_parent_id(), Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_path_length_of_id(), Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_root(), Aleph::Gen_Centroid_Decomposition< GT, SA >::centroid_root_id(), Aleph::Gen_Binary_Lifting_LCA< GT, SA >::depth_of_id(), Aleph::Gen_Centroid_Decomposition< GT, SA >::distance_to_centroid_id(), Aleph::Gen_Euler_RMQ_LCA< GT, SA >::euler_tour_size(), graph_harness::Check::expect(), graph_harness::Check::fail(), Aleph::Gen_Centroid_Decomposition< GT, SA >::for_each_centroid_ancestor(), Aleph::Gen_Centroid_Decomposition< GT, SA >::for_each_centroid_ancestor_id(), graph_harness::Built< GT >::g, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::get_node_id(), h, Aleph::Gen_Centroid_Decomposition< GT, SA >::id_of(), Aleph::Gen_Binary_Lifting_LCA< GT, SA >::is_ancestor(), Aleph::Gen_Euler_RMQ_LCA< GT, SA >::is_ancestor(), Aleph::Gen_Binary_Lifting_LCA< GT, SA >::is_ancestor_id(), Aleph::Gen_Euler_RMQ_LCA< GT, SA >::is_ancestor_id(), Aleph::Gen_Centroid_Decomposition< GT, SA >::is_centroid_ancestor_id(), Aleph::Gen_Binary_Lifting_LCA< GT, SA >::is_empty(), Aleph::Gen_Euler_RMQ_LCA< GT, SA >::is_empty(), Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::is_empty(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::is_empty(), Aleph::Gen_Centroid_Decomposition< GT, SA >::is_empty(), Aleph::Gen_Binary_Lifting_LCA< GT, SA >::kth_ancestor(), Aleph::Gen_Binary_Lifting_LCA< GT, SA >::kth_ancestor_id(), Aleph::Gen_Euler_RMQ_LCA< GT, SA >::lca_id(), Aleph::Gen_Binary_Lifting_LCA< GT, SA >::lca_id(), Aleph::Gen_Heavy_Light_Decomposition< GT, SA >::lca_id(), Aleph::Gen_Centroid_Decomposition< GT, SA >::max_centroid_level(), graph_harness::Spec::n, Aleph::Gen_Centroid_Decomposition< GT, SA >::node_of(), graph_harness::Built< GT >::nodes, Aleph::Gen_Binary_Lifting_LCA< GT, SA >::num_levels(), out, Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_path_id(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::query_subtree_id(), r, Aleph::Gen_Binary_Lifting_LCA< GT, SA >::root(), graph_harness::Check::run(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::set_node_id(), Aleph::Gen_Binary_Lifting_LCA< GT, SA >::size(), Aleph::Array< T >::size(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::size(), Aleph::tree_max_distance(), Aleph::tree_subtree_sizes(), Aleph::tree_sum_of_distances(), Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::update_node(), and Aleph::Gen_HLD_Path_Query< GT, T, Op, SA >::update_node_id().

◆ TYPED_TEST() [27/27]

◆ TYPED_TEST_SUITE() [1/3]

TYPED_TEST_SUITE ( ExhaustiveMoOnTrees  ,
All_Kinds   
)

◆ TYPED_TEST_SUITE() [2/3]

TYPED_TEST_SUITE ( ExhaustiveTreeDp  ,
All_Kinds   
)

◆ TYPED_TEST_SUITE() [3/3]

TYPED_TEST_SUITE ( ExhaustiveTreeQueries  ,
Undirected_Kinds   
)