To estimate the traveling salesman problem using the dynamic programming technique in Matlab, we can follow the steps below:
dist
between cities and the starting city start
.n
and initialize the dp
table with Inf
values and set dp(start, 1) = 0
.j
from 2 to n
, and k
from 1 to n-1
:
S
subset of cities of size j
that contains start
and k
, compute dp(S,j)
as:
main.m43 chars2 lines
m
is any city in S
.optDist
is given by:
main.m51 chars2 lines
k
is any city that leads to the optimal tour.Here's the Matlab code implementing this algorithm:
main.m839 chars39 lines
gistlibby LogSnag