当前位置: 首页 > news >正文

福建富通建设有限公司网站比较好的wordpress主题

福建富通建设有限公司网站,比较好的wordpress主题,wordpress 指定 任务,杭州网站备案目前可以查到的最好的方法求解TSP问题是 LKH,所以本篇文章介绍如何使用Matlab 调用LKH 参考文档:用matlab调用迄今为止最强悍的求解旅行商(TSP)的算法-LKH算法_wx6333e948c3602的技术博客_51CTO博客 【LKH算法体验】用matlab调用…

目前可以查到的最好的方法求解TSP问题是 LKH,所以本篇文章介绍如何使用Matlab 调用LKH
参考文档:

用matlab调用迄今为止最强悍的求解旅行商(TSP)的算法-LKH算法_wx6333e948c3602的技术博客_51CTO博客

【LKH算法体验】用matlab调用迄今为止最强悍的求解旅行商(TSP)的算法-LKH算法_lkh3算法_果州做题家的博客-CSDN博客

使用步骤:
首先需要提前准备好matlab的环境,然后去github 下载matlab程序:
网址链接:https://github.com/unr-arl/LKH_TSP
里面除了有matlab调用程序 还有python 的程序

下载之后将内部的函数放到当前文件夹的路径下

然后建立两个文件夹 LKH 和 TSPLIB

下载LKH 应用程序链接如下:

LKH (Keld Helsgaun)

LKH问价夹内放该程序

 然后就是编写程序就可以了
 

%已知距离矩阵,求最优解
clear,clc;
fname_tsp='test';
LKHdir=strcat(pwd,'/LKH/');
TSPLIBdir=strcat(pwd,'/TSPLIB/');
lkh_cmd=[LKHdir,'LKH',' ',TSPLIBdir,fname_tsp,'.par'];
%距离矩阵
D=[0 0 2 1 2 1 1 1 1 1 2 4 3 0 0 
0 0 0 2 1 3 1 1 1 1 1 1 3 0 0 
2 0 0 0 2 1 1 0 1 1 2 1 1 2 0 
1 2 0 0 0 2 1 1 1 1 0 1 2 1 0 
2 1 2 0 0 1 1 3 1 1 1 2 2 4 0 
1 3 1 2 1 0 0 1 1 2 1 1 2 0 0 
1 1 1 1 1 0 0 1 1 1 1 3 1 1 0 
1 1 0 1 3 1 1 0 0 0 0 2 1 2 0 
1 1 1 1 1 1 1 0 0 0 0 1 1 3 0 
1 1 1 1 1 2 1 0 0 0 0 2 1 2 0 
2 1 2 0 1 1 1 0 0 0 0 1 1 1 0 
4 1 1 1 2 1 3 2 1 2 1 0 0 1 0 
3 3 1 2 2 2 1 1 1 1 1 0 0 0 0 
0 0 2 1 4 0 1 2 3 2 1 1 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
CostMatrix=D;
user_comment='a comment by the user';
pars_struct.CostMatrixMulFactor = 1000;
pars_struct.user_comment = user_comment;
LKH_TSP(CostMatrix,pars_struct,fname_tsp,LKHdir,TSPLIBdir)

 这里需要注意一些细节:
下载下来的LKH_TSP 可能会报错,此时需要更改
 

function TSPsolution = LKH_TSP(CostMatrix,pars_struct,fname_tsp,LKHdir,TSPLIBdir)
%
%   Syntax:
%   TSPsolution = LKH_TSP(CostMatrix,pars_struct,fname_tsp,LKHdir,TSPLIBdir)
%
%   This functions solves TSP problems using the Lin-Kernighan-Helsgaun
%   solver. It assumes that a compiled executable of the LKH solver as
%   found at: http://www.akira.ruc.dk/~keld/research/LKH/ is available at
%   the LKHdir directory. Furthermore a TSPLIB directory is assumed.
%   For the definition of the TSPLIB and the compilation of the LKH code
%   check the aforementioned url. 
%
%   Inputs:
%   CostMatrix      : the Cost Matrix of the (asymmetric) TSP. [e.g. it can be an NxN matrix of distances]
%   pars_struct     : parameters structure with
%                   : -> CostMatrixMulFactor (value that makes Cost Matrix
%                        almost integer. [eg. pars_struct.CostMatrixMulFactor = 1000; ]
%                     -> user_comment (a user comment for the problem) [optional]
%   fname_tsp       : the filename to save the tsp problem
%   LKHdir          : the directory of the LKH executable
%   TSPLIBdir       : the directory of the TSPLIB files
%   
%   Outputs:
%   TSPsolution     : the TSP solution
%   
%   Authors:
%   Kostas Alexis (kalexis@unr.edu)
%CostMatrix_tsp = pars_struct.CostMatrixMulFactor*CostMatrix;
CostMatrix_tsp = floor(CostMatrix_tsp);
user_comment = pars_struct.user_comment; % fileID = writeTSPLIBfile_FE(fname_tsp,CostMatrix_tsp,user_comment);
% writeProblemFiles(strcat(LKHdir, "/", TSPLIBdir, "/", fname_tsp),CostMatrix_tsp,pars_struct);disp('### LKH problem set-up...');
%%  Solve the TSP Problem via the LKH Heuristic
disp('### Now solving the TSP problem using the LKH Heuristic...');
copy_toTSPLIBdir_cmd = ['cp ' LKHdir fname_tsp '.txt' ' ' TSPLIBdir];start_lkh_time = cputime;
lkh_cmd = [LKHdir 'LKH' ' ' TSPLIBdir fname_tsp '.par'];[status,cmdout] = system(lkh_cmd,'-echo');
end_lkh_time = cputime;copy_toTSPLIBdir_cmd = ['cp ' LKHdir fname_tsp '.txt' ' ' TSPLIBdir];
[status,cmdout] = system(copy_toTSPLIBdir_cmd);
disp('### ... done!');
solution_file = [fname_tsp '.txt']; 
tsp_sol_cell = importdata(solution_file);% rm_solution_file_cmd = ['rm ' LKHdir fname_tsp '.txt'];
% [status,cmdout] = system(rm_solution_file_cmd);
% 
tsp_sol = [];
for i = 1:length(tsp_sol_cell.textdata)if ~isempty(str2num(tsp_sol_cell.textdata{i}))tsp_sol(end+1) = str2num(tsp_sol_cell.textdata{i});end
endtsp_sol(end) = [];TSPsolution = tsp_sol;end

https://download.csdn.net/download/qq_34995963/87541471

http://www.yayakq.cn/news/675734/

相关文章:

  • 网站开发经验与教训范文网站设置搜索关键字
  • 网站开发z亿玛酷1负责凡客软件下载
  • 网站开发需要的技术人员有什么软件西安网站建设咪豆互联
  • 郑州网站建设喝彩科技南通网站备案
  • 广州做响应式网站中山专业网站建设公司
  • 网站下做二级域名如何修改网站抓取内容
  • 东莞网站制作搜索祥奔科技东莞市研发网站建设公司
  • 西安做网站公司哪家好wordpress如何做站群
  • 深圳福永做网站江都建设局网站
  • 网站制作排名优化数字营销专业学什么课程
  • 房产网站管理系统做我的世界的mod的网站
  • 网站seo技术教程做机械的网站
  • 现在建设校园网站用什么软件二级网站开发 一级关系
  • 怎么用网吧电脑做网站服务器吗百度推广关键词排名规则
  • 网站编辑应该怎么做行业门户网站案例分析
  • 做网站要用什么软件图文教程wordpress 多个注册表单
  • 营销型网站建设是什么element-ui网站开发
  • 免费自助建站模板自己做影视类网站
  • 文化网站开发背景wordpress 图片缩略图不显示图片
  • 网站开发项目费用预算泰安人才网最新招聘
  • 北京 网站设计公司公司网站建设进度
  • 优质国外网站合肥专业做网站公司哪家好
  • 火车票网站开发建站能赚钱吗
  • 做网站先买域名购物系统属于什么系统
  • 响应式网站新闻部分怎么做视频网站哪个做的好
  • 网站移动端的设计思想手机版万能视频提取器
  • 网站建设 软件企业asp.net sql server网站建设 pdf
  • 在线做数据图的网站有哪些问题品优购html代码
  • 普陀手机网站建设长沙网站推广¥做下拉去118cr
  • 手机旅游视频网站模板Wordpress自建主题视频百度云下载