The Network Solver

Traveling Salesman Problem

The traveling salesman problem (TSP) finds a minimum-cost tour in an undirected graph G that has a node set, N, and link set, A. A tour is a connected subgraph for which each node has degree two. The goal is then to find a tour of minimum total cost, where the total cost is the sum of the costs of the links in the tour. Associated with each link $(i,j) \in A$ are a binary variable $x_{ij}$, which indicates whether link $x_{ij}$ is part of the tour, and a cost $c_{ij}$. Let $\delta (S) = \{ (i,j) \in A \; |\;  i \in S, \;  j \notin S\} $. Then an integer linear programming formulation of the TSP is as follows:

\[  \begin{array}{llllll} \text {minimize} &  \displaystyle \sum _{(i,j) \in A} c_{ij} x_{ij} \\ \text {subject to} &  \displaystyle \sum _{(i,j) \in \delta ({i})} x_{i,j} &  = &  2 &  i \in N &  (\mr{two\_ match}) \\ &  \displaystyle \sum _{(i,j) \in \delta (S)}x_{ij} &  \geq &  2 &  S \subset N, \;  2 \leq |S| \leq |N| - 1 &  (\mr{subtour\_ elim})\\ &  x_{ij} \in \{ 0,1\}  & & &  (i,j) \in A \end{array}  \]

The equations (two_match) are the matching constraints, which ensure that each node has degree two in the subgraph. The inequalities (subtour_elim) are the subtour elimination constraints (SECs), which enforce connectivity.

In practical terms, you can think of the TSP in the context of a routing problem in which each node is a city and the links are roads that connect cities. Given the pairwise distances between each city, the goal is to find the shortest possible route that visits each city exactly once. The TSP has applications in planning, logistics, manufacturing, genomics, and many other areas.

In the network solver, you can invoke the traveling salesman problem solver by using the TSP= option.

The algorithm that the network solver uses for solving a TSP is based on a variant of the branch-and-cut process described in Applegate et al. (2006).

The resulting tour is represented in two ways: In the numeric array that is specified in the ORDER= suboption in the SOLVE WITH NETWORK statement, the tour is specified as a sequence of nodes. In the set that is specified in the TOUR= suboption of the TSP option, the tour is specified as a list of links in the optimal tour.

Traveling Salesman Problem of a Simple Undirected Graph

As a simple example, consider the weighted undirected graph in Figure 9.65.

Figure 9.65: A Simple Undirected Graph

A Simple Undirected Graph


The links data set can be represented as follows:

data LinkSetIn;
   input from $ to $ weight @@;
   datalines;
A B 1.0   A C 1.0   A D 1.5   B C 2.0   B D 4.0
B E 3.0   C D 3.0   C F 3.0   C H 4.0   D E 1.5
D F 3.0   D G 4.0   E F 1.0   E G 1.0   F G 2.0
F H 4.0   H I 3.0   I J 1.0   C J 5.0   F J 3.0
F I 1.0   H J 1.0
;

The following statements calculate an optimal traveling salesman tour and output the results in the data sets TSPTour and NodeSetOut:

proc optmodel;
   set<str,str> EDGES;
   set<str> NODES = union{<i,j> in EDGES} {i,j};
   num weight{EDGES};
   read data LinkSetIn into EDGES=[from to] weight;
   num tsp_order{NODES};
   set<str,str> TOUR;

   solve with NETWORK /
      loglevel = moderate
      links    = (weight=weight)
      tsp
      out      = (order=tsp_order tour=TOUR)
   ;

   put TOUR;
   print {<i,j> in TOUR} weight;
   print tsp_order;
   create data NodeSetOut from [node] tsp_order;
   create data TSPTour from [from to]=TOUR weight;
quit;

The progress of the procedure is shown in Figure 9.66.

Figure 9.66: Network Solver Log: Optimal Traveling Salesman Tour of a Simple Undirected Graph

NOTE: There were 22 observations read from the data set WORK.LINKSETIN.         
NOTE: The number of nodes in the input graph is 10.                             
NOTE: The number of links in the input graph is 22.                             
NOTE: Processing the traveling salesman problem.                                
NOTE: The initial TSP heuristics found a tour with cost 16 using 0.07 (cpu:     
      0.06) seconds.                                                            
NOTE: The MILP presolver value NONE is applied.                                 
NOTE: The MILP solver is called.                                                
          Node  Active    Sols    BestInteger      BestBound      Gap    Time   
             0       1       1     16.0000000     15.5005000    3.22%       0   
             0       0       1     16.0000000     16.0000000    0.00%       0   
NOTE: Optimal.                                                                  
NOTE: Objective = 16.                                                           
NOTE: Processing the traveling salesman problem used 0.10 (cpu: 0.09) seconds.  
{<'A','B'>,<'B','C'>,<'C','H'>,<'H','J'>,<'I','J'>,<'F','I'>,<'F','G'>,<'E','G'>
,<'D','E'>,<'A','D'>}                                                           
NOTE: The data set WORK.NODESETOUT has 10 observations and 2 variables.         
NOTE: The data set WORK.TSPTOUR has 10 observations and 3 variables.            



The data set NodeSetOut now contains a sequence of nodes in the optimal tour and is shown in Figure 9.67.

Figure 9.67: Nodes in the Optimal Traveling Salesman Tour

Traveling Salesman Problem

node tsp_order
A 1
B 2
C 3
H 4
J 5
I 6
F 7
G 8
E 9
D 10



The data set TSPTour now contains the links in the optimal tour and is shown in Figure 9.68.

Figure 9.68: Links in the Optimal Traveling Salesman Tour

Traveling Salesman Problem

from to weight
A B 1.0
B C 2.0
C H 4.0
H J 1.0
I J 1.0
F I 1.0
F G 2.0
E G 1.0
D E 1.5
A D 1.5
    16.0



The minimum-cost links are shown in green in Figure 9.69.

Figure 9.69: Optimal Traveling Salesman Tour

Optimal Traveling Salesman Tour