1

Take the square tiling of the plane, and imagine a finite, connected and simply connected subset D of tiles. D can of course also be interpreted as a particular subgraph of the square grid by taking a node for each tile and connecting adjacent nodes.

Let's say I have a start node/tile A and an end tile B both in D and in D's boundary.

Is there a simple, straightforward algorithm for finding reasonably long self-avoiding paths in D between A and B?

I've found literature referring to finding the absolute longest path, and suboptimal algorithms which while performing very good look extremely complex. I was wondering whether there exist tamer algorithms which do good enough.

My only idea here is to compute the shortest path through A*, then distorting it by "folding" laterally to fill as much space as possible, but I'm not sure whether that's a good idea.

Another idea is whether there is an almost stupidly easy "scanline" pattern that fills the space between A and B and therefore performs well for a "rectangleish" D. I suspect this exists, but I cannot find it.

1 Answers1

0

For square grid greater than 2-Dimensions:
The Longest Path problem is considered to be NP-Hard; it can't be solved in polynomial time unless P=NP for some arbitrary graph.

Having said that, you could do a DFS on each node to determine the longest path. This is all assuming that the graph is weighted (which you have not indicated in your post). It's important to note that you should not allow repeating of vertices.

At the end of the DFS, compare your current longest path with the one that is previously considered to be the longest. Replace this result with the longest as many time as required.

The running time is not great; exponential

For square grid that is 2-Dimensions

Evan Bechtol
  • 2,855
  • 2
  • 18
  • 36
  • I see, thanks. This is for rectangular portions though, maybe it can be adapted (as suboptimal) to arbitrary regions by partitioning the region in rectangles. – Riccardo Antonelli Apr 15 '16 at 11:43