版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、MATLABMATLAB 多旅行商问题源代码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. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年合同管理软件操作教程3篇
- 2024年度婚前协议书(职业发展支持)3篇
- 2024年度临时兼职人员雇佣协议3篇
- 2024年消防设施设备研发与生产合作协议3篇
- 2024年度三人股东在电子商务领域合作协议书2篇
- 2024年学校食堂餐饮管理合同6篇
- 2024年度水暖工程节能减排劳务分包合同范本3篇
- 2024年度能源企业收购项目居间服务合同2篇
- 2024年全新版奢侈品质押担保与全球市场布局合同3篇
- 2024年度航天科技研发与转让协议3篇
- 太原永辉超市活动促销方案
- 采购部经理年度工作总结
- 新能源汽车项目融资计划书
- 研学基地设计方案
- 预防网络成瘾心理课课件
- 运动中常见骨折的预防与处理
- 2024年1月份21起典型事故案例汇总及2024年节前安全检查与春节安全专题培训
- 《GDP核算讲义》课件
- 金属钴分析报告
- 《小肠解剖及临床》课件
- 《柔韧素质训练方法》课件
评论
0/150
提交评论