9# include <gtest/gtest.h>
40TEST(IDAStar, BasicShortestPath)
55 double d = ida(g, n0, n3, path);
71 double d = ida(g, n0, n0, path);
87 double d = ida(g, n0, n1, path);
89 EXPECT_EQ(d, std::numeric_limits<double>::max());
103 double d = ida(g, n0, n0, path);
125 double d = ida(g, n0, n3, path);
143 double d = ida(g, n0, n1, path);
151TEST(IDAStar, NullNodeValidation)
160 EXPECT_THROW(ida(g,
nullptr, n0, path), std::domain_error);
161 EXPECT_THROW(ida(g, n0,
nullptr, path), std::domain_error);
165 EXPECT_THROW(ida(g_empty, n0, n0, path), std::domain_error);
172 EXPECT_THROW(ida(g_neg, s, t, path), std::domain_error);
178TEST(IDAStar, RelaxationFindsCheaperPath)
191 double d = ida(g, n0, n1, path);
199TEST(IDAStar, CrossValidationWithDijkstra)
218 double ida_d = ida(g, n0, n4, ida_path);
222 double dij_d = dij(g, n0, n4, dij_path);
224 EXPECT_NEAR(ida_d, dij_d, 1e-9);
230TEST(IDAStar, CrossValidationWithAStar)
246 double ida_d = ida(g, n0, n3, ida_path);
250 double astar_d = astar(g, n0, n3, astar_path);
252 EXPECT_NEAR(ida_d, astar_d, 1e-9);
275 double d = ida(g, n0, n3, path);
298 double d = ida(g, n0, n3, path);
320 int d = ida(g, n0, n2, path);
328TEST(IDAStar, MultipleComputations)
341 double d1 = ida(g, n0, n2, p1);
345 double d2 = ida(g, n2, n0, p2);
352TEST(IDAStar, PathNodeVerification)
367 double d = ida(g, n0, n3, path);
375 ASSERT_EQ(
nodes.size(), 4u);
376 auto pit =
nodes.get_it();
377 EXPECT_EQ(pit.get_curr(), 0); pit.next();
378 EXPECT_EQ(pit.get_curr(), 1); pit.next();
379 EXPECT_EQ(pit.get_curr(), 2); pit.next();
380 EXPECT_EQ(pit.get_curr(), 3);
398 double d = ida(g, n0, n2, path);
406TEST(IDAStar, FractionalWeights)
418 double d = ida(g, n0, n2, path);
420 EXPECT_NEAR(d, 0.8, 1e-9);
429 auto n0 = g.insert_node(0);
430 auto n1 = g.insert_node(1);
431 auto n2 = g.insert_node(2);
433 g.insert_arc(n0, n1, 1.0);
434 g.insert_arc(n1, n2, 1.0);
438 double d = ida(g, n0, n2, path);
449 auto n0 = g.insert_node(0);
450 auto n1 = g.insert_node(1);
452 g.insert_arc(n0, n1, 1.0);
456 double d = ida(g, n1, n0, p);
458 EXPECT_EQ(d, std::numeric_limits<double>::max());
480 double d = ida(g, n1, n4, path);
489TEST(IDAStar, DisconnectedGraph)
502 double d = ida(g, n0, n3, path);
504 EXPECT_EQ(d, std::numeric_limits<double>::max());
511TEST(IDAStar, LargerCrossValidation)
517 for (
int i = 0; i <
N; ++i)
520 for (
int i = 0; i <
N - 1; ++i)
530 for (
int end = 1; end <
N; end += 2)
535 EXPECT_NEAR(
id, dd, 1e-9) <<
"Mismatch for end=" << end;
552TEST(IDAStar, WeightedGridExample)
575 double d = ida(g, n0, n5, path);
595 double d = ida(g, n0, n1, path);
605TEST(IDAStar, ChebyshevHeuristicExists)
607 struct Coord {
int x;
int y; };
612 auto n1 = g.insert_node(
Coord{0, 0});
613 auto n2 = g.insert_node(
Coord{3, 5});
617 EXPECT_EQ(ch(n1, n2), 5);
618 EXPECT_EQ(ch(n2, n1), 5);
619 EXPECT_EQ(ch(n1, n1), 0);
A* shortest path algorithm.
Dijkstra's shortest path algorithm.
IDA* (Iterative Deepening A*) shortest path algorithm.
WeightedDigraph::Node Node
A* algorithm for finding the shortest path between two nodes.
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.
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)
IDA* algorithm for memory-efficient shortest path search.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Graph_Node< int > Node
The graph type.
Graph_Arc< double > 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.
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
Chebyshev (L-infinity) distance heuristic for 8-connected grids.
Arc of graph implemented with double-linked adjacency lists.
Default heuristic for A* (zero heuristic, degrades to Dijkstra).
Generic graph and digraph implementations.