Skip to content

A* heuristic based on distance to the goal#3

Merged
ragoune merged 18 commits intomasterfrom
feat/heuristic
Oct 30, 2025
Merged

A* heuristic based on distance to the goal#3
ragoune merged 18 commits intomasterfrom
feat/heuristic

Conversation

@ragoune
Copy link
Copy Markdown
Contributor

@ragoune ragoune commented Oct 30, 2025

Compute the distance to the goal using the current state value, instead of a simple incrementation using the number of steps from the starting point.
In the benchmark it reduces the required loop number from 46 to 14. Benchmarks:
Before:

goos: linux
goarch: amd64
pkg: benchmark
cpu: AMD Ryzen 7 5800X 8-Core Processor             
BenchmarkGoapAI-16                 49186             25324 ns/op           12777 B/op        449 allocs/op

After:

goos: linux
goarch: amd64
pkg: benchmark
cpu: AMD Ryzen 7 5800X 8-Core Processor             
BenchmarkGoapAI-16                129136              9122 ns/op            8288 B/op        166 allocs/op

Additional improvements:

  • Heap storage for the nodes, to reduce the number of slices & maps. Reduces the fetch of next node
  • One call to fetchNodeInHeap instead of two
  • Hash with XOR incrementation
  • Simplified hash using a simple hash multiplication
  • Unit Test coverage > 90%
  • Code documentation

@ragoune ragoune merged commit 9b024ab into master Oct 30, 2025
3 checks passed
@ragoune ragoune deleted the feat/heuristic branch October 30, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant