Search code examples
algorithmtraveling-salesman

How to define a time-distance function for the Traveling Salesman algorithm


I wrote a program that solves the traveling salesman problem minimizing the travel distance. Now I'm triyng to create a weight function that takes distance and time and outputs a value I can use instead of the distance for the TSP. My idea is to let the user input a percentage (like 70%) and weight the distance and time somehow.

The problem is I've no idea how to compare distance in meters with time in seconds.


Solution

  • One way to go is to specify a generalized cost function, i.e. you determine the costs (in monetary units) for one distance unit AND the costs for one time unit. For example, if your traveling salesman is a real traveling salesman then costs_per_time_unit could be approximated with wage_per_time_unit and cost_per_distance_unit with fuel_cost_per_distance_unit + ...

    This yields c_generalized = cost_per_time_unit * time + cost_per_distance_unit * distance and you are done.