# Traveling Salesman Problem Without Return

32 views (last 30 days)
Jake Smith on 17 Jan 2019
Commented: Walter Roberson on 24 Jul 2021
I've been looking at the traveling salesman problem with the code provided by MATLAB here:
While I understand most of the content, I'm wondering if there is a variation that can be implemented that doesn't form a complete loop after the subtours have been removed, but is still optimized for distance.
In other words, what can be changed in the existing code so there is no return to a "start" point after the last point has been reached?
Walter Roberson on 17 Jan 2019
That is a bit tricky in linear programming. You would be trying to program the conditions that:
• exactly one object has an in-degree of 0
• all other objects have an in-degree of exactly 1
• exactly one object has an out-degree of 0
• all other objects have an out-degree of exactly 1
You can give constraints such as the sum of the in-degree over all nodes is (nodes-1) and you can give constraints such as the in-degree of each node is exactly 1, but ... hmmm...
You can add constraints that the in-degree of each node is either 0 or 1 (>=0 and <=1) , and that the out-degree of each node is either 0 or 1, and you can add constraints that the sum of the in degrees is (nodes-1) and the sum of the out degrees is (nodes-1) .
But at the moment, there would still seem to be the loophole that it could end up creating a tour of all but one of the nodes and leaving that other node isolated. The in-degree of all of the nodes in the tour would be 1, and the out-degree of all of the nodes in the tour would be 1, and the in-degree of the isolated node would be 0, and the out-degree of the isolated node would be 0, and the total in-degree would be (nodes-1) and the total out-degree would be (nodes-1). The equality and inequality constraints would be satisfied. Ah, but if you forced the total degree for each node to be >= 1 and <= 2 then that would eliminate this possibility and by the pigeon-hole principle you would have to get a path instead of a tour.

Iuliu Ardelean on 15 Jul 2021
Edited: Iuliu Ardelean on 16 Jul 2021
Hi
If you know your start and end points, and your graph is not directed:
start_idx = 1; % make node 1 start point
end_idx = 2; % make node 2 end point
constr2trips = optimconstr(nStops,1);
for stop = 1:nStops
whichIdxs = outedges(G,stop); % Identify trips associated with the stop
constr2trips(stop) = sum(trips(whichIdxs)) == 2;
end
whichIdxs = outedges(G, start_idx);
constr2trips(start_idx) = sum(trips(whichIdxs)) == 1;
whichIdxs = outedges(G, end_idx);
constr2trips(end_idx) = sum(trips(whichIdxs)) == 1;
tsp.Constraints.constr2trips = constr2trips;
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 24 Jul 2021
See my description https://www.mathworks.com/matlabcentral/answers/440292-traveling-salesman-problem-without-return#comment_661629 of why setting in-degree and out-degree by themselves are not enough.

### Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

R2017a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!