route_cost.m

来自「该程序是基于Matlab编写的模拟退火工具软件包」· M 代码 · 共 22 行

M
22
字号
function Ew = route_cost(X,W)
% Ew = route_cost(X,W)
% Method for tsp example supplied with SA Tools.
% See http://www.frostconcepts.com/software for information on SA Tools.
%
%   Ew = route_cost(X,W) ;
%
%   X = {N, D}
%       N = # of cities.
%       D = distance matrix. D(i,j) = distance from city i to j.
%   W = a route, a permutation of the indicies 1:N
%
%   Ew = energy corresponding to W.
%   Computed by summing the distances along the route.
%
N = X{1} ;
D = X{2} ;
Ew = D(W(N),W(1)) ;
for i=1:(N-1)
    Ew = Ew + D(W(i),W(i+1)) ;
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?