r/computerscience • u/Datalore1234 • Jun 19 '25
Heuristic for A* For Terrain Cost
I am working on a problem which involves using A* for finding the optimal route on a terrain of varying slope. I am representing the terrain as a network where each point is a node and adjacent points are connected by an edge. The cost of a path between two points is the line integral of the absolute values of the slopes of the path. Currently the best heuristic function I can think of is the net slope between the current point and the end goal, but I was wondering if anyone can think of or has used a heuristic function which is, on average, closer to the cost function between the current function and the goal.
1
u/SirClueless Jun 19 '25
This one you can use a bit of math: The line integral of the absolute values of the slopes is definitely greater than the line integral of the slopes, and the line integral of the slopes is just the difference in the terrain heights.
2
u/exploding_nun Jun 19 '25
You could use a "pattern database" approach to derive an informative heuristic.
The big idea: you "abstract" your concrete problem, mapping it onto a smaller / simpler problem that is feasible to solve with a weak heuristic or even breadth-first search. Then, you can use the actual distance in the abstract space as an admissible heuristic for your original, concrete problem.
There are the older "static" pattern database approaches (lots of work from Ariel Felner). These are expensive to construct, but can work well if you have many concrete problem instances to solve.
But there are newer approaches that essentially compute a pattern database lazily (aka on-demand). See Hierarchical A*, or Switchback for a better-performing variant when your problem space actions are invertible (it sounds like your navigation problem is like this).
Hierarchical A*: https://cdn.aaai.org/AAAI/1996/AAAI96-079.pdf
Switchback: https://ojs.aaai.org/index.php/AAAI/article/view/7563
0
u/Liam_Mercier Jun 21 '25
You probably already know this, but your heuristic is only beneficial if it saves more time compared to its computation cost. You want to find a heuristic which is simple to compute and accurate, which may not exist.
If you can preprocess the graph then this isn't as big of an issue, but you probably cannot.