9# include <gtest/gtest.h>
42TEST(Dial, BasicShortestPath)
58 int d = dial(g, n0, n3, path);
74 int d = dial(g, n0, n0, path);
90 int d = dial(g, n0, n1, path);
92 EXPECT_EQ(d, std::numeric_limits<int>::max());
106 int d = dial(g, n0, n0, path);
128 int d = dial(g, n0, n3, path);
148 int d = dial(g, n0, n2, path);
171 int d = dial(g, n0, n3, path);
187 EXPECT_THROW(dial(g,
nullptr, n0, path), std::domain_error);
188 EXPECT_THROW(dial(g, n0,
nullptr, path), std::domain_error);
194TEST(Dial, NegativeWeightValidation)
204 EXPECT_THROW(dial(g, n0, n1, path), std::domain_error);
243TEST(Dial, GetDistanceAfterPainting)
267TEST(Dial, GetDistanceBeforePainting)
279TEST(Dial, CrossValidationWithDijkstra)
301 int dial_d = dial(g, n0, n5, dial_path);
306 int dij_d = dij(g, n0, n5, dij_path);
308 EXPECT_EQ(dial_d, dij_d);
317 auto n0 = g.insert_node(0);
318 auto n1 = g.insert_node(1);
319 auto n2 = g.insert_node(2);
321 g.insert_arc(n0, n1, 3);
322 g.insert_arc(n1, n2, 2);
326 int d = dial(g, n0, n2, path);
337 auto n0 = g.insert_node(0);
338 auto n1 = g.insert_node(1);
340 g.insert_arc(n0, n1, 3);
345 EXPECT_EQ(dial(g, n0, n1, p1), 3);
348 EXPECT_EQ(dial(g, n1, n0, p2), std::numeric_limits<int>::max());
354TEST(Dial, MultipleComputations)
367 EXPECT_EQ(dial(g, n0, n2, p1), 5);
370 EXPECT_EQ(dial(g, n2, n0, p2), 5);
382 for (
int i = 0; i <
N; ++i)
385 for (
int i = 0; i <
N - 1; ++i)
410 int d = dial(g, n0, n2, path);
418TEST(Dial, PathNodeVerification)
433 int d = dial(g, n0, n3, path);
441 ASSERT_EQ(
nodes.size(), 4u);
442 auto pit =
nodes.get_it();
443 EXPECT_EQ(pit.get_curr(), 0); pit.next();
444 EXPECT_EQ(pit.get_curr(), 1); pit.next();
445 EXPECT_EQ(pit.get_curr(), 2); pit.next();
446 EXPECT_EQ(pit.get_curr(), 3);
469 int d = dial(g, n0, n3, path);
490 int d = dial(g, n0, n2, path);
522TEST(Dial, DisconnectedPainting)
543TEST(Dial, RelaxationCorrectness)
556 int d = dial(g, n0, n1, path);
617 int dist = dial(g, a, e, path);
626TEST(Dial, LargerCrossValidation)
632 for (
int i = 0; i <
N; ++i)
636 for (
int i = 0; i <
N - 1; ++i)
640 for (
int i = 0; i <
N - 3; i += 3)
646 for (
int end = 1; end <
N; end += 3)
651 EXPECT_EQ(dd, jd) <<
"Mismatch for end=" << end;
658TEST(Dial, DistanceTypeOverflowValidation)
671 EXPECT_THROW(dial(g, n0, n2, path), std::overflow_error);
677TEST(Dial, BucketUpperBoundValidation)
682 constexpr int bucket_limit = 16 * 1024 * 1024;
689 EXPECT_THROW(dial(g, n0, n1, path), std::runtime_error);
695TEST(Dial, ParallelEdgesKeepSingleParentArcMarked)
702 auto direct_high = g.
insert_arc(start, end, 10);
704 auto mid_end_high = g.
insert_arc(mid, end, 5);
720 size_t painted_arcs = 0;
721 for (GT::Arc_Iterator it(g); it.has_curr(); it.next())
725 EXPECT_EQ(painted_arcs, 2u);
744TEST(Dial, GetMinPathUsesTheDistanceItWasGiven)
756 EXPECT_EQ(dial.find_min_path(g, n0, n2, path), 21);
758 dial.paint_min_paths_tree(g, n0);
759 EXPECT_EQ(dial.get_distance(n2), 21);
760 EXPECT_EQ(dial.get_min_path(n2, path), 21);
Dial's algorithm for shortest paths with small integer weights.
Dijkstra's shortest path algorithm.
WeightedDigraph::Node Node
static Array create(const size_t n)
Create an array with n logical elements.
auto has_curr() const noexcept(noexcept(std::declval< I & >().has_curr())) -> decltype(std::declval< I & >().has_curr())
true if there is a current item.
Dial's algorithm for shortest paths with integer weights.
Distance_Type get_distance(Node *node)
Gets the accumulated distance to a node after painting.
Distance_Type get_min_path(Node *end, Path< GT > &path)
Extracts a shortest path from a previously painted graph.
GT * get_graph() const noexcept
Get the graph of the last computation.
void paint_min_paths_tree(const GT &g, Node *start)
Paints the shortest paths tree on the graph from start.
Node * get_start_node() const noexcept
Get the start node of the last computation.
bool is_painted() const noexcept
Check if the graph has been painted.
Generic directed graph (digraph) wrapper template.
typename BaseGraph::Arc Arc
typename BaseGraph::Node Node
Spanning tree calculation of all shortest paths from a given node according to Dijkstra's algorithm.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Graph_Node< int > Node
The graph type.
Graph_Arc< int > Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Number Theoretic Transform over Z / MOD Z.
Iterator on nodes and arcs of a path.
bool is_empty() const noexcept
Return true if the path is empty.
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
DynArray< Graph::Node * > nodes
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
#define NODE_COOKIE(p)
Return the node cookie
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
Main namespace for Aleph-w library functions.
Arc of graph implemented with double-linked adjacency lists.
Distance_Type operator()(Arc *arc) const noexcept
int operator()(Arc *arc) const
Generic graph and digraph implementations.