This is a pretty nasty problem. This is the shortest Hamiltonian path, but you have a ton of edges (all edges (u, v), where u is the endpoint of some line and v is the starting point of another line), and the distances are not symmetrical. The elegant ZDD method described in TAOCP 4A is not really applied, I think it will be loaded in all these parts.
Here's an idea (not optimal, but in any case, it seems like a pretty good idea), borrowing from TSP:
For every line s Schedule = empty sequence For every line n insert n in the optimal position in Schedule Apply 2-opt (see TSP) to the Schedule Take the best Schedule.
Be very careful with this 2-opt. This is often described for the case of symmetrical distances, which allows optimizing the calculation of "distance change". Here you cannot here.
Here's another idea, borrowing heavily from TSP:
Solve a ton of problems with ILP. For each node s and t (not equal):
- boolean for each edge.
- weights are the lengths of these ribs.
- every node
n that is not s or t gives a form constraint of "the sum of all edges adjacent to n == 2" - for nodes
s and t , this sum instead of 1 - It is lazy to add restrictions that everything should be a single communication component, that is:
- discovery of connected components. If there is 1, this is the solution.
- if for each connected component is greater than 1,
- if it contains
s or t , add the restriction that the sum of all edges adjacent to this connected component must be 1. - otherwise, this amount should be 2.
Take advantage of all these solutions. This may take some time.
source share