73 return abs(f.x - t.x) +
abs(f.y - t.y);
78 cout <<
"=== IDA* (Iterative Deepening A*) Example ===" <<
endl <<
endl;
101 for (
int i = 1; i <= 3; ++i) {
108 cout <<
"Grid-based pathfinding (5x5):" <<
endl;
109 cout <<
"S = Start, G = Goal, # = Obstacle, . = Free" <<
endl <<
endl;
113 if (x == 0
and y == 0)
144 int dx[] = {0, 0, 1, -1};
145 int dy[] = {1, -1, 0, 0};
147 for (
int d = 0; d < 4; ++d) {
153 auto src =
nodes.find(make_pair(x,
y));
154 auto tgt =
nodes.find(make_pair(
nx,
ny));
161 auto start =
nodes.find(make_pair(0, 0));
164 cout <<
"Running IDA* with Manhattan distance heuristic:" <<
endl;
169 auto cost =
ida(g, start,
goal, path);
171 if (cost == numeric_limits<int>::max()) {
172 cout <<
"No path found!" <<
endl;
174 cout <<
"Path found! Cost: " << cost <<
endl <<
endl;
176 cout <<
"Path coordinates: ";
179 auto & c = n->get_info();
180 cout <<
"(" << c.x <<
"," << c.y <<
") ";
183 cout <<
endl <<
"Path length: " << (
count - 1) <<
" moves" <<
endl;
186 cout <<
endl <<
"=== Performance ===" <<
endl
187 <<
"Time: O(b^d)" <<
endl
188 <<
"Space: O(d) [linear in depth]" <<
endl;
IDA* (Iterative Deepening A*) shortest path algorithm.
Core header for the Aleph-w library.
void insert(Dlink *node) noexcept
Insert node after this.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Generic key-value map implemented on top of a binary search tree.
IDA* algorithm for memory-efficient shortest path search.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
void for_each_node(Operation op=Operation()) const
Execute an operation on each node of path.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_abs_function > > abs(const __gmp_expr< T, U > &expr)
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Arc of graph implemented with double-linked adjacency lists.
bool operator==(const Coord &other) const
int operator()(typename GT::Node *from, typename GT::Node *to) const
Dynamic key-value map based on balanced binary search trees.
Generic graph and digraph implementations.