[Graph] A* with heterogeneous heuristics
Dear all,
I haven't given up in trying to implement an A* algorithm with BGL. My
problem is theoretically simple, as in some previous posts.
Given a graph of letters, and a word, find the path in the
graph that minimizes the distance between the letters of
the word and the nodes in the graph.
It's best to show an example:
/*
* B H
* / \ /
* A---D---F---G---I
* \ /\
* C E
*
* input: A E I O U
* result: A D F G I
*/
With that graph, my heuristic should take into account not just the
letter in the graph per se, but the *corresponding* one in the input
word. So, starting with "AEIOU" the search will:
- expand A (A in **A**EIOU)
- find B, C, D
- expand D (closest to E in A**E**IOU)
- find D, F
- expand F (closest to I in AE**I**OU)
- find G
- expand G (only one, closest to O in AEI**O**U)
- find H, I
- expand U (closest to U in AEIO**U**)
This settings could also be more complicated, adding weights to edges,
but for now I am happy with this problem.
What I've done now? Implementing my own A* algorithm, by hand. Of course
this might work, but I'd prefer using BGL's facilities.
I must say that I am quite confused about BGL's data structures, as for
instance in the A* cities example (1), we need to create a weight map,
so what if I don't need weights? Moreover, predecessors and distances
are instantiated with a std::vector, but what happens if I need to
operate on a very large graph, for instance 200M nodes? Moreover, what
will happen when I will distribute the graph over a cluster with Boost
Parallel Graph? ... Ok maybe this is too ahead of the time! :)
Basically, I'd need to replicate my A* ugly by-hand implementation with
custom visitors and custom heuristics.
Below you may find my failed attempt. I need some help with this,
because I find the documentation a little bit hard to understand,
especially when some newbie like me approaches Boost :)
Failures in my code: I can't get to define a non-weighted graph, and the
call to the A* search is cryptic: I don't have weights. Should I define
fake ones for instance all equal to 1?
I really hope you guys can help me in this, my code works, but using BGL
would be best!
Thanks!
(1) http://www.boost.org/doc/libs/1_57_0/libs/graph/example/astar-cities.cpp
#include <iostream>
#include
participants (1)
-
Sensei