MATLAB多旅行商問(wèn)題源代碼_第1頁(yè)
MATLAB多旅行商問(wèn)題源代碼_第2頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、MATLABMATLAB 多旅行商問(wèn)題源代碼f unc t i onvarargout =mtspf_ga (xy, dmat, salesmen, min_tour, pop_size, num_iter, show_prog, show_res)% MTSPF_GA Fixed Multiple Traveling Salesmen Problem (M-TSP)Genetic algorithm (GA)% Finds a (near) optimal solution to a variation of the M-TSP bysetting% up a GA to search fo

2、r the shortest route (least distance needed for% each salesman to travel from the start location to individualcities% and back to the original starting place)% Summary:%1 Each salesman starts at the first point, and ends at the firstpoint, but travels to a unique set of cities inbetween2. Except for

3、 the first, each city is visited by exactly onesalesman% Note: The Fixed Start/End location is taken to be the first XY point% Input:%XY (float) is an Nx2 matrix of city locations, where N is the number of cities%DMAT (float) is an NxN matrix of city-to-city distances orcosts%SALESMEN (scalar intege

4、r) is the number of salesmen to visitthe cities% min_T0UR (scalar integer) is the minimum tour length for any of the%salesmen, NOT including the start/end point%POP_SIZE (scalar integer) is the size of the population(should be divisible by 8)% NUM_ITER (scalar integer) is the number of desired itera

5、tions for the algorithmto runSH0W_PR0G (scalar logical) shows the GA progress if trueSHOW_RES (scalar logical) shows the GA results if true% Output:%OPT_RTE (integer array) is the best route found by thealgorithm%OPT_BRK (integer array) is the list of route break points(these specify the indices%int

6、o the route used to obtain the individual salesmanroutes)% min_DIST (scalar float) is the total distance traveled by the salesmen% Route/breakpoint Details:%If there are 10 cities and 3 salesmen, a possibleroute/break% combination might be: rte = 5 6 9 4 2 8 10 3 7, brks = 3 7%Taken together, these

7、represent the solution 1 5 6 9 1 1 42 8 11 10 3 7 1,% which designates the routes for the 3 salesmen as follows:% Salesman 1 travels from city 1 to 5 to 6 to 9 andback to 1% Salesman 2 travels from city 1 to 4 to 2 to 8 andback to 1% Salesman 3 travels from city 1 to 10 to 3 to 7 andback to 1% 2D Ex

8、ample:%n二35;%xy = 10*rand(n, 2);%salesmen二5;%min_tour= 3;%pop_size二80;%num_iter= 5e3;%a = meshgrid(1:n);%dmat二reshape(sqrt(sum(xy(a, :)-xy(a,:) 2, 2), n, n);% opt_rte, opt_brk, min_dist= mtspf_ga(xy, dmat, salesmen, min_tour,%pop_size, num_iter, 1, 1);% 3D Example:%n = 35;%xyz = 10*rand(n, 3);%sales

9、men二5;%min_tour二3;%pop_size二80;%num_iter= 5e3;%a = meshgrid(1:n);%dmat = reshape(sqrt (sum(xyz (a, :)xyz(a :)2, 2), n, n);%opt_rte, opt_brk, min_dist二mtspf_ga(xyz, dmat, salesmen, min_tour,%pop_size, num_iter, 1, 1);% See also: mtsp_ga, mtspo_ga, mtspof_ga, mtspofs_ga, mtspv_ga,distmat% Author: Jose

10、ph Kirk% Email: jdkirk630gmai1. com% Release: 1.3% Release Date: 6/2/09% Process Inputs and Initialize DefauItsnargs = 8;for k = nargin:nargs-lswitch kcase 0 xy = 10*rand(40, 2);case 1N = size(xy, 1);a = meshgrid(1:N);dmat = reshape(sqrt(sum(xy (a, :)-xy(, :) 2, 2), X, X);case 2salesmen = 5;case 3mi

11、n_tour = 2;case 4pop_size = 80;case 5num_iter = 5e3;case 6show_prog = 1;case 7showeres = 1;otherwiseendend% Verify InputsX, dims = size(xy);nr,nc = size(dmat);if X二nr X二ncerrorInvalid XY or DMAT inputs!)endn = X - 1; % Separate Start/End City% Sanity Checkssalesmen = max(1, min(n, round(real(salesmen(1);min_tour = max(l, min(floor(n/salesmen), round(real(mintour(1);pop_size = max(& 8歡ceil(pop_size(l)/8);num_ite:r = max (1, round (real (numiter (1);show_prog = logical(show_prog(l);showeres = logical(show_res(1);% Initializations for Route break Point Selectionnum_brks =

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論