If you are interested in exact solutions, and you are not in a geometric setting (i.e., no triangle inequality), you can just add a very large constant to each of the non-pairs, and solve the regular traveling salesman problem. This constant will force you to use all the pair edges (1 in the first problem, n in the second), and since the number of times you use non-pair edges is fix, it gives you an optimal solution.
Let's look at an example. Suppose you have four cities, A, X, Y, and Z, and A is at distance $1$ from each of the others, while the distance between any two of X, Y, Z is $100$. Then of course a solution to TSP starting at A is given by A to X to A to Y to A to Z to A – let's write this as AXAYAZA, which has length $6$, and visits A multiple times.
Now let's carry out the construction in Rahul's comment. We form a new problem with the same cities but with the distance between cities replaced by the length of the shortest path between the two cities. So in the new problem, A is still at distance $1$ from each of the others, but the distance between any two of X, Y, Z is $2$. Now the tirangle inequality is satisfied (although the configuration is still unrealizable in any Euclidean space), and a solution is given by AXYZA, length $6$, no city visited twice (except for both starting and ending at A).
So we have taken a problem where the solution has multiple visits to a city, and replaced it with an equivalent problem which doesn't. I hope it's clear that you can carry out this construction for any (finite) set of cities and distances. So you can always replace a problem with an equivalent problem where the triangle inequality is satisfied and no city gets visited more than once. So, there is no loss of generality in assuming the triangle inequality holds and no city gets visited more than once. That's why we can restrict our attention to what looks like, but really isn't, a special case.
Best Answer
With OR-Tools (very good idea) :
Allow the solver to drop all nodes with the AddDisjunction() method https://developers.google.com/optimization/routing/penalties
Add the (custom) constraint $$ \sum_{v \in V} x_v = 5$$ where $x_v$ takes value $1$ iff node $v$ is visited. You need to use the solver().Add() method :https://github.com/google/or-tools/issues/847.