-1

Basically my goal is to find the target node to solve the TSP. In order to find this target node I need to know the shortest path between two nodes, specifying only the starting point where:

  • The minimum cost path visits all nodes in subset of nodes.
  • Cost is minimum.

My return function would return a NodeId which would be interpreted as the target node ID.

Any pseudocode would be appreciated.

chrslg
  • 9,023
  • 5
  • 17
  • 31
Joan
  • 1
  • That is exactly what Ford's and Dijkstra's algorithm are doing: finding shortest path from a starting node to any other nodes. – chrslg Oct 28 '22 at 10:54

1 Answers1

0

You want the minimum spanning tree algorithm, modified to span your subset of nodes.

Here is how it goes:

- LOOP over every pair of nodes in the subset
  - APPLY Dijkstra algorithm to find shortest path between node pair.
- CREATE new graph, containing only the nodes in the subset
- ADD links between nodes in new graph with cost equal to length of shortest path between them in original graph.
- APPLY minimum spanning tree algorithm
- For links in the spanning tree, replace with nodes and links on shortest path between nodes in original graph.

This will give you the shortest tree that includes every node in the subset.

I do not know what you mean by "target node". Please clarify what this is.

ravenspoint
  • 19,093
  • 6
  • 57
  • 103