# Traveling Salesman with paths instead of points

I have a rectangular area filled with vector paths (an SVG document, to be precise). Starting at the origin, I need to visit every part of every path.

For an open path, like a line or an arc, I would most often walk to one end of the path, walk the length of the path, then walk to another path.

For a closed path, like a circle or a square, I would most often walk to a point on the path near my previous stop, walk the perimeter of the path, then walk to another path.

I say "most often" above because it would also be valid to visit a path, not necessarily at an endpoint, walk along part of it, then leave to another path, later coming back to finish the abandoned walk.

The purpose of this problem is to minimize total travel distance for a laser cutter or CNC mill that needs to cut along all the paths.

Are there any existing algorithms (or open source tools) for solving this problem?

EDIT: Two paths never cross. Anywhere that might happen will have been altered from 4 vertices and 2 paths to 5 vertices and 4 paths by a previous step in my workflow.

EDIT2: The set of paths is disjoint. Some steps in the solution will be between pieces of disconnected paths.

• I'm fairly sure it only makes sense to walk from one path to another at the points where their separation is (locally) minimal. If that's true, then there are only finitely many valid transitions, and you can reduce this to the usual discrete TSP on a graph.
– user856
Mar 8, 2017 at 21:46
• @Rahul that seems like a plausible proposition, but I don't see how to reduce it to the usual TSP on a graph because some of the steps are forced (from one end to the other for a given pair of transitions). Mar 8, 2017 at 22:05
• I see what you mean. Maybe it should be modeled as a variation of TSP where some edges are required to be traversed. I wonder if this is a standard variation of the problem.
– user856
Mar 9, 2017 at 2:53
• You would also need to allow some vertices to be visited twice. Two major changes to the standard TSP, which makes finding an existing variation unlikely :( Mar 9, 2017 at 6:11

As far as I see, taking all crosspoints as vertices and all parts of pathes as edges we come to the Chinese postman problem. Unlike the Travelling salesman problem the Chinese postman problem is polynomially solvable. You can find $O(n^3)$ solution here.
• All right, I see. I thought that your picture is connected, while now I understand it is completely disconnected. Anyway it is more like CPP for graph (on $n(n - 1)$ vertices if you have $n$ pathes) with selected edges to travel then TSP. Mar 9, 2017 at 20:32