1

I have a graph with 80 cities. I need to find a shortest possible route passing through 10 cities.

I have to start from a city that already defined as starting city and user will enter 10 city names from the city list. I must travel this 10 cities and than I have to go back to the city where I started. I just have all the information about road distances between the cities that are adjacent.I haven't any information except that.

I know that Dijkstra, etc. found the shortest path between 2 cities and some heuristic algorithms need more data than that.

Can I use Dijkstra for the shortest path between starting city and other 10 cities and then find a min spanning tree of that and traverse on it? Is there any heuristic algorithm that I can use with this data?

RBT
  • 24,161
  • 21
  • 159
  • 240
j4ckhunter
  • 11
  • 2
  • After a-priori preparation of your 10/11 city subgraph, this sounds like a classic [TSP](https://en.wikipedia.org/wiki/Travelling_salesman_problem) where lots of resources are available. If your graph is not complete, you might give missing edges very high costs (and check feasibility later if not guaranteed). Check if this fits your problem and maybe go the integer-programming route. – sascha Mar 26 '20 at 18:41
  • @sascha is correct this problem is at least as hard as TSP, if you have any additional information about the structure of the graph, please share. Unless you are willing to settle on an approximation, you will need to brute force that. – Yonlif Mar 26 '20 at 19:03
  • thanks for comments.we have no information about structure type of graph. we just know that graph basicly represents all cities,their adjacent cities and road costs in a matrix form. – j4ckhunter Mar 26 '20 at 19:30
  • I think we're trying to solve the same problem. Asked [a similar question](https://stackoverflow.com/questions/60963398/nullpointerexception-at-org-graphstream-algorithm-apspapspinfo-getshortestpatht) yesterday, still unasnswered. I'm using APSP algorithm and Java's GraphStream library. – Rasshu Apr 01 '20 at 12:14

1 Answers1

3

Given your 10 cities, find the shortest path between each pair. That's only 45 calls to Dijkstra's algorithm. This gives you a complete graph on 10 vertices.

Now you have a travelling salesman problem, but 10 cities is not so many, and you're given the start city, so there's only 9! (362880) possibilities. I'd simply try all permutations and find the minimal one.

You can do something cleverer, but this simple brute-force solution will be fast and easy to code.

[edit: maybe you have a start city and 10 other cities. Still, 10! (3728800) is small enough to make searching every permutation fast enough]

Paul Hankin
  • 54,811
  • 11
  • 92
  • 118
  • 2
    Dijkstra's algorithm finds shortest paths from the source to all other nodes in the graph so you only have to run it on each source, rather than each pair of cities. – Peter de Rivaz Mar 26 '20 at 21:49