Search code examples
matlabgraphminimum-spanning-treekruskals-algorithm

Plotting a tour from an MST


I am new to matlab coding and I would like to know how to plot a tour visiting all points in a minimum spanning tree (yes, TSP/TSM). I was given a set of points a matrix of 20x2 and I was able to find out the MST of these points and I need help figuring out how to plan a tour of these points of minimum possible distance?

my adj matrix for the MST is,

X_st =

     0     0     1     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0     0     0
     0     0     0     0     0     0     0     1     0     0     0     0     0     1     0     0     0     0     0     0
     1     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1
     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0     0     0     1     0     1
     0     0     0     0     0     0     0     0     0     0     1     0     0     0     0     0     1     0     0     0
     0     1     0     0     0     0     0     0     0     0     1     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0     0
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0
     0     0     0     0     0     0     1     1     0     0     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0
     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0     0     0     0     0
     0     1     0     0     0     1     0     0     0     0     0     0     0     0     0     1     0     0     0     0
     0     0     1     0     0     0     0     0     0     0     0     0     1     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0     0     0     0     1     0
     1     0     0     0     0     0     1     0     0     0     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     1     0     0     1     0     0     0     0     0     0     0     0     0     0     0
     0     0     0     1     0     0     0     0     0     1     0     1     0     0     0     1     0     0     0     0
     0     0     0     0     1     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0

Obtained from kruskal algorithm to plot a MST of a complete graph.

My, neighbouring weighted matrix obtained from kruskal function is,

     1     3
     7    17
     5    20
     6    14
     1    17
     6    20
    16    19
     2    14
     7    11
     6    18
    12    19
    14    16
    10    19
     8    11
     2     8
     3    15
     9    18
     4    19
    13    15

Any guidance would be much appreciated.


Solution

  • once you have extracted the points for the MST using krushkals algorithm u need to use f=figure then for each (x,y) point it has to be like f = f + plot(x1,y1,x2,y2,[options]) plot and the plot code should be surrounded by hold on hold off please let me know if the answer was helpful the complete snippet will be like

    f = figure;
    hold on
    f = f + plot(x1,y1,x2,y2) //put this in a loop for all points 
    hold off