7

I have 2D world maps that are basically Mercator-Like projections, (If you walk west long enough you end up east of where you started)

Question I have: Can you use A* for computing paths on these types of maps as well?

I can't think of any reason why you couldn't (I'm thinking that you would simply represent the edge map nodes such that the North, South, East, Wed, "border" nodes simply connected to the opposite side).

Thanks in advance, if anyone has seen something like this before or can give me a few hints I would appreciate it.

1

3 Answers 3

4

Pathfinding algorithms don't really care about global topology of the map. The only tricky part is to get a good estimator for A* but using the 3D distance should be ok if your map is indeed a surface in a 3d space and step cost is step length.

Your map can have all sort of strange "connections" (including for example knotted bridges) and this will not be a problem if you implement A* correctly.

3
  • 1
    Although really weird and irregular teleportation points may make creating a good the heuristic (and thus, keeping search space low) much harder - especially when the shortcuts can change dynamically.
    – user395760
    Commented Sep 21, 2011 at 17:06
  • @delnan: True. That's why I said "if your map is a surface in a 3d space and your step cost is step length". Clearly if you have a "teleport" then step cost is not step length.
    – 6502
    Commented Sep 21, 2011 at 17:09
  • @6502 Thank you for your answer, I'll pursue an A* implementation Commented Sep 21, 2011 at 17:35
2

I can't imagine why a Mercator-Like projections would cause a problem for A*, as long as your heuristic function approximates distances correctly. I think something along the below function should work fine

float heuristic(point from, point to, size mapsize) {
    float x = from.x - to.x;
    if (abs(x) > mapsize.x/2)
        x = mapsize.x - x;
    float y = from.y - to.y;
    if (abs(y) > mapsize.y/2)
        y = mapsize.y - y;
    return sqrt(x*x+y*y);
}
7
  • Please test it first, I'm not 100% confident in it. Commented Sep 21, 2011 at 17:40
  • Think that should use x = mapsize.x - x and y = mapsize.y - y in the if statement blocks. Commented Sep 21, 2011 at 18:43
  • No, I mean it's flat-out wrong. If for argument's sake mapsize.x is 1.0 and the x-differential is 0.6, and if the from point is positioned right on the x-edge, then basically you should be able to go 0.6 one way and 0.4 the other way to get to it. (In other words, both paths should end up adding to the size of the map.) So you should be using the entire mapsize value rather than half of it. Commented Sep 21, 2011 at 19:48
  • Also, given the same paramters, mapsize.x / 2 is equal to 0.5, and 0.5 - 0.6 is equal to -0.1, which is just weird. Yes, negative numbers will work in the distance formula thanks to the squaring, but the absolute value itself is just plain wrong. Commented Sep 21, 2011 at 19:49
  • 1
    @PlatinumAzure so are you saying that the heuristic can exceed the actual distance?
    – user555045
    Commented Sep 21, 2011 at 19:51
1

Edited: I realize know I was misled by the non-graph theoretical) use of the word edge (where the question title strongly suggested a graph algorithm question :))

Why do you suppose there are no edges? There are many logical discrete locations that you could model, and limited connections between (i.e. not where a wall is :)). There you go: you have your edges.

What you probably mean is that you don't want to represent your edges in data (which you don't have to, but still there are the logical edges that connect locations/points.)

That said:

you ask whether someone has seen things like this before. I vaguely recall seeing something relevant to this in Knuths Dancing Links article (DLX) which is an implementation technique for A* algorithms.

The article specifically treats states as 'cells' (in a grid) with east/west/north/south links. It's been a long time so I don't quite recall how you would map (no pun intended) your problem on that algorithm.

The dance steps. One good way to implement algorithm X is to represent each 1 in the matrix A as a data object x with five fields L[x]; R[x]; U [x]; D[x]; C[x]. Rows of the matrix are doubly linked as circular lists via the L and R fields ("left" and "right"); columns are doubly linked as circular lists via the U and D fields ("up" and "down"). Each column list also includes a special data object called its list header.

enter image description here

4
  • I'm pretty sure Dancing Links is an implementation technique for AlgorithmX to solve exact cover problems, are you sure it can do A* too?
    – user555045
    Commented Sep 21, 2011 at 19:27
  • I remember them as 1 and the same thing. Now I might be completely off the tracks, but it was an honest memory. Basically: no, i'm not sure. Just hoping that the OP would be able to recognize a potential match. If someone can pinpoint the mismatch or any big error on my side, I'll be happy to delete the answer tough.
    – sehe
    Commented Sep 21, 2011 at 19:32
  • reworded my intro of Dancing Links raise fewer expectations :)
    – sehe
    Commented Sep 21, 2011 at 19:34
  • @sehe Sorry about that! I'll try and be more careful with my question wording in the future. Commented Sep 22, 2011 at 5:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.