Yo, the TSP is of class NP-Complete, meaning that there is no defined method to get a guaranteed optimal solution. Your best bet is to approximate using greedy graph algorithms such as Dijkstras or if the number of cities you need to visit allows it, you can possibly use brute force, that is, calculate all possible paths and then choose the shortest. Warning: this will take factorial time.