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

网络网站建设电话推销seo实战培训中心

网络网站建设电话推销,seo实战培训中心,如何在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.tj-hxxt.cn/news/104366.html

相关文章:

  • 重点学科网站建设湖北seo诊断
  • 网站建设部门宣言seo服务工程
  • 专业做效果图网站百度关键词搜索量排行
  • 网站两列导航公司域名注册查询
  • 摄影课程自学网站网络营销策划书案例
  • 成都网站制作成都网站制作网盘搜索
  • 百度头条怎么做网站站长之家ip查询
  • 个人网站建设报告友情链接交换网站
  • 美国做3d h动画的网站上海企业网站seo
  • 功能型网站建设seo百科大全
  • 电子商务网站开发的视频seo外链工具软件
  • 做关于家乡的网站正规软件开发培训学校
  • 江阴网站建设推广360关键词指数查询
  • 成品网站nike源码1688百度网页版下载
  • 已申请域名怎么做网站上海网络推广优化公司
  • 远近互联网站建设软文营销案例分析
  • 南宁外贸网站建设搜易网提供的技术服务
  • 建网站 选安全网页设计与制作作业成品
  • 网站搭建说明网店seo排名优化
  • 做网站销售电销好做吗软文新闻发稿平台
  • 建站工具搭建网站搜狗站长工具
  • 个人网站建立多少钱十大免费无代码开发软件
  • 网站的建设属于无形资产网络营销建议
  • 那样的网站18年长春网站建设方案推广
  • 做环卫车怎么做网站网站关键词排名优化价格
  • 网站建设的税率是多少网络营销的基本特征
  • 如何用wordpress做视频网站产品故事软文案例
  • 规划电子商务网站高端网站建设案例
  • 南京小程序开发网站建设公司口碑营销案例有哪些
  • 好看的响应式网站链接交换平台