I am solving the Travelling Salesman Problem. I have a cost matrix and i want to find the cost of a tour.
Method i have written works but my question is whether it is written in a Pythonic style. Any suggestions to improve the style are welcome.
Method i have written works but my question is whether it is written in a Pythonic style. Any suggestions to improve the style are welcome.
def findTourCost(self, tour):
total = 0
for index, value in enumerate(tour):
if index == len(tour) - 1:
total = total + self.costMatrix[value][tour[0]]
break
total = total + self.costMatrix[value][tour[index + 1]]
return total