matlab迭代次数,怎么知道程序中的迭代次数呢
function [result,x,y]=TS_BS1(num_1,num_2,c_i,d_j,M_i,T)
%初始參數(shù)設(shè)置
runcount = 0;
tabulength = 3 + num_1;
candidate.x = round(rand(1,num_1));
y = zeros(num_1,num_2);
sum_d = 0;
for i = 1:num_2
sum_d = sum_d + d_j(i);
end
alfa = 0.9;
%初始化禁忌表
for i = 1:tabulength
tabulist(i).change = [0,0];
tabulist(i).x = 0;
tabulist(i).value = 0;
end
candidate.value = c_i*candidate.x';%目前的解
best_so_far.x = candidate.x;
best_so_far.value = candidate.value;
while runcount < T
runcount = runcount+1;
%產(chǎn)生領(lǐng)域解
kk = 1;
for i = 1:num_1-2
for j = i:num_1-1
flag = 1;
for n = 1:tabulength
tempflag = sum(abs(tabulist(n).change-[i, j]));
flag = flag & tempflag;
end;
if flag
temp = cat(1,candidate.x);
t = temp(i);
temp(i ) = temp(j);
temp(j) = t;
neighborhood(kk).x= temp; % 候選的x
neighborhood(kk).change= [i, j];
kk= kk+1;
end;
end;
end;
L = length(neighborhood);
%滿足約束條件
for i = 1:L
for j = 1:num_1
if ~ neighborhood(i).x(j)
y(j,:) = 0;
end
if neighborhood(i).x(j)
y(j,:) = round(rand(1,num_2));
while (d_j*y(j,:)'>M_i(j)&&sum(d_j*y')
y(j,:) = round(rand(1,num_2));
end
end
end
end
for i = 1:L
neighborhood(1).value = neighborhood(i).x*c_i';%候選的目標(biāo)值
end
candidate_next = sort(cat(1, neighborhood.value), 1).';%將目標(biāo)值從小到大開(kāi)始排序
if candidate_next(1)
index= find(cat(1, neighborhood.value)==candidate_next(1)); % 找到最小目標(biāo)值對(duì)應(yīng)的對(duì)象的位置
candidate.x = neighborhood(index).x;
candidate.change = neighborhood(index).change;
candidate.value = candidate_next(1);
%將這個(gè)值放入禁忌表中
for i= tabulength-1:-1:1
tabulist(i+1).change = tabulist(i).change;
tabulist(i+1).x = tabulist(i).x;
tabulist(i+1).value = tabulist(i).value;
end;
tabulist(1).change = candidate.change;
tabulist(1).x = candidate.x;
tabulist(1).value = candidate.value;
best_so_far.x= candidate.x;
best_so_far.value= candidate.value;
end
end
result = best_so_far.value; % 返回目標(biāo)值結(jié)果
x = best_so_far.x; % 返回城市順序結(jié)果
fprintf('\nbest value = %d', result);
總結(jié)
以上是生活随笔為你收集整理的matlab迭代次数,怎么知道程序中的迭代次数呢的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 微信开通检测软件使用心得与技巧
- 下一篇: matlab怎么计算行列式,matlab