jvkersch / pyconcorde

Python wrapper around the Concorde TSP solver
BSD 3-Clause "New" or "Revised" License
342 stars 95 forks source link

Set start node #10

Closed Carpetfizz closed 6 years ago

Carpetfizz commented 6 years ago

How do we specify the start vertex of the tour?

jvkersch commented 6 years ago

@Carpetfizz I do not know of a way to specify the start vertex. However, you can always apply a cyclic permutation to the tour to bring any desired vertex to the front:

>>> import numpy as np
>>> tour = np.arange(10)
>>> np.random.shuffle(tour)
>>> tour
array([1, 5, 7, 6, 0, 2, 9, 3, 8, 4])
>>> start = 7
>>> index = np.where(tour == start)[0][0]
>>> index
2
>>> np.hstack([tour[index:], tour[:index]])
array([7, 6, 0, 2, 9, 3, 8, 4, 1, 5])