2

This is my probleme, I've got a list of point in matrix and I want to link all of these points and minimize this cover. I work on 8-neighborhood, and link must be also on point.

For example, one solution :

╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗
║   ║ * ║*2 ║   ║   ║   ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ 5*║   ║   ║   ║   ║   ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║ * ║   ║   ║ 3*║   ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║ * ║   ║   ║ * ║   ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║   ║ * ║ * ║   ║ * ║   ║ * ║ * ║*4 ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║ 1*║   ║   ║   ║   ║ 6*║   ║   ║   ║
╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝

One other :

╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗
║   ║   ║*2 ║   ║   ║   ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ 5*║ * ║   ║   ║   ║   ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║   ║ * ║   ║ 3*║   ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║   ║   ║ * ║   ║ * ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║   ║ * ║   ║   ║   ║ * ║ * ║ * ║*4 ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║ 1*║   ║   ║   ║   ║ 6*║   ║   ║   ║
╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝

So I search an algorithm to find this minimal cover of my set of points. I search on internet but I don't find what I need but similar problems like Minimum spanning tree, Minimal vertex cover ...

Some ideas would be appreciated

Hideman
  • 81
  • 1
  • 10
  • 1
    What is your metric for "minimal"? Total path length (with what distance metric)? Total added points? I'm wondering, because neither of the given solutions appears minimal by any well-behaved metric. – Prune Oct 23 '17 at 22:02
  • minimal in total path length to cover all off my points. distance of 1 it's grid so if we move to 8-neighborhood near case the cost is 1 so i want to find optimal path – Hideman Oct 25 '17 at 17:34

2 Answers2

1

The rectilinear Steiner algorithm isn't quite what you want; it depends critically on the orthogonality of available moves.

Instead, I think you need Bresenham's line algorithm (as you already said) to connect points found with a basic property of added Steiner nodes: each Steiner node has three edges that meet at 120-degree angles. The node is the Fermat point of a triangle with appropriately chosen vertices (such that those vertices form a minimal triangle in the Steiner tree).

In your example, your smallest triangle is nodes 2, 3, 5; the Fermat point A (rounded to the lattice) is just to the right of 5, as seen in your second diagram. Your connected tree is nodes 2, 3, 5, A.

The next "best" triangle that includes a new node is A, 3, 1. The Fermat point B will be in the same column as node 2, and one row below node 3. The connected tree is now 1, 2, 3, 5, A, B.

Extending the process, your remaining triangle will be 3, B, 6 (adding point C) and (I think) C, 6, 4. There will then be a small amount of lattice dithering to achieve the final result (removing B and C from the tree). This is your second example. Note that the original connections AB and B1 could have chosen a point one unit to the left; the dithering would need to have them closer to node 3, and then remove B from the tree.

╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗
║   ║   ║*2 ║   ║   ║   ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ 5*║ A*║   ║   ║   ║   ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║   ║ * ║   ║ 3*║   ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║   ║ B ║ * ║ C ║ * ║   ║   ║   ║   ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║   ║ * ║   ║   ║   ║ D*║ * ║ * ║*4 ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║   ║ 1*║   ║   ║   ║   ║ 6*║   ║   ║   ║
╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝
Prune
  • 76,765
  • 14
  • 60
  • 81
0

This is the Steiner tree problem and NP-hard.

In your example it seems you got a 8-neighborhood grid here as diagonals are allowed. In the case of 4-neighborhood, there is a special version called Rectilinear Steiner tree (still NP-hard).

Your problem seems to be an example of the Steiner tree in graphs variant.

sascha
  • 32,238
  • 6
  • 68
  • 110
  • Yes it's exactly what I want in adtion with Bresenham's line algorithm. Thanks you for your answer. – Hideman Oct 24 '17 at 06:18