matlab之run求解器

语法

x = run(gs, problem); % 运行GlobalSearch以找到问题的解决方案或多个本地解决problem方案
[x,fval] = run(gs, problem); %返回目标函数值在x点出找到的最佳值

实例

rng default
gs = GlobalSearch;
sixmin = @(x)(4*x(1)^2 - 2.1*x(1)^4 + x(1)^6/3 + x(1)*x(2) - 4*x(2)^2 + 4*x(2)^4);
problem = createOptimProblem(‘fmincon’,‘x0’,[-1,2],‘objective’,sixmin,‘lb’,[-3,-3],‘ub’,[3,3]);
x = run(gs,problem)

运行结果
GlobalSearch stopped because it analyzed all the trial points.
All 8 local solver runs converged with a positive local solver exit flag.
x = 1×2
-0.0898 0.7127

调用run时,可以使用下面的语法得到x处的run目标函数值:

[x,fval] = run(gs, problem)

当忽略fval时,仍然可以计算处x处的目标函数值。

fval = sixmin(x);

fval = -1.0316

参考:

matlab官方文件doc run

### LKH Solver MATLAB Interface Documentation and Examples The Lin-Kernighan-Helsgaun (LKH) algorithm is one of the most effective methods for solving Traveling Salesman Problems (TSP). For integrating this powerful tool with MATLAB, specific interfaces have been developed to facilitate its use within a MATLAB environment. #### Installation Process To begin using LKH from MATLAB, installation involves downloading both the LKH source code as well as any necessary MATLAB scripts that serve as an intermediary between user inputs in MATLAB and execution by LKH[^1]. Typically, these resources can be found on academic or personal websites dedicated to TSP research. #### Example Code Usage Below demonstrates how to set up and call LKH through MATLAB: ```matlab % Define problem parameters such as number of cities and their coordinates. cities = [ 0.743592861151, 0.604238244580; 0.933999969005, 0.297525043037; % ... additional city locations ... ]; % Write data file compatible with LKH format requirements. fid = fopen('problem.tsp', 'w'); fprintf(fid, "NAME : Problem\n"); fprintf(fid, "TYPE : TSP\n"); fprintf(fid, "DIMENSION : %d\n", size(cities, 1)); fprintf(fid, "EDGE_WEIGHT_TYPE : EUC_2D\n"); fprintf(fid, "NODE_COORD_SECTION\n"); for i = 1:size(cities, 1) fprintf(fid, "%d %.6f %.6f\n", i, cities(i, 1), cities(i, 2)); end fclose(fid); % Call system command to run LKH solver. system(['./LKH params.par']); ``` This script prepares input files required by LKH according to specified formats before invoking it via shell commands directly from MATLAB's workspace. After running LKH externally, results are typically parsed back into MATLAB structures for further analysis. #### Parsing Output Files Once LKH completes processing, output will usually reside inside text-based tour files which need parsing routines implemented either manually or utilizing pre-built functions available online. --related questions-- 1. How does parameter tuning affect performance when applying LKH? 2. What preprocessing steps should precede feeding datasets into LKH? 3. Can other optimization algorithms achieve comparable efficiency levels like those seen with LKH? 4. Are there alternative solvers offering similar ease-of-use alongside strong computational capabilities?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值