0

Traditionally the traveling salesman problem works with the distance from city to city taking from its origin. This works perfectly fine if you can neglect the travel cost through the city compared to the travel cost between cities. So the question is, how can the shortest route be found when the traveling cost through a city can't be neglected?

The easiest way to explain the problem better is by taking a greedy algorithm, nearest neighbour for example starting at A who goes to B and then having 2 options, one going to C for 5 cost and one going to D for 6 cost. At first C looks like the cheaper options, but traveling through the city to go to B takes 3 cost and traveling through the city to go to D only takes 1. So in the end, taking D would be the cheaper option.

Before I created a map with the traveling cost between each city, but as you can see in the example, traveling through a city has big impact on the true traveling cost.

Any help on how to tackle such problem?

EDIT: the prefered edge can be chosen at the starting point (no traveling through city). The destination is reached when the salesman enters the city (no traveling through city). traveling through cities cost the same for both directions.

73nismit
  • 57
  • 1
  • 6

2 Answers2

1

If we assume that city cost existent for start node and end node as well, then you will need to add that cost to the vertice you wish to include into your road. If a vertice has a cost of n and its target has a cost of m and the agent will have to go through the city, then the cost is n + m. If the start and end node is included into inner city traffic cost, then you need to initialize your total travel cost to the cost of the starting city and you will be able to add the target city's cost each time you traverse a vertice. If not, then you initialize the cost with 0 and will only add the city travel cost if you are not at the very last step.

If the agent has to visit all the cities exactly once, then the city cost can be ignored from the algorithm, as it will be a constant which can be calculated and added to the optimal vertice road cost.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • I don't think I get what you're saying, doesn't that make the traveling cost through cities the same for every entering point? for example, crossing city C takes 5 extra cost instead of when comming from B, going through C takes 5 extra cost? – 73nismit May 08 '17 at 12:19
  • @73nismit is there a difference in how the city is crossed in your situation? – Lajos Arpad May 08 '17 at 14:12
  • yes, from from B to C to D crosses C in different way than A to C to D. the cost of traveling through the city is dependend on the previous location. Making a map that contains data from C to D when comming from B etc creates a huge array. – 73nismit May 08 '17 at 15:47
0

My idea would be to replace every city node C by a clique of size n = |Neighbors(C)|. Connect every neighbor of C to a node in the clique.

The edges inside the clique represent "transit" through C, and they have the corresponding transit costs associated. Then, you would have to modify the traveling saleman "goal" to visit at least one node of each city cliques (instead of visiting each clique) - or mark all city clique nodes as visited once one is visited.