0

I've been struggling to solve it using branch-and-bound to find the optimal path for the next task:

enter image description here

There's a list of cities, that are all connected with each other, basically, a complete graph, each city has a interest index ( city 'A' has 8 interest points, city 'B' has 9). There's a limited budget for travelling and we need to come up with a path that gets the most possible interest indices. Also, the path must start and end at the same city, so we need to return back to the city 'A' from the last one if we started there, for example.

It is not necessary to visit all the cities, sometimes the budget doesn't allow this. Starting city can be chosen as well as the ending one, but the thing is you need to return back to the starting one.

Visiting one city twice is not allowed, the only situation you can visit the same city twice is when returning back to the starting one.

Also, travelling across the cities X and Y via some other city may be cheaper so the graph is non-metric.

Someone has asked about the real world problem this task covers, it's the tourism path algorithm. We need to create the path with most interest covered with available money.

What other algorithms are suitable for this kind of task?

I tried greedy algorithm and there was an attempt to solve it with branch and bound

I expect a valid solution with branch-and-bound on any language.

  • The travelling budget is the maximum number of edges that can be traversed? The start/end city can be freely chosen to give the best result, rather than specified? Please clarify these points in your question. – ravenspoint May 09 '23 at 23:57
  • I see that your example has numbers on the edges. I assume these have something to do with the traveling budget. Please clarify – ravenspoint May 10 '23 at 00:00
  • 1
    Your example graph is not metric. What is the actual problem you are trying to solve? Does your example correctly model your problem? – ravenspoint May 10 '23 at 00:59
  • @ravenspoint yeah, budget is something like 600 dollars, and we need to use it to have the most interest indices covered and afford to get back to the first city. – unfavourite May 10 '23 at 10:54
  • Since your graph is not metric ( your tourist can travel through hyperspace, maybe? ) there is no easy solution to your problem. You probably are just making these numbers up out of thin air. – ravenspoint May 10 '23 at 11:22
  • @ravenspoint why is it such a problem? It is quite real that travelling somewhere with transit is cheaper than doing it straight forward – unfavourite May 10 '23 at 12:00
  • A metric graph allows the use of the metric TSP algorithm which allows an guaranteed optimal solution. If the graph is not metric, then the solution is not guaranteed to be optimal. – ravenspoint May 10 '23 at 12:31
  • @ravenspoint maybe you could take a look at the task itself and give it a try to comprehend it somehow different, please? Here's the link for the task and what we've already came up with for it. > > > https://imgur.com/a/ErYwQYI < < – unfavourite May 10 '23 at 12:32
  • Looks like you did make up those edge numbers out of thin air. Not cool! – ravenspoint May 10 '23 at 12:37
  • @ravenspoint Can you explain then what is the problem with it? Maybe you can give an advice for improving the problem? – unfavourite May 10 '23 at 13:18
  • Not sure what you mean by "improving the problem". What is your purpose - you do not say. Maybe it is just homework? – ravenspoint May 10 '23 at 13:27

1 Answers1

-1

The branch and bound version of the TSP algorithm is only necessary if the graph is not metric. ( A metric graph means that for any two vertices ( X and Y ) the direct edge between X and Y is always cheaper than the travelling between X and Y via a third vertex ). Most graphs modelling real world problems are metric. The metric version of the TSP algorithm is simpler to code and runs much faster than branch&bound.

Since your example graph is not metric, I have implemented the TSP branch&bound solution to your problem.

Here is the algorithm:

Solve travelling salesman problem to visit every city once as cheaply as possible

If solution cost is less than budget, SOLVED

Delete city with smallest interest, and all its links

Repeat until solution found.

Here is the output from a run on your example graph for a budget of 1000

Minimum cost : 750 Budget : 1000
Path Taken : a d b c e

and for budget of 500

Dropping e ( 6 ) from itinerary
Dropping c ( 7 ) from itinerary
Minimum cost : 200 Budget : 500
Path Taken : a b d

The complete application C++ code, documentation and discussion can be found in the github repository https://github.com/JamesBremner/so76213744

ravenspoint
  • 19,093
  • 6
  • 57
  • 103