

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高三数学教学总结模版
- 区块链技术下智能合约的合同法律解析
- 《甲亢治疗药物选择》课件 - 分析和比较不同药物的疗效与安全性
- 区块链技术推动普惠金融与贷款业务发展
- 区块链技术在物流供应链透明度中的实践
- 互换性与测量技术重点知识点总结模版
- 《销售业务代表管理》课件
- 办公自动化与电子健康记录系统的融合实践
- 医疗AI技术如何实现数据安全与隐私保护的平衡探讨报告
- 2025年铁路货物运输合同
- 2025年内蒙古中煤蒙大新能源化工有限公司招聘笔试参考题库附带答案详解
- 年产16.6万吨工业涂料用树脂、2.8万吨装配式建筑用硅烷改性胶粘剂用树脂、2万吨高性能防水涂料用树脂项目(一期)公众参与说明
- “4 组织环境-4.2理解相关方的需求和期望”专业深度解读与应用指导材料(雷泽佳编制-2025C1)
- 湖北省第十届湖北省高三(4月)调研模拟考试数学试题及答案
- 五一劳动节前安全检查重点
- 地理西亚+课件-2024-2025学年七年级地理下册人教版
- 诊所医疗质量相关管理制度
- CHINET2024年全年细菌耐药监测结果
- 膀胱癌健康宣教课件
- DBJ50T-284-2018 工程勘察信息模型设计标准
- 中药学习题集(总论-第二十章,附标准答案)
评论
0/150
提交评论