SA: Using SA algorithm to solve TSP (data is the horizontal ordinate of 14 virtual cities) problem--jason Niu

Source: Internet
Author: User

%SA: Using SA algorithm to solve TSP (data is a horizontal ordinate of 14 virtual cities)--jason niu X = [16.4700 96.1000 16.4700 94.4400 20.0900 92.5400 22.39      00 93.3700 25.2300 97.2400 22.0000 96.0500 20.4700 97.0200 17.2000 96.2900 16.3000 97.3800 14.0500 98.1200 16.5300 97.3800 21.5200 95.5900 19.4100 97.1300 20.0900 92.5500];D = Distan  CE (X);    N = size (d,1);     T0 = 1e10; Tend = 1e-30;        L = 2;      Q = 0.9;  Time = Ceil (double (Solve ([Num2str (T0) ' * (0.9) ^x = ', Num2str (Tend)])));            Count = 0;  OBJ = zeros (time,1); Track = zeros (Time,n);  S1 = Randperm (N);    DrawPath (s1,x) title (' The initial path to draw a TSP problem using a custom function (randomly generated)-jason niu ') disp (' a random value in the initial population: ') OutputPath (S1); Rlength = Pathlength (D,S1);         DISP ([' Total Distance: ', Num2str (rlength)]), while T0 > Tend count = count + 1;    temp = zeros (l,n+1);      S2 = Newanswer (S1);     [S1,r] = Metropolis (s1,s2,d,t0); if count = = 1 | |               R < obj (count-1) obj (count) = R; Else OBJ (COUNT) = OBJ (count-1);    End Track (count,:) = S1;         T0 = q * T0; Endfigureplot (1:count,obj) xlabel (' Iteration count ') ylabel (' Distance ') title (' SA: shows the SA algorithm's optimization process for TSP (fitness function)-jason niu ') DrawPath ( Track (end,:), X) title (' SA: using SA to optimize the TSP problem, draw the optimal path graph-jason niu ') percent IX using SA algorithm optimization. The route and total distance of the output optimal solution disp (' Optimal solution: ') S = Track (end,:);p = OutputPath (S);d ISP ([' Total Distance: ', Num2str (Pathlength (d,s)]));

SA: Using SA algorithm to solve TSP (data is the horizontal ordinate of 14 virtual cities) problem--jason Niu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.