An algorithm for the traveling salesman problem